And it's a start!!
I will start slowly with small parts for a shoot 'em up game. The thing that is fun with a shooter game is to try and invent cool bullet patterns. They have to look scary but still doable. There is some classic patterns that you pretty much have to use, they are basics wall of bullets over which you'll add other things.
I'll begin by showing my Ball class which is used as my simple bullet.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Ball extends Sprite
{
private var color:Number;
private var radius:Number;
public var vx:Number = 0;
public var vy:Number = 0;
public function Ball(radius:Number, color:Number)
{
this.radius = radius;
this.color = color;
drawSelf();
addEventListener(Event.ENTER_FRAME, update);
}
public function update(e:Event):void
{
x += vx;
y += vy;
if (this.x < 0 - this.radius || this. x > stage.stageWidth + this.radius || this. y < 0 - this.radius || this.y > stage.stageHeight +this.radius)
{
parent.removeChild(this);
this.removeEventListener(Event.ENTER_FRAME, update);
}
}
private function drawSelf():void
{
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
}
So it's pretty straightforward, when you call a new ball, you give it a radius and a color, it will draw itself with those and then add a listener for each frame that will call the update function.
In the update function, the ball will move by the amount of its X and Y velocity ( vx and vy ) and will remove itself if it gets out of bounds (the big IF statement).
Thats a ball!
Just try this to see it
public class Main extends Sprite
{
public var ball:Ball = new Ball(15, 0x555555);
public function Main():void
{
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
ball.vx = 0;
ball.vy = 0;
addChild(ball);
}
}
You get your nice ball right in the middle of the stage!! BRAVO
Play with the vx and vy properties to wee it move, you can also easily change the size and color.
Ok that was easy, I know. Next time we'll build a nice "fan" pattern the flood your screen with bullet. Until then, try it yourself!!
No comments:
Post a Comment