Skip to content

Commit 98e1801

Browse files
committed
Part2 - Shooting Bullets
1 parent 7b9ad2d commit 98e1801

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Aeroplane Shooting Game Tutorial
2+
=========
3+
4+
This is a small tutorial written in flash to create an aeroplane shooting game. The tutorial tries to be minimalistic to implment the basic features for such a game and to do it using as low code as possible.
5+
6+
It is structured in 5 parts:
7+
8+
1. [Player Movement]
9+
2. [Shooting Bullets]
10+
3. Adding Enemies
11+
4. Collisions
12+
5. Scoring and HUD.
13+
14+
----
15+
16+
[Player Movement]:http://gametuts.org/aeroplane-shooting-game-tutorial-player-movement/
17+
[Shooting Bullets]:http://gametuts.org/aeroplane-shooting-game-tutorial-shooting-bullets/

lib/AeroplaneTutorial.swc

5.87 KB
Binary file not shown.

src/AeroplaneGameTutorial.as

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package
22
{
3+
import flash.display.MovieClip;
34
import flash.display.Sprite;
45
import flash.events.Event;
56
import flash.events.KeyboardEvent;
6-
7+
78
[SWF(width=440,height=480,frameRate=60)]
89
public class AeroplaneGameTutorial extends Sprite
910
{
@@ -13,6 +14,11 @@ package
1314
private var keys:Vector.<int> = new Vector.<int>(255);
1415
private var SPEED:Number = 3;
1516

17+
private var playerBullets:Vector.<MovieClip> = new Vector.<MovieClip>();
18+
private var playerBulletsDelay:Number = 0;
19+
20+
private var BULLET_SPEED:Number = 6;
21+
1622
public function AeroplaneGameTutorial()
1723
{
1824
this.addChild(water);
@@ -29,16 +35,43 @@ package
2935
this.addEventListener(Event.ENTER_FRAME, enterFrame);
3036
}
3137

38+
private var lastFrameTime:Number = (new Date()).getTime();
39+
3240
private function enterFrame(e:Event):void
3341
{
42+
var thisFrame:Date = new Date();
43+
var dt:Number = (thisFrame.getTime() - lastFrameTime) / 1000;
44+
lastFrameTime = thisFrame.getTime();
45+
3446
water.y += 1;
3547
if (water.y > 0)
3648
water.y -= 512;
3749

3850
if (isUp()) plane.y = Math.max(plane.height / 2, plane.y - SPEED);
3951
if (isDown()) plane.y = Math.min(stage.stageHeight - plane.height / 2, plane.y + SPEED);
4052
if (isLeft()) plane.x = Math.max(plane.width / 2, plane.x - SPEED);;
41-
if (isRight()) plane.x = Math.min(stage.stageWidth - plane.width / 2, plane.x + SPEED);
53+
if (isRight()) plane.x = Math.min(stage.stageWidth - plane.width / 2, plane.x + SPEED);
54+
55+
// shoot
56+
playerBulletsDelay -= dt;
57+
if (isFire()
58+
&& playerBulletsDelay <= 0)
59+
{
60+
playerBulletsDelay = 0.3;
61+
shootPlayerBullet();
62+
}
63+
64+
// update bulltes positions
65+
for each( var b:MovieClip in playerBullets)
66+
{
67+
b.y -= BULLET_SPEED;
68+
}
69+
70+
// remove bullets which are getting out of the screen
71+
while(playerBullets.length > 0 && playerBullets[0].y < -10)
72+
{
73+
this.removeChild(playerBullets.shift());
74+
}
4275
}
4376

4477
private function keyUp(e:KeyboardEvent):void
@@ -57,15 +90,31 @@ package
5790
private function isDown():Boolean{
5891
return (keys[40] || keys[83]);
5992
}
60-
93+
6194
private function isLeft():Boolean{
6295
return (keys[37] || keys[65]);
6396
}
64-
97+
6598
private function isRight():Boolean{
6699
return (keys[39] || keys[68]);
67100
}
68101

102+
private function isFire():Boolean{
103+
return (keys[17]);
104+
}
105+
106+
private function shootPlayerBullet():void
107+
{
108+
var playerBullet:MovieClip = new BulletRes();
109+
110+
playerBullet.x = plane.x;
111+
playerBullet.y = plane.y - plane.width / 2;
112+
113+
this.addChild(playerBullet);
114+
115+
playerBullets.push(playerBullet);
116+
}
117+
69118

70119
}
71120

0 commit comments

Comments
 (0)