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
|
package fortress;
/**
* Temporarily shows the HP for an object.
*/
class HPLiveObject extends LiveObject
{
var trackLO : LiveObject;
var timeout : Float;
public function new( gd :GameDriver, lo : LiveObject )
{
super( gd );
actMode = LiveObject.actInvisible;
timeout = 2;
trackLO = lo;
at = lo.at; //just use
draw();
}
override private function draw( )
{
graphics.clear();
//assume objects are centered
graphics.beginFill( 0x808080 );
graphics.drawRect(
-GConst.gridSizeX/2,
GConst.gridSizeY * trackLO.size.y / 2,
GConst.gridSizeX,
GConst.gridSizeY/4
);
graphics.endFill( );
graphics.beginFill( 0x800000 );
graphics.drawRect(
-GConst.gridSizeX/2,
GConst.gridSizeY * trackLO.size.y / 2,
GConst.gridSizeX / trackLO.maxHP * trackLO.hp,
GConst.gridSizeY/4
);
graphics.endFill();
}
override public function step( elapsed :Float ) : StepResult
{
timeout -= elapsed;
if( timeout <= 0 || trackLO.hp <= 0 ) //also if the tracked object has no more HPs
return StepResult.Remove;
at = trackLO.at; //no copy
return StepResult.Changed;
}
}
|