-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpirateLives.ts
36 lines (32 loc) · 1012 Bytes
/
pirateLives.ts
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
namespace PirateLives {
let _liveCountSprite: Sprite
let _liveCountIcon: Sprite
export let currentPirateCount: number = 10
// If a pirate dies, call this with a negative number
export function updatePirateCount(byHowMuch: number) {
currentPirateCount += byHowMuch
if (currentPirateCount < 0) {
currentPirateCount = 0
}
show()
}
export function show() {
hide()
_liveCountIcon = sprites.create(assets.image`Pirate Lives`)
_liveCountIcon.x = 5
_liveCountIcon.y = 115
_liveCountIcon.z = 120
_liveCountSprite = textsprite.create(currentPirateCount + '', 0, 1)
_liveCountSprite.x = 8 + 5 + (_liveCountSprite.width / 2)
_liveCountSprite.y = 115
_liveCountSprite.z = 120
}
export function hide() {
if (_liveCountSprite) {
_liveCountSprite.destroy()
}
if (_liveCountIcon) {
_liveCountIcon.destroy()
}
}
}