-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
192 lines (148 loc) · 4.38 KB
/
index.js
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
183
184
185
186
187
188
189
190
191
192
function preload() {
keys = []
for (let x = 0; x < 10; x++) {
keys.push(loadImage("assets/images/keys/" + x + ".png"))
}
// fonts
font_backbones = loadFont("assets/fonts/Backbones.ttf")
font_coolvetica = loadFont("assets/fonts/coolvetica.ttf")
// background
bg1 = loadImage("assets/images/background-1.png");
bg2 = loadImage("assets/images/background-2.png");
bg3 = loadImage("assets/images/background-3.png");
bg4 = loadImage("assets/images/background-4.png");
// sprites
sprites = new GenerateSprites()
sprites.keys = keys
sprites.availableKeys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
sprites.evilImages = []
sprites.evilImages.push(loadImage("assets/images/crab.png"))
sprites.evilImages.push(loadImage("assets/images/chipmunk.png"))
sprites.evilImages.push(loadImage("assets/images/bird.png"))
sprites.evilImages.push(loadImage("assets/images/duck.png"))
sprites.evilImages.push(loadImage("assets/images/chick.png"))
sprites.evilImages.push(loadImage("assets/images/penguin.png"))
sprites.evilImages.push(loadImage("assets/images/hedgehog.png"))
sprites.evilImages.push(loadImage("assets/images/skunk.png"))
sprites.evilImages.push(loadImage("assets/images/swan.png"))
sprites.evilImages.push(loadImage("assets/images/turkey.png"))
sprites.desertEmojis = []
sprites.desertEmojis.push(loadImage("assets/images/scorpion.png"))
sprites.desertEmojis.push(loadImage("assets/images/snake.png"))
sprites.desertEmojis.push(loadImage("assets/images/camel.png"))
sprites.desertEmojis.push(loadImage("assets/images/2camel.png"))
sprites.desertEmojis.push(loadImage("assets/images/cockroach.png"))
crabGif = loadImage("assets/images/crab.gif")
soundFormats('wav', 'ogg');
bling = loadSound("assets/audio/bling.wav")
boop = loadSound("assets/audio/boop.wav")
doh = loadSound("assets/audio/doh.wav")
tsk = loadSound("assets/audio/tsk.wav")
game_over = loadSound("assets/audio/game_over.ogg")
}
function setup() {
const cw = 1280
const ch = 720
createCanvas(cw, ch);
// title screen
titleScreen = new TitleScreen();
titleScreen.titleFont = font_backbones;
titleScreen.buttonFont = font_coolvetica;
titleScreen.cw = cw;
titleScreen.ch = ch - 30;
//bg3 = loadImage("assets/images/background-1.png");
titleBg = new Background();
titleBg.bg = bg1;
// initial speed
titleBg.bgSpeed = 1.75;
currentModal = {};
currentModal.show = function () {
return;
}
// game setup
game = {};
game.show = function () {
return;
}
inGame = true
}
function startGame(mode) {
player = sprites.playerSprite()
sprites.keys = keys
titleScreen.active = false;
game = new Game();
// settings
game.font = font_coolvetica;
game.player = player;
game.mode = mode;
game.active = true;
inGame = game.inGame
game.sprites = sprites
// sounds
game.bling = bling
game.boop = boop
game.doh = doh
game.game_over = game_over
game.tsk = tsk
game.startGameFromTutorial = function () {
localStorage.setItem("tutorial_done", true)
startGame("game")
}
}
function draw() {
// show title background
let currentScore = round(game.score * 10) || 0
titleBg.moving = true
if (currentScore < 300) {
titleBg.bg = bg1
} else if (currentScore > 300 && currentScore < 500) {
titleBg.bg = bg2
} else if (currentScore > 500 && currentScore < 700) {
titleBg.bg = bg3
} else if (currentScore > 700 && currentScore < 1000) {
titleBg.bg = bg4
} else if (currentScore > 1000) {
titleBg.bg = crabGif
titleBg.moving = false
}
titleBg.show();
// code after this (background must be first)
// render a modal
if (currentModal.active) {
titleScreen.active = false
currentModal.show();
}
// show title screen
if (titleScreen.active) {
titleScreen.show();
}
if (game.active) {
game.show();
} else {
titleScreen.active = true
}
drawSprites();
titleScreen.onPlay = function () {
tutorialDone = localStorage.getItem("tutorial_done")
if (!tutorialDone) {
currentModal = new Modal()
currentModal.text = "You must complete the tutorial first.";
currentModal.font = font_coolvetica;
currentModal.closeModal = function () {
titleScreen.active = true;
currentModal.hide();
}
currentModal.active = true;
// have completed the tutorial
// start playing game
titleScreen.hide();
} else if (inGame) {
startGame("game");
}
}
titleScreen.onTutorial = function () {
// start the tutorial
titleScreen.hide();
startGame("tutorial")
}
}