-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAchievements.hx
69 lines (59 loc) · 1.63 KB
/
Achievements.hx
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
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
class Achievements {
static var ach = new Hash<{ name : String, desc : String, achieved : Bool}>();
static var displaybox : AchievementTextField;
public static function init() {
displaybox = new AchievementTextField();
Game.rootmc.addChild(displaybox);
add("killturt", "You killed a turtle!");
add("killgwill", "You killed a gwillen!");
}
static function add(name : String, desc : String) {
if (!ach.exists(name)) {
ach.set(name, { name : name, desc : desc, achieved : false });
}
}
public static function got(name : String) {
var a = ach.get(name);
if (a.achieved == false) {
a.achieved = true;
ach.set(name, a);
trace("Player got achievement: " + a.desc);
displaybox.set("Achievement unlocked:\n" + a.desc);
}
}
public static function tick() {
displaybox.tick();
}
}
class AchievementTextField extends TextField{
public function new() {
super();
width = 300;
height = 66;
x = (600 - width)/2;
y = (600 - height)/2;
textColor = 0x0000CF;
selectable = false;
defaultTextFormat = new TextFormat("Comic Sans", 30, null, null, null, null, null, null, TextFormatAlign.CENTER);
background = true;
backgroundColor = 0xFFFFFF;
visible = false;
alpha = 0.4;
}
public function set(s : String) {
text = s;
timer = 20;
visible = true;
}
public function tick() {
if (timer > 0) {
timer--;
} else {
visible = false;
}
}
static var timer : Int = 0;
}