-
Notifications
You must be signed in to change notification settings - Fork 58
/
Arrow.as
executable file
·50 lines (42 loc) · 1.46 KB
/
Arrow.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
package
{
import flash.geom.Point;
import org.flixel.FlxParticle;
import org.flixel.FlxG;
import org.flixel.FlxObject;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
public class Arrow extends FlxParticle{
[Embed(source='/assets/gfx/arrow.png')] private var Img:Class;
public var shooter:Citizen = null;
public function Arrow(){
super();
loadRotatedGraphic(Img);
maxVelocity.x = 200;
maxVelocity.y = 275;
acceleration.y = 500;
offset.x = 3;
offset.y = 3;
height = 2;
width = 2;
elasticity = 0.5;
}
public function shotFrom(from:Citizen, at:FlxObject):void{
x = from.x + from.width/2 + (from.facing == RIGHT ? 6 : -6);
y = from.y + 10;
revive();
velocity.x = (from.facing == RIGHT ? maxVelocity.x : -maxVelocity.x);
velocity.y = - Math.abs(at.x - from.x) + FlxG.random()*40;
lifespan = 10;
shooter = from;
}
override public function update():void{
if (y > (FlxG.state as PlayState).water.y){
kill();
var s:Splash = (FlxG.state as PlayState).fx.recycle(Splash) as Splash;
s.reset(x,y);
}
angle = (180/Math.PI) * Math.atan2(velocity.y, velocity.x);
}
}
}