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

Eating fruits


Once the fruit is placed, eating is easy, let's say a piece of cake. A fruit cake, of course.

The idea: In the same way we checked for an empty tile to place the fruit in, we'll check for the tile occupied by the snake's head looking for a fruit. If we find a fruit, we have to remove it and place a new one elsewhere.

The development: Once the head has moved, we have to retrieve its middle point and see if there's a fruit under such point. Before the end of onEnterFr function, add this code:

var point_to_watch:Point=new Point(the_head.x+TILE_SIZE/2,the_head.y+TILE_SIZE/2);
var children_in_that_point:Array=stage.getObjectsUnderPoint(point_to_watch);
for (var i:uint=0; i<children_in_that_point.length; i++) {
  switch (children_in_that_point[i].parent.name) {
    case "fruit" :
      removeChild(fruit);
      placeStuff();
      break;
  }
}

Test the movie and eat a fruit: it will disappear and a new fruit will appear in another location.

In the picture, the snake eats a fruit...