forked from theblackcascade/Invaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObject.as
78 lines (69 loc) · 2.02 KB
/
GameObject.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
package
{
import flash.display.Sprite;
import flash.events.Event;
public class GameObject extends Sprite
{
public var isDead:Boolean = false;
public var isRemoved:Boolean = false;
public var type:String = new String;
private var targetX:Number = 0;
private var targetY:Number = 0;
public function GameObject()
{
targetX = this.x;
}
public function startFollowing(_x:int,_y:int):void
{
targetX = _x;
targetY = _y;
}
public function follow():void
{
if(this.x < this.targetX) this.x++;
else if(this.x > this.targetX) this.x--;
if(this.y < this.targetY) this.y++;
else if(this.y > this.targetY) this.y--;
}
public function stopFollowing():void
{
targetX = this.x;
}
public function updatePosition():void
{
follow();
if((this.type == "bullet") && this.y < 10)
{
GameObjectPool.Instance.Search("bullet").x = -20;
GameObjectPool.Instance.Search("bullet").y = -20;
Game.Instance.removeChild(GameObjectPool.Instance.Search("bullet"));
GameObjectPool.Instance.Objects.pop();
}
else if((this.type == "alien0") ||(this.type == "alien1") ||(this.type == "alien2"))
if(GameObjectPool.Instance.Search("bullet") != null)
if(this.hitTestObject(GameObjectPool.Instance.Search("bullet")))
{
this.isDead = true;
GameObjectPool.Instance.Search("bullet").x = -20;
GameObjectPool.Instance.Search("bullet").y = -20;
Game.Instance.removeChild(GameObjectPool.Instance.Search("bullet"));
GameObjectPool.Instance.Objects.pop();
}
if((this.type == "alien0") ||(this.type == "alien1") ||(this.type == "alien2"))
if(this.y >= 300)
Game.Instance.removeEventListener(Event.ENTER_FRAME,Game.Instance.Loop);
}
public function startFire():void
{
var object:GameObject = new GameObject();
object.x = this.x;
object.y = this.y
object.type = "bullet";
object.startFollowing(this.x,0);
GameObjectPool.Instance.Objects.push(object);
}
public function stopFire():void
{
}
}
}