-
Notifications
You must be signed in to change notification settings - Fork 58
/
Farmland.as
executable file
·44 lines (35 loc) · 1.36 KB
/
Farmland.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
package
{
import flash.geom.Point;
import org.flixel.FlxSprite;
import org.flixel.FlxG;
import org.flixel.FlxObject;
import org.flixel.FlxPoint;
public class Farmland extends FlxSprite implements Workable{
[Embed(source='/assets/gfx/farmland.png')] private var FarmlandImg:Class;
public static const WORK_COOLDOWN:Number = 8;
private var t:Number = 0;
public function Farmland(X:int, Y:int){
super(X,Y);
loadGraphic(FarmlandImg, true, false, 64, 32);
addAnimation("grow",[0,1,2,3,4,5,6,7],10);
}
public function needsWork():Boolean {
return t > WORK_COOLDOWN;
}
public function work(by:Citizen=null):void{
t = 0;
if (frame == 7){
((FlxG.state as PlayState).coins.recycle(Coin) as Coin).drop(this, by);
((FlxG.state as PlayState).coins.recycle(Coin) as Coin).drop(this, by);
((FlxG.state as PlayState).coins.recycle(Coin) as Coin).drop(this, by);
((FlxG.state as PlayState).coins.recycle(Coin) as Coin).drop(this, by);
by.pickNewGoal(x+width/2);
}
frame = (frame + 1) % 8;
}
override public function update():void{
t += FlxG.elapsed;
}
}
}