-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ship.as
40 lines (39 loc) · 1.13 KB
/
Ship.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
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import com.junkbyte.console.Cc;
public class Ship extends Floater {
private var health:int;
public static var player:Ship;
public function getRatio():Array {
var changeX:Number = player.x - this.x;
var changeY:Number = player.y - this.y;
var magnitude:Number = Math.sqrt(changeY * changeY + changeX * changeX);
changeY = changeY / magnitude;
changeX = changeX / magnitude;
var components:Array = new Array();
components.push(changeX);
components.push(changeY);
return components;
}
public function initialize(type:String):void {
}
public function setVelocity(x:Number, y:Number):void {
xVelocity = x;
yVelocity = y;
}
public function hurt(n:int):void {
health = health - n;
}
public function getHealth():int {
return health;
}
public function die():void {
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, setImage);
loader.load(deathImage());
}
public function deathImage():URLRequest{ return new URLRequest("images/explosion.gif");}
}
}