forked from noio/kingdom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Coin.as
executable file
·69 lines (61 loc) · 2.16 KB
/
Coin.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
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 Coin extends FlxParticle{
[Embed(source='/assets/gfx/coin.png')] private var Img:Class;
public static const TOTAL_LIFESPAN:Number = 25;
public static const OWNER_LIFESPAN:Number = 4;
public var owner:FlxObject = null;
public var justThrown:Boolean = false;
public var called:Boolean = false;
public function Coin(){
super();
loadGraphic(Img,true,false,10,10);
maxVelocity.x = 20;
maxVelocity.y = 275;
acceleration.y = 900;
addAnimation('spin',[0,1,2,3,4,5,6,7],10,true);
play('spin');
elasticity = 0.5;
}
public function drop(from:FlxSprite, owner:FlxObject=null, far:Boolean=false):Coin{
reset(from.x + from.width/2 - 5, Math.max(40, from.y - 10));
lifespan = TOTAL_LIFESPAN;
if (far){
velocity.x = FlxG.random()*140 - 70;
velocity.y = -180;
} else {
velocity.x = FlxG.random()*60 - 30;
velocity.y = -180;
}
called = false;
this.owner = owner;
if (owner != null && owner is Citizen){
(owner as Citizen).pickNewGoal(this.x + this.width/2 + this.velocity.x)
}
return this;
}
override public function update():void{
if (!called && lifespan <= TOTAL_LIFESPAN - OWNER_LIFESPAN / 2) {
justThrown = false;
var cit:Citizen = owner as Citizen;
if (cit){
called = true;
justThrown = false;
flicker();
cit.pickNewGoal(x+width/2);
}
}
if (owner != null && lifespan <= TOTAL_LIFESPAN - OWNER_LIFESPAN){
flicker();
owner = null;
}
super.update()
}
}
}