Book Image

Flash Game Development by Example

By : Emanuele Feronato
Book Image

Flash Game Development by Example

By: Emanuele Feronato

Overview of this book

<p>You can't call yourself a Flash game developer unless you know how to build certain essential games, and can quickly use the skills and techniques that make them up.<br /><br />Flash Game Development by Example is an ultra-fast paced game development course. Learn step-by-step how to build 10 classic games. Each game introduces new game development skills, techniques, and concepts. By the end of the book you will have built ten complete games &ndash; and have the skills you need to design and build your own game ideas.<br /><br />The book starts with simple well known puzzle games: Concentration and Minesweeper. After learning the basics of game design you&rsquo;ll introduce AI with a four-in-a-row game. Then as you build your own versions of old arcade games such as Snake, Tetris, and Astro Panic. The book ends with a collection of modern casual classics.</p>
Table of Contents (17 chapters)
Flash Game Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Where to Go Now
Index

Advancing levels


Once all enemies have been destroyed, the player must be able to play the next level, with more enemies moving faster.

For our convenience, we should manage level creation with a function, changing Main function removing the for loop and adding a new function called playLevel.

public function Main() {
  placeSpaceship();
  playLevel();
  addEventListener(Event.ENTER_FRAME,onEnterFrm);
  stage.addEventListener(MouseEvent.CLICK,onMouseCk);
}

This function is just a cut/paste of the for loop previously included in Main function, but this way we can call playLevel from elsewhere.

private function playLevel():void {
  for (var i:uint=1; i<level+3; i++) {
    placeEnemy(i);
  }
}

And in this specific case, we are calling it from onEnterFrm function once we removed an enemy:

private function onEnterFrm(e:Event) {
  ...
  if (enemyToRemove>=0) {
    enemyVector.splice(enemyToRemove,1);
    enemyToRemove=-1;
    if (enemyVector.length==0) {
      level++;
      playLevel();
    ...