-
Notifications
You must be signed in to change notification settings - Fork 0
/
treasureIsland.ts
101 lines (83 loc) · 2.77 KB
/
treasureIsland.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace TreasureIsland {
let _onComplete: () => void
let pirate1: Pirate
let pirate2: Pirate
let treasure: Sprite
let island: Sprite
let waves: Sprite[] = []
const waveAnimation: Image[] = Utils.swapAnimationColors(assets.animation`wave`, 9, 6)
const _boundaries: number[] = [10, 70, 150, 110]
export function init() {
scene.setBackgroundColor(9)
island = sprites.create(assets.image`Treasarr Island`)
island.x = 80
island.y = 60
island.z = 1
Utils.getArrayOfLength(10).forEach(() => {
const wave = sprites.create(assets.animation`wave`[0])
animation.runImageAnimation(
wave,
waveAnimation,
500,
true
)
wave.x = Math.randomRange(10, 150)
wave.y = Math.randomRange(10, 60)
wave.z = 0
waves.push(wave)
})
pirate1 = new Pirate({
control: controller.player1,
playerNumber: 0,
onAttack: touchTreasure,
onDie: () => {},
boundaries: _boundaries
})
pirate2 = new Pirate({
control: controller.player2,
playerNumber: 1,
onAttack: touchTreasure,
onDie: () => { },
boundaries: _boundaries
})
pirate1.sprite.x = 23
pirate1.sprite.y = 80
pirate2.sprite.x = 23
pirate2.sprite.y = 95
treasure = sprites.create(assets.image`Chest`)
treasure.x = 120
treasure.y = 85
treasure.z = 85
music.play(music.createSong(assets.song`Treasure Island Theme`), music.PlaybackMode.LoopingInBackground)
}
export function onComplete(callback: () => void) {
_onComplete = callback
}
export function render() {
pirate1.render()
pirate2.render()
}
function destroy() {
pirate1.destroy()
pirate2.destroy()
treasure.destroy()
island.destroy()
waves.forEach(wave => wave.destroy())
scene.setBackgroundColor(0)
scene.setBackgroundImage(assets.image`empty`)
music.stopAllSounds()
}
function touchTreasure({ pirate }: AttackCallbackParams) {
if (Utils.getDistance(pirate.sprite, treasure) < 12) {
game.showLongText('Ye have stashed ' + TreasureStats.currentTreasure.onBoat + ' coin on ye island for safe keepin\' ', DialogLayout.Center)
TreasureStats.currentTreasure = {
onBoat: 0,
onIsland: TreasureStats.currentTreasure.onIsland + TreasureStats.currentTreasure.onBoat,
inPocket: 0
}
TreasureStats.show({})
destroy()
_onComplete()
}
}
}