-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
182 lines (165 loc) · 4.59 KB
/
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* Greedy Pirates
* Art + Music: Eli
* Music: Ez (the first drafts)
* Coding and Fill in the Gap: Chris
*
* Top down level select to pick which island to visit.
* Once an island is picked, a side-scrolling multiplayer beat-em-up game
* [phase 1 end]
* At the end of each level is a treasure, that is added to the totals
* Pirates must stash their treasure on their own island
* When you beat a level/island you "claim" that island with your flag
* Other pirates will attack islands and claim them
* Claiming an island will allow you to slowly gain treasure (that stays on that island)
* You must visit your own islands and move the treasure to your own treasure island
*/
enum States {
Menu,
Overview,
Island,
AllDead,
TreasureIsland,
Travel,
BoatBattle,
GameOver,
Win
}
enum SpriteKind {
PlayerAttackLeft,
PlayerAttackRight,
}
const playerState = {
currentIsland: ''
}
const version: string = 'v1.2'
const debugMode: boolean = false
let currentState: States
let currentIsland: Map.Island = Map.islands[0]
let treasureSprite: Sprite
console.log('Yarrrgh! Thee Kraken lives in this here code!')
game.onUpdate(() => {
switch(currentState) {
case States.Overview:
Map.render()
break;
case States.Island:
Island.render();
break;
case States.BoatBattle:
BoatBattle.render()
break;
case States.TreasureIsland:
TreasureIsland.render()
break;
default:
break;
}
})
if (debugMode) {
game.onUpdateInterval(5000, () => {
console.log('Delta ' + control.eventContext().deltaTimeMillis)
// GC Stats only works on hardware
// console.log('Mem: ' + control.gcStats())
control.heapSnapshot()
})
}
function switchState(state: States) {
currentState = state
switch (currentState) {
case States.Overview:
Map.init({ islands: Map.islands, currentIsland })
break;
case States.Island:
Island.init({ island: currentIsland })
break;
case States.BoatBattle:
BoatBattle.init()
break;
case States.AllDead:
AllDead.init()
break;
case States.GameOver:
GameOver.init()
break;
case States.Win:
Win.init()
break;
case States.Travel:
Travel.init({ targetIsland: currentIsland })
break;
case States.TreasureIsland:
TreasureIsland.init()
break;
case States.Menu:
default:
Menu.init()
}
}
function startGame(initialState?: States) {
Map.onSelectIsland((island: Map.Island) => {
if (currentIsland && island.id !== currentIsland.id) {
currentIsland = island
switchState(States.Travel)
} else if (island.id === 0) {
currentIsland = island
switchState(States.TreasureIsland)
} else {
currentIsland = island
// If you re-select the same island you don't floatyboaty
switchState(States.Island)
}
})
Map.onWin(() => {
switchState(States.Win)
})
Island.onLeaveIsland(() => {
switchState(States.Overview)
})
Island.onAllDead(() => {
if (PirateLives.currentPirateCount <= 0) {
switchState(States.GameOver)
} else {
switchState(States.AllDead)
}
})
BoatBattle.onWin(() => {
if (currentIsland.id === 0) {
switchState(States.TreasureIsland)
} else {
switchState(States.Island)
}
})
BoatBattle.onLoose(() => {
if (PirateLives.currentPirateCount <= 0) {
switchState(States.GameOver)
} else if (currentIsland.id === 0) {
switchState(States.TreasureIsland)
} else {
switchState(States.Overview)
}
})
Travel.onBoatBattle(() => {
switchState(States.BoatBattle)
})
Travel.onLandOnIsland(() => {
currentIsland = currentIsland ? currentIsland : Map.islands[0]
if (currentIsland.id === 0) {
// Our own Island
switchState(States.TreasureIsland)
} else {
switchState(States.Island)
}
})
TreasureIsland.onComplete(() => {
switchState(States.Overview)
})
Menu.onStartGame(() => {
switchState(States.Overview)
})
AllDead.onRevive(() => {
switchState(States.Overview)
})
switchState(initialState ? initialState : States.Menu)
}
startGame()