forked from github/game-off-2012
/
HumanOutline.as
72 lines (60 loc) · 2.44 KB
/
HumanOutline.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
70
71
72
package {
import flash.display.BitmapData;
import net.flashpunk.Entity;
import net.flashpunk.World;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Text;
/**
* Helper class for drawing the overall progress bar.
*/
public class HumanOutline {
// the outline should be behind pretty much everything else
private static const LAYER:int = 9999;
[Embed(source='assets/human_outline.png')]
private const OUTLINE:Class;
private var outline:Entity = new Entity;
private var progressBar:Entity = new Entity;
private var percentText:Text = new Text("0%");
private var percentTextEntity:Entity;
public function HumanOutline(world:World, x:uint, y:uint) {
outline.graphic = new Image(OUTLINE);
outline.layer = LAYER;
outline.x = x;
outline.y = y;
progressBar.graphic = new Image(new BitmapData(65, 1, false, 0xb2e335));
progressBar.layer = LAYER;
progressBar.x = x;
progressBar.y = y + 116;
percentText.font = "MainFont"; // embedded in MyWorld.as
percentText.color = 0xfafafa;
percentText.size = 28;
percentTextEntity = new Entity;
percentTextEntity.graphic = percentText;
percentTextEntity.layer = LAYER;
percentTextEntity.x = outline.x + 2 + 65 / 2 - percentText.width / 2;
percentTextEntity.y = outline.y + 60 - percentText.height / 2;
world.add(progressBar);
world.add(outline);
world.add(percentTextEntity);
}
/**
* Update the completion percentage.
*/
public function set progress(percent:uint):void {
percentText.text = percent + "%";
percentTextEntity.x = outline.x + 2 + 65 / 2 - percentText.width / 2;
percentTextEntity.y = outline.y + 60 - percentText.height / 2;
var h:uint = Math.max(112 * (percent / 100), 1);
progressBar.graphic = new Image(new BitmapData(65, h, false, 0xb2e335));
progressBar.y = outline.y + 116 - h;
}
/**
* Bring the graphics forward above the overlay layer (used in the death sequence).
*/
public function toForeground():void {
progressBar.layer = 0;
percentTextEntity.layer = 0;
outline.layer = 0;
}
}
}