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

Being killed by an enemy


Both enemies and the spaceship have a perfect circular shape. This will help us to determine when an enemy and the spaceship collide. Being basically two circles, we can say they collide when the distance between their centers is less than the sum of both the radius.

Let's start creating a quick function to determine the distance between two Sprites using the Pythagorean Theorem:

private function distance(from:Sprite,to:Sprite):Number {
  var distX:Number=from.x-to.x;
  var distY:Number=from.y-to.y;
  return distX*distX+distY*distY;
}

There isn't that much to explain, since we are just applying a world famous formula, but I want you to notice I am not performing any square root because it's quite CPU-expensive. It won't be a problem as long as I remember to compare the collision distance applying the power of two, which is way faster than applying a square root.

Everything is ready to check for collisions, so add these lines at the end of manageEnemy function:

private...