Game Development Reference
In-Depth Information
The SimpleShooter Class
This class handles all the logic behind the gameplay. It will control
the player
s position, the scrolling background, and creation,
movement, and removal of the projectiles. The background actually
consists of two separate objects we
re calling the foreground and
background . We will move these two objects at different speeds to
achieve a feeling of depth and sense of motion known as parallax
public class SimpleShooter extends Sprite {
public var background:Sprite, foreground:Sprite;
public var player:Sprite;
protected var _projectileList:Vector. < Projectile > ;
protected var _speed:Number = 15;
protected var _stageWidth:int, _stageHeight:int;
protected var _projectileSpeed:Number = 20;
public function SimpleShooter() {
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
addEventListener(Event.ENTER_FRAME, frameScript,
false, 0, true);
_projectileList = new Vector. < Projectile > ();
As you can see, there are three public variables representing the
background, foreground, and player Sprites. Internally, it also stores
a list of all active projectiles, the speed at which the foreground
should move, the speed of any projectiles upon creation, and refer-
ences to the stage
s width and height.
protected function addedToStage(e:Event):void {
_stageWidth = stage.stageWidth;
_stageHeight = stage.stageHeight;
addEventListener(MouseEvent.MOUSE_DOWN, createProjectile,
false, 0, true);
protected function frameScript(e:Event):void {
Once added to the stage, the game stores information about the
stage and adds a listener for when the mouse button is pressed, it
Search Nedrilad ::

Custom Search