-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.pde
More file actions
350 lines (334 loc) · 9.8 KB
/
Main.pde
File metadata and controls
350 lines (334 loc) · 9.8 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import processing.sound.*;
//SETUP ----------------------------------
boolean setUp = true; //if setup fails the boolean is changed.
boolean mainMenu = true;
boolean gameOver = false;
boolean gameOverMenu = false;
boolean playing = false;
boolean credits = false;
boolean freeze= false;
boolean won = false;
int counter = 0;
int counter2 = 0;
float speed = 30; //Displacement between each position
int direction = 0; //0=up, 1=right, 2=down, 3=left
PFont font;
PFont fontBig;
//MAINMENU & LASTMENU ----------------------------------
PImage mainMenuImage;
PImage gameOverMenuImage;
//CHARACTER ----------------------------------
int cX = 300;
int cY= 300; //X position and Y position of character (c)
PImage characterUp, characterDown, characterLeft, characterRight;
int matrixPosX = 10; //Starting character X position within the matrix.
int matrixPosY = 10; //Starting character Y position within the matrix
//BACKGROUND&STUFF ----------------------------------
float bX, bY = 0; //Background (b) positions within the screen
float imgWidth = 5064;
float imgHeight = 2154;
PImage background;
//GHOSTS ----------------------------------
PImage ghost;
Ghost g1 = new Ghost(1,19,39);
Ghost g2 = new Ghost(2,43,28);
Ghost g3 = new Ghost(3,80,36);
Ghost g4 = new Ghost(4,108,45);
Ghost g5 = new Ghost(5,137,23);
Ghost g6 = new Ghost(6,151,43);
//FUSES ----------------------------------
PImage fuse;
int fusesNumber = 0;//number of fuses collected
Fuse f1 = new Fuse(1,4,34);
Fuse f2 = new Fuse(2,27,48);
Fuse f3 = new Fuse(3,93,54);
Fuse f4 = new Fuse(4,92,21);
Fuse f5 = new Fuse(5,150,56);
Fuse f6 = new Fuse(6,50,15);
//LANTERN&BATTERY
float battery = 90;
PImage lanternLayer;
//AUDIO ----------------------------------
SoundFile bMusic;
SoundFile allFuses;
SoundFile collectFuse;
SoundFile death;
SoundFile doorOpen;
boolean playedAllFuses = false;
//----------------------------------------------------------------------------------------------------------------------------------------
//SETUP ----------------------------------
void setup(){
size(600,600); //Screen size, 600x600 pixels
mainMenuImage = loadImage("Cover600.png");//MainMenu
gameOverMenuImage = loadImage("fondo.png");
frameRate(30);//30 frames per second
smooth();
background = loadImage("map.png"); //map
lanternLayer = loadImage("lantern.png"); //lantern
characterUp = loadImage("characterUP.png");//character
characterDown = loadImage("characterDOWN.png");//character
characterLeft = loadImage("characterLEFT.png");//character
characterRight = loadImage("characterRIGHT.png");//character
fuse = loadImage("fuse.png");//fuse
ghost = loadImage("ghost.png");//ghost
bMusic = new SoundFile(this,"bMusic.wav");
allFuses = new SoundFile(this,"allFuses.wav");
collectFuse = new SoundFile(this,"collectFuse.wav");
death = new SoundFile(this,"death.wav");
doorOpen = new SoundFile(this,"doorOpen.wav");
bMusic.stop();
bMusic.loop();
font = createFont("Lobster 1.4.otf", 42);
fontBig = createFont("Lobster 1.4.otf", 52);
}
//Screen "drawing" (animations)
void draw(){
//CHECK IF SETUP WAS EXECUTED CORRECTLY----------------------------------
if(!setUp){
background(0,0,0);
textSize(32);
text("Something went wrong", 0,200);
//DISPLAY MAIN MENU ----------------------------------
}else if(mainMenu){
image(mainMenuImage, 0, 0);
textAlign(CENTER);
PFont font;
PFont fontBig;
font = createFont("Lobster 1.4.otf", 42);
fontBig = createFont("Lobster 1.4.otf", 52);
textFont(font);
fill(255, 217, 204);
text("-----·-----", 300, 340);
fill(999, 999, 999);
if(dist(mouseX,mouseY,300, 386)<25){
textFont(fontBig);
text("Play Game", 300, 400);
} else {
textFont(font);
text("Play Game", 300, 400);
}
/*
if(dist(mouseX,mouseY,300,450)<20){
textFont(fontBig);
text("Credits", 300, 460);
} else {
textFont(font);
text("Credits", 300, 460);
} */
//DISPLAY DURING GAME ----------------------------------
}else if(playing) {
counter2++;
background(0);
image(background,bX,bY,imgWidth,imgHeight);
switch(direction){
case 0: image(characterUp,cX,cY,30,30); break;
case 1: image(characterRight,cX,cY,30,30); break;
case 2: image(characterDown,cX,cY,30,30); break;
case 3: image(characterLeft,cX,cY,30,30); break;
}
f1.fusePlacement();
f2.fusePlacement();
f3.fusePlacement();
f4.fusePlacement();
f5.fusePlacement();
f6.fusePlacement();
g1.move();
g2.move();
g3.move();
g4.move();
g5.move();
g6.move();
image(lanternLayer,-50,-50,700,700);
if(counter2 < 300){
displayText();
}
barFuses();
barBattery();
counter++;
if(battery != 0 && counter == 30){
battery--;
counter = 0;
}
if(fusesNumber == 6 && !playedAllFuses){
allFuses.play();
playedAllFuses = true;
}
if(fusesNumber == 6 && (matrixPosX == 159 || matrixPosX == 160) && (matrixPosY == 15 || matrixPosY == 16)){
doorOpen.play();
playing = false;
freeze = true;
won = true;
counter = 0;
}
//DISPLAY AFTER GAMEOVER (FIRST FREEZE THEN MENU)----------------------------------
} else if (gameOverMenu){
image(gameOverMenuImage, 0, 0, 600,600);
textAlign(CENTER);
textFont(font);
fill(255, 217, 204);
text("-----·-----", 300, 340);
fill(999, 999, 999);
textFont(fontBig);
if(won){
text("You won", 300, 260);
} else{
text("You lost", 300, 260);
}
if(dist(mouseX,mouseY,300, 386)<25){
textFont(fontBig);
text("Play Again", 300, 400);
} else {
textFont(font);
text("Play Again", 300, 400);
}
} else if (freeze){
counter++;
if(counter > 120){
gameOverMenu = true;
freeze = false;
}
if(!gameOver){
}else{
background(0);
image(background,bX,bY,imgWidth,imgHeight);
background(0);
image(background,bX,bY,imgWidth,imgHeight);
switch(direction){
case 0: image(characterUp,cX,cY,30,30); break;
case 1: image(characterRight,cX,cY,30,30); break;
case 2: image(characterDown,cX,cY,30,30); break;
case 3: image(characterLeft,cX,cY,30,30); break;
}
f1.fusePlacement();
f2.fusePlacement();
f3.fusePlacement();
f4.fusePlacement();
f5.fusePlacement();
f6.fusePlacement();
g1.move();
g2.move();
g3.move();
g4.move();
g5.move();
g6.move();
image(lanternLayer,-50,-50,700,700);
barFuses();
barBattery();
}
}
}
void keyPressed(KeyEvent e){
if(key == CODED){
try{
if((matrixPosX+1<=168 || matrixPosX-1>=0 || matrixPosY+1<=71 || matrixPosY-1>=0) && playing){
if(keyCode == UP && (limMatrix[matrixPosY-1][matrixPosX] != 1) && (limMatrix[matrixPosY][matrixPosX+1] != 3)){
direction = 0;
bY += speed;
g1.gpy += speed;
g2.gpy += speed;
g3.gpy += speed;
g4.gpy += speed;
g5.gpy += speed;
g6.gpy += speed;
f1.fpy += speed;
f2.fpy += speed;
f3.fpy += speed;
f4.fpy += speed;
f5.fpy += speed;
f6.fpy += speed;
matrixPosY--;
} else if(keyCode == DOWN && (limMatrix[matrixPosY+1][matrixPosX] != 1) && (limMatrix[matrixPosY][matrixPosX+1] != 3)){
direction = 2;
bY -= speed;
g1.gpy -= speed;
g2.gpy -= speed;
g3.gpy -= speed;
g4.gpy -= speed;
g5.gpy -= speed;
g6.gpy -= speed;
f1.fpy -= speed;
f2.fpy -= speed;
f3.fpy -= speed;
f4.fpy -= speed;
f5.fpy -= speed;
f6.fpy -= speed;
matrixPosY++;
} else if(keyCode == LEFT && (limMatrix[matrixPosY][matrixPosX-1] != 1) && (limMatrix[matrixPosY][matrixPosX+1] != 3)){
direction = 3;
bX += speed;
g1.gpx += speed;
g2.gpx += speed;
g3.gpx += speed;
g4.gpx += speed;
g5.gpx += speed;
g6.gpx += speed;
f1.fpx += speed;
f2.fpx += speed;
f3.fpx += speed;
f4.fpx += speed;
f5.fpx += speed;
f6.fpx += speed;
matrixPosX--;
} else if(keyCode == RIGHT && ((limMatrix[matrixPosY][matrixPosX+1] != 1)) && (limMatrix[matrixPosY][matrixPosX+1] != 3)){
direction = 1;
bX -= speed;
g1.gpx -= speed;
g2.gpx -= speed;
g3.gpx -= speed;
g4.gpx -= speed;
g5.gpx -= speed;
g6.gpx -= speed;
f1.fpx -= speed;
f2.fpx -= speed;
f3.fpx -= speed;
f4.fpx -= speed;
f5.fpx -= speed;
f6.fpx -= speed;
matrixPosX++;
} else if(keyCode == UP){
direction = 0;
} else if(keyCode == DOWN){
direction = 2;
} else if(keyCode == RIGHT){
direction = 1;
} else if(keyCode == LEFT){
direction = 3;
} else if(keyCode == 32){ //SPACE BAR ASCII = 32
}
}
} catch(Exception f){
}
}
}
void mouseClicked(){
if(dist(mouseX,mouseY,300, 386)<25 && (mainMenu == true || gameOverMenu == true)){
mainMenu = false;
gameOver = false;
gameOverMenu = false;
playing = true;
f1 = new Fuse(1,4,34);
f2 = new Fuse(2,27,48);
f3 = new Fuse(3,93,54);
f4 = new Fuse(4,92,21);
f5 = new Fuse(5,150,56);
f6 = new Fuse(6,50,15);
g1 = new Ghost(1,19,39);
g2 = new Ghost(2,43,28);
g3 = new Ghost(3,80,36);
g4 = new Ghost(4,108,45);
g5 = new Ghost(5,137,23);
g6 = new Ghost(6,151,43);
bX = 0;
bY = 0;
fusesNumber = 0;
battery = 90;
matrixPosX = 10;
matrixPosY = 10;
}
if(dist(mouseX,mouseY,300,450)<20 && (mainMenu == true || gameOverMenu == true)){
mainMenu = false;
freeze = false;
gameOverMenu = false;
credits = true;
}
}