Learning to Add Multiple Levels?

Subscribe to Learning to Add Multiple Levels? 7 posts

avatar for fiddlecrab fiddlecrab 4 posts
Flag Post

I’m looking for a way to add multiple levels to a game for AS3. I want to start learning by adding multiple levels to the AS3 version of the Shootorial.

I was wondering if anyone could direct me to a resource that could shed light on how I would add additional levels with new values for enemies, different images, etc. in AS3.

Thanks in advance.

 
avatar for vesperbot vesperbot 1883 posts
Flag Post

Well, I believe you should separate metadata and data in your level concept. See, if your enemy types are numbered, then in your level you just need to place a number of the enemy you want to spawn, and then parse it and make said enemy arrive. You will need some more numbers tho, say position, angle, trajectory of movement if applicable. These numbers are metadata, and the enemy type along with its attacks, images etc. is data.

You can add more levels by specifying data storage format for yourself, which you will use to form a level. It might contain types of enemies available (up to storing actual data, although I’d say this is wrong, you will most likely re-use enemy types across your game), timing, enemies’ data, boss type, anything else your fantasy would put into a level.

 
avatar for BluePriest BluePriest 470 posts
Flag Post

A timer is the easiest way to do it imo. Just make a timer, and once timer1=10000 or however long you want the round to be, then round=2 and the new wave of enemies will come.

 
avatar for RTL_Shadow RTL_Shadow 1036 posts
Flag Post
Originally posted by BluePriest:

A timer is the easiest way to do it imo. Just make a timer, and once timer1=10000 or however long you want the round to be, then round=2 and the new wave of enemies will come.

Timers still run at default framerate when out of focus, but the game runs at 2fps. Don’t use a Timer, use frame-based timers :)

 
avatar for vesperbot vesperbot 1883 posts
Flag Post
Originally posted by RTL_Shadow:

Timers still run at default framerate when out of focus, but the game runs at 2fps. Don’t use a Timer, use frame-based timers :)

Pretty much this. And, it depends on the game, some games run at top speed when unfocused/hidden, some run at a crawl. I say using two different time (quantum) sources to be really bad, also timers are asynchronous, and I’m seeing that massive use of timers make the game misbehave (GemTD as an example), so I prefer enter frame routine to do all jobs associated with counting time.

 
avatar for fiddlecrab fiddlecrab 4 posts
Flag Post

@vesperbot

Any code that could send me in the right direction?

 
avatar for vesperbot vesperbot 1883 posts
Flag Post
class LevelElement {
  public var time:int;
  public var monsterType:int;
  public var mx:int;
  public var my:int;
  public var mr:Number;
  public var hpmod:Number;
}

class LevelData {
  public var levelNum:int;
  public var monsters:Vector.<LevelElement>;
  ....
}
...
private function loadLevel(ld:LevelData){...} // prepare level
private function onEnterFrame(e:Event) {
  currentTime++;
  while (ld.monsters[currentIndex].time<currentTime) {
     spawnMonster(ld.monsters[currentIndex]);
     currentIndex++;
  }
  // process the rest of duties
}