Developing a space shooter game
[ October 07, 2004 ] by Richard Nias aka Crashlanding
In this collection of tutorials, the author explains how to create a basic shooter game, considering all its different aspects: movement, shooting, enemies, sound, etc.


COMPLEX ENEMY PATHS

At the moment, the enemies movements look something like this:

By the end of this tutorial, the movement will look something like this:

The enemies will have move complex, zigzag paths. This effect looks better, but takes little effort. Lets see what it will look like.

This requires only three changes to the code, both on the enemy. Click on the enemy MovieClip and open the actions window. Add this to the bottom of the reset function:

maxH = this._y + 100;
minH = this._y - 100;

This sets two variables, maxH and minH to 100 either side of the enemy's starting _y. These will tell the script where to reverse the direction. Add this bit of code after the reset function but still in the load event:

var upspeed = -2;

Upspeed will act as the speed variable. Now, in the EnterFrame function, put:

this._y += upspeed;
 
if (this._y > maxH)
{
  upspeed = -2;
}
else if (this._y < minH)
{
  upspeed = 2;
}

Now, every frame the enemy's y is increased by uspeed. However, when y goes over maxH, upspeed is changed to -2, therefore every frame y is increased by -2, which makes it go in the opposite direction. Then, when y goes below minH, upspeed is changed back to 2. Simple! But, there is one problem. What if minH or maxH is off the stage? The enemy would keep disapearing. so, change the if statments so the also reverse the direction when the enemies get too near the edge of the screen:

if (this._y > maxH || this._y>290)
{...

if (this._y < minH || this._y<0)
{...

There! You've done it! Now, you can move on to shooting... from the enemies! You can download the .fla here. If you need to ask me any questions, email me at richard@livescripts.net.


     
 
 
Name: Richard Nias aka Crashlanding
Location: South-east London, UK
Age: 14
Flash experience: Had Flash for 1 1/4 years now. I learnt from the help files before finding gotoandplay and flashkit, getting me intrested in games.
Job: None
Website: http://flash.livescripts.net
 
 
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| www.smartfoxserver.com | www.gotoandplay.biz | www.openspace-engine.com |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048