-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.as
154 lines (141 loc) · 3.43 KB
/
Plane.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.KeyboardEvent;
import com.junkbyte.console.Cc;
public class Plane extends Ship{
private var horizontal:Number;
private var vertical:Number;
private var firing:Boolean;
private var reload:int;
private var slow:Boolean;
private var left:Boolean;
private var right:Boolean;
private var up:Boolean;
private var down:Boolean;
private var health:int;
private static var imageFile:URLRequest = new URLRequest("http://www.davidpmah.com/planegame/images/reimu.gif");
public function Plane(x:Number, y:Number):void {
loadSprite();
graphics.lineStyle(2, 0x000000);
//graphics.drawRect(-10, -10, 20, 20);
graphics.beginFill(0xff0000);
// graphics.drawCircle(0, 0, 3);
this.x = x;
this.y = y;
horizontal = 1;
vertical = 1;
firing = false;
reload = 0;
slow = false;
left = false;
right = false;
up = false;
down = false;
}
public function registerKey(e:KeyboardEvent):Floater {
var result:Floater = null;
if(e.keyCode == 37){
Cc.log("left");
left = true;
}
else if(e.keyCode == 39){
Cc.log("right");
right = true;
}
else if(e.keyCode == 38){
Cc.log("up");
up = true;
}
else if(e.keyCode == 40){
Cc.log("down");
down = true;
}
else if(e.keyCode == 90){
firing = true;
}
else if(e.keyCode == 16){
slow = true;
}
return result;
}
public function unregisterKey(e:KeyboardEvent):Floater {
var result:Floater = null;
if(e.keyCode == 37){
left = false;
}
else if(e.keyCode == 39){
right = false;
}
else if (e.keyCode == 38){
up = false;
}
else if (e.keyCode == 40){
down = false;
}
else if (e.keyCode == 90) {
firing = false;
}
else if (e.keyCode == 16) {
slow = false;
}
return result;
}
override public function act(index:int):Array {
var sendbacks:Array = [];
this.move();
if(firing && reload <= 0) {
var sendback:Signal = new Signal();
sendback.setFloater(this.fire());
sendback.setIndex(index);
sendbacks.push(sendback);
reload = 4;
}
reload -= 1
return sendbacks;
}
override public function move():void {
var f:Number = 7;
var s:Number = 2;
var xwise:Number = horizontal;
var ywise:Number = vertical;
if( (left && right) || (!left && !right)) {
xwise = 0;
} else if (left) {
xwise = -xwise;
}
if( (down && up) || (!down && !up)) {
ywise = 0;
} else if (up) {
ywise = -ywise;
}
if( !(this.x + 10 < 0 && xwise < 0) && !(this.x + 10 > 500 && xwise > 0)) {
this.x = this.x + xwise * (slow ? s : f);
}
if( !(this.y - 10 < 0 && ywise < 0) && !(this.y + 10 > 800 && ywise > 0)) {
this.y = this.y + ywise * (slow ? s : f);
}
}
public function fire():Projectile {
var bolt:PlaneBolt = new PlaneBolt(this.x , this.y - 15);
return bolt;
}
override public function getType():String {
return "Plane";
}
override public function hurt(n:int):void {
}
override public function radius():Number {return 5;}
override public function image():URLRequest{return imageFile;}
override public function redraw():void {
var dot:Sprite = new Sprite();
dot.graphics.lineStyle(2, 0x000000);
dot.graphics.beginFill(0x0000FF);
dot.graphics.drawCircle(0, 0, 5);
addChild(loader);
addChild(dot);
}
}
}