-
Notifications
You must be signed in to change notification settings - Fork 0
/
travel.ts
93 lines (79 loc) · 2.73 KB
/
travel.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
namespace Travel {
let _onBoatBattle: () => void
let _onLandOnIsland: () => void
let _videoSprite: Sprite
let _textSprite: Sprite
const _startAnimation: Image[] = assets.animation`Boat Float`
const _pirateAnimation: Image[] = assets.animation`Boat Float Enemy Spotted`
const _islandAnimation: Image[] = assets.animation`Boat Float Island`
export function init({ targetIsland }: { targetIsland: Map.Island }) {
// Probably should have done this better... oh well
let result = Math.min((TreasureStats.currentTreasure.onBoat / 500) * 100, 100)
// Odds are different if you are heading to your island
if (targetIsland.id === 0) {
result = Math.min((TreasureStats.currentTreasure.onBoat / 200) * 100, 100)
}
scene.setBackgroundColor(0)
scene.setBackgroundImage(assets.image`empty`)
_videoSprite = sprites.create(image.create(80, 60))
_videoSprite.x = 80
_videoSprite.y = 60
animation.runImageAnimation(
_videoSprite,
_startAnimation,
500,
true
)
// Animate!
_textSprite = textsprite.create('Floaty boaty', 0, 14)
_textSprite.x = 80
_textSprite.y = 100
pause(2000)
if (result > Math.randomRange(0,100)) {
animation.runImageAnimation(
_videoSprite,
_pirateAnimation,
500,
false
)
_textSprite.destroy()
_textSprite = textsprite.create('Thar be pirates!')
_textSprite.x = 80
_textSprite.y = 100
pause(_pirateAnimation.length * 500 + 1000)
destroy()
_onBoatBattle()
} else {
animation.runImageAnimation(
_videoSprite,
_islandAnimation,
500,
false
)
_textSprite.destroy()
const text = targetIsland.id === 0 ? 'Ye made it home!' : 'Arrgh, steal thee loot!'
_textSprite = textsprite.create(text)
_textSprite.x = 80
_textSprite.y = 100
pause(_islandAnimation.length * 500 + 1000)
destroy()
_onLandOnIsland()
}
}
function destroy() {
if (_textSprite) {
_textSprite.destroy()
}
if (_videoSprite) {
_videoSprite.destroy()
}
scene.setBackgroundImage(assets.image`empty`)
scene.setBackgroundColor(0)
}
export function onBoatBattle(callback: () => void) {
_onBoatBattle = callback
}
export function onLandOnIsland(callback: () => void) {
_onLandOnIsland = callback
}
}