Game Development Reference
In-Depth Information
First, let's take a quick look at the class instance variables. Notice that we have added four new
variables. dir is the direction the Enemy plane will fly, while DIR_DOWN , DIR_RIGHT and DIR_LEFT
represent this direction. They are static variables so they can be referenced outside the Enemy class.
package com.efg.games.flakcannon
{
import flash.display.Shape;
import flash.display.Sprite
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
public class Enemy extends Sprite
{
public var imageBitmapData:BitmapData;
public var image:Bitmap;
private var startLocation:Point;
private var endLocation:Point;
public var nextLocation:Point;
Notice that nextLocation is a public variable in the class. We do this so we can access it for
collision detection. Since we will not be using look-ahead collision detection in this game, we will
not make use of this feature, but it is something that should be noted. You need to remember to
make variables that need to be accessed from the out public in some way, either by making them
explicitly public, or by creating get/set methods for each
Another addition is the variable angle . We are now creating objects that move from one point in
any particular direction until we tell them to stop, instead of moving from one point to another and
stopping. To facilitate this, we will keep track of the current angle at which the object is travelling.
This value will help us calculate the nextLocation point values in a brand new render() function.
private var speed:int = 5;
public var finished:Boolean;
public var dir:Number;
public var angle:Number;
public static const DIR_DOWN:int = 1;
public static const DIR_RIGHT:int =2;
public static const DIR_LEFT:int =3;
Another thing we need to do is embed the three different plane graphics if we are using Flex.
Again, these three graphics are used for the three different directions from which an Enemy can fly
onto the screen.
/*
//**Flex Framework Only
[Embed(source = "assets/flakassets.swf", symbol="PlaneGif")]
private var PlaneGif:Class;
[Embed(source = "assets/flakassets.swf", symbol="PlaneLeftGif")]
private var PlaneLeftGif:Class;
[Embed(source = "assets/flakassets.swf", symbol="PlaneRightGif")]
private var PlaneRightGif:Class;
*/
Search WWH ::




Custom Search