-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
534 lines (482 loc) · 20.9 KB
/
index.html
File metadata and controls
534 lines (482 loc) · 20.9 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crossing ND Game</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/p5.min.js"></script>
<style>
/* Basic styling to center the canvas and remove default browser margins/padding */
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
display: flex; /* Use flexbox for easy centering */
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
background-color: #333; /* A dark background color */
overflow: hidden; /* Hide scrollbars if the canvas is slightly larger than viewport */
}
canvas {
display: block; /* Removes extra space below the canvas element */
border: 2px solid #555; /* Optional: adds a subtle border around the game */
}
</style>
</head>
<body>
<script>
// User-defined NPC class
class NPC {
constructor(initialX, initialY, npcSpeed, minBoundaryY, maxBoundaryY, img, up) {
this.x = initialX;
this.y = initialY;
this.speed = npcSpeed;
this.minY = minBoundaryY;
this.maxY = maxBoundaryY;
this.npcImage = img;
this.up = up;
}
display() {
image(this.npcImage, this.x, this.y);
}
update() {
// Player collision check
// Assuming player width/height are roughly 15/30, adjust if your player image is different
if (
px - 15 / 2 < this.x + 15 / 2 &&
px + 15 / 2 > this.x - 15 / 2 &&
py - 30 / 2 < this.y + 30 / 2 &&
py + 30 / 2 > this.y - 30 / 2
) {
hit();
}
if (this.up) {
this.y -= this.speed;
if (this.y < this.maxY) {
this.y = this.minY;
}
} else {
this.y += this.speed;
if (this.y > this.maxY) {
this.y = this.minY;
}
}
}
}
// All global variables
let background0, background1, background2, background3, player;
let playerDead, playerW1, playerW2, playerW3, playerW4, playerW5, playerW6;
let playerA1, playerA2, playerA3, playerA4, playerA5, playerA6;
let playerS1, playerS2, playerS3, playerS4, playerS5, playerS6;
let playerD1, playerD2, playerD3, playerD4, playerD5, playerD6;
let textFont_game, titleFont_game;
let dw, dh;
let px, py;
let dx = 2;
let dy = 2;
let lock = true;
let W = 1;
let A = 1;
let S = 1;
let D = 1;
let screen = 0;
let info = false;
let egg = false;
let npcDown = [];
let npcUp = [];
let NPC1 = [];
let NPC2 = [];
let lives = 1;
// Key state tracking variables
let keys = {};
// Preload function to load assets before setup
function preload() {
background0 = loadImage("assets/background00.jpg");
background1 = loadImage("assets/background01.jpg");
background2 = loadImage("assets/background02.jpg");
background3 = loadImage("assets/background03.jpg");
playerW1 = loadImage("assets/front (1).png");
playerW2 = loadImage("assets/front (2).png");
playerW3 = loadImage("assets/front (3).png");
playerW4 = loadImage("assets/front (4).png");
playerW5 = loadImage("assets/front (5).png");
playerW6 = loadImage("assets/front (6).png");
playerA1 = loadImage("assets/left (1).png");
playerA2 = loadImage("assets/left (2).png");
playerA3 = loadImage("assets/left (3).png");
playerA4 = loadImage("assets/left (4).png");
playerA5 = loadImage("assets/left (5).png");
playerA6 = loadImage("assets/left (6).png");
playerS1 = loadImage("assets/back (1).png");
playerS2 = loadImage("assets/back (2).png");
playerS3 = loadImage("assets/back (3).png");
playerS4 = loadImage("assets/back (4).png");
playerS5 = loadImage("assets/back (5).png");
playerS6 = loadImage("assets/back (6).png");
playerD1 = loadImage("assets/right (1).png");
playerD2 = loadImage("assets/right (2).png");
playerD3 = loadImage("assets/right (3).png");
playerD4 = loadImage("assets/right (4).png");
playerD5 = loadImage("assets/right (5).png");
playerD6 = loadImage("assets/right (6).png");
playerDead = loadImage("assets/playerDead (1).png");
npcDown[0] = loadImage("assets/down (1).png");
npcDown[1] = loadImage("assets/down (2).png");
npcDown[2] = loadImage("assets/down (3).png");
npcUp[0] = loadImage("assets/up (1).png");
npcUp[1] = loadImage("assets/up (2).png");
npcUp[2] = loadImage("assets/up (3).png");
textFont_game = loadFont("assets/stardewValleyText.ttf");
titleFont_game = loadFont("assets/stardewValleyTitle.ttf");
}
function setup() {
createCanvas(640, 360);
dw = width;
dh = height;
background0.resize(dw, dh);
background1.resize(dw, dh);
background2.resize(dw, dh);
background3.resize(dw, dh);
px = 30;
py = dh / 2;
imageMode(CENTER);
player = playerW1;
setup1();
}
function draw() {
handleMovement(); // Player movement handled here
switch (screen) {
case 0:
image(background0, width / 2, height / 2);
push();
rectMode(CENTER);
noStroke(); // Ensure no stroke for these elements
fill(200, 150, 100, 240);
rect(width / 2, height / 2 - 60, 400, 100);
rect(width / 2, height / 2 + 50, 100, 40);
textAlign(CENTER);
textFont(titleFont_game);
fill(110, 70, 30);
textSize(48);
text("Crossing ND", width / 2, height / 2 - 30);
textFont(textFont_game);
fill(110, 70, 30);
textSize(24);
text("Start", width / 2, height / 2 + 60);
pop();
break;
case 1:
image(background1, width / 2, height / 2);
image(player, px, py);
screen1();
break;
case 2:
image(background2, width / 2, height / 2);
image(player, px, py);
screen2();
break;
case 3:
// This is the "Congratulations" screen, it is handled in gameOver
// but also here for consistency if screen is directly set to 3.
// The actual drawing of the "Congratulations" popup is done within restart() and gameOver()
// or just once when screen becomes 3 and noLoop is called.
image(background3, width / 2, height / 2);
drawWinScreen(); // Call a dedicated function to draw the win screen
break;
}
// Draw popups if active, ensure they are always on top
if (info) {
drawInfoPopup();
}
if (egg) {
drawEggPopup();
}
}
// Dedicated drawing function for the "Congratulations" screen
function drawWinScreen() {
push();
rectMode(CENTER);
stroke(110, 70, 30);
strokeWeight(5);
fill(200, 150, 100, 240);
rect(width / 2, height / 2, 300, 200);
textAlign(CENTER);
// Apply noStroke for text specifically
noStroke(); // <--- CRITICAL FIX: No stroke for text
textFont(textFont_game);
fill(110, 70, 30);
textSize(32);
text("Congratulations!", width / 2, 115);
textSize(20);
text("You have crossed Notre Dame (for now)", width / 2, 150);
text("Press (R) to reset", width / 2, 180);
text("Game by Evaristo CAR using Processing", width / 2, 210);
text("Special thanks to Prof. Ramzi", width / 2, 240);
pop();
}
// Dedicated drawing function for the Info popup
function drawInfoPopup() {
push();
rectMode(CENTER);
stroke(110, 70, 30);
strokeWeight(5);
fill(200, 150, 100, 240);
rect(width / 2, height / 2, 300, 200);
textAlign(CENTER);
// Apply noStroke for text specifically
noStroke(); // <--- CRITICAL FIX: No stroke for text
textFont(textFont_game);
fill(110, 70, 30);
textSize(32);
text("Crossing ND - Guide", width / 2, 115);
textSize(20);
text("Press (ENTER) to start", width / 2, 150);
text("Press (W)(A)(S)(D) to move", width / 2, 180);
text("Press (E) to interact", width / 2, 210);
text("Press (I) to pause and toggle info", width / 2, 240);
pop();
}
// Dedicated drawing function for the Easter Egg popup
function drawEggPopup() {
push();
rectMode(CENTER);
stroke(110, 70, 30);
strokeWeight(5);
fill(200, 150, 100, 240);
rect(width / 2, height / 2, 300, 200);
textAlign(CENTER);
// Apply noStroke for text specifically
noStroke(); // <--- CRITICAL FIX: No stroke for text
textFont(textFont_game);
fill(110, 70, 30);
textSize(32);
text("Easter Egg", width / 2, 115);
textSize(20);
text("Welcome to Knights of Columbus", width / 2, 150);
text("It's gameday and you bought a steak", width / 2, 180);
text("Your speed has been enhanced", width / 2, 210);
text("This effect is only applied once", width / 2, 240);
pop();
}
// keyPressed() p5.js function
function keyPressed() {
keys[key.toLowerCase()] = true; // Mark key as pressed
if (keyCode === ENTER && lock) {
lock = false;
screen = 1;
} else if (!lock) {
switch (key.toLowerCase()) {
case 'r':
// This case handles restart, which will call loop()
if (lives <= 0 || screen == 3) {
restart();
}
break;
case 'e':
if (screen === 1 && px >= 356 && px <= 403 && py >= 68 && py <= 92) {
if (egg) {
egg = false;
loop(); // Resume loop
} else {
egg = true;
dx = 2.8; // Apply speed increase here
dy = 2.8;
// Draw the popup immediately and then stop the loop
// This ensures the popup is drawn at least once.
drawEggPopup();
noLoop(); // Pause loop
}
}
break;
case 'i':
if (info) {
info = false;
loop(); // Resume loop
} else {
info = true;
// Draw the popup immediately and then stop the loop
drawInfoPopup();
noLoop(); // Pause loop
}
break;
}
}
}
// Stop tracking key when released
function keyReleased() {
keys[key.toLowerCase()] = false;
}
// Function to handle continuous movement
function handleMovement() {
// Only move if not locked, not on start screen, not in info/egg menu, and not dead
if (lock || screen === 0 || info || egg || lives <= 0) {
return;
}
// Movement logic (W,A,S,D) as before
if (keys['w']) {
py -= dy;
switch (W) {
case 1: player = playerW1; break; case 2: player = playerW2; break;
case 3: player = playerW3; break; case 4: player = playerW4; break;
case 5: player = playerW5; break; case 6: player = playerW6; break;
}
switch (screen) {
case 1:
if ((px >= 0 && px <= 202 && py >= 0 && py <= 68) || (px >= 303 && px <= 577 && py >= 0 && py <= 75) || (px >= 564 && px <= 601 && py >= 178 && py <= 205) || (px >= 404 && px <= 620 && py >= 266 && py <= height) || (px >= 172 && px <= 340 && py >= 280 && py <= height)) { py += dy; }
break;
case 2:
if ((px >= 64 && px <= 227 && py >= 0 && py <= 180) || (px >= 333 && px <= width && py >= 0 && py <= 195)) { py += dy; }
break;
}
W = (W % 6) + 1;
if (py <= 0) py += dy;
}
if (keys['s']) {
py += dy;
switch (S) {
case 1: player = playerS1; break; case 2: player = playerS2; break;
case 3: player = playerS3; break; case 4: player = playerS4; break;
case 5: player = playerS5; break; case 6: player = playerS6; break;
}
switch (screen) {
case 1:
if ((px >= 564 && px <= 601 && py >= 178 && py <= 205) || (px >= 404 && px <= 620 && py >= 266 && py <= height) || (px >= 172 && px <= 340 && py >= 280 && py <= height)) { py -= dy; }
break;
case 2:
if ((px >= 333 && px <= width && py >= 0 && py <= 195)) { py -= dy; }
break;
}
S = (S % 6) + 1;
if (py >= height) py -= dy;
}
if (keys['a']) {
px -= dx;
switch (A) {
case 1: player = playerA1; break; case 2: player = playerA2; break;
case 3: player = playerA3; break; case 4: player = playerA4; break;
case 5: player = playerA5; break; case 6: player = playerA6; break;
}
switch (screen) {
case 1:
if ((px >= 0 && px <= 202 && py >= 0 && py <= 68) || (px >= 303 && px <= 577 && py >= 0 && py <= 75) || (px >= 564 && px <= 601 && py >= 178 && py <= 205) || (px >= 404 && px <= 620 && py >= 266 && py <= height) || (px >= 172 && px <= 340 && py >= 280 && py <= height)) { px += dx; }
break;
case 2:
if ((px >= 64 && px <= 227 && py >= 0 && py <= 180) || (px >= 333 && px <= width && py >= 0 && py <= 195)) { px += dx; }
break;
}
A = (A % 6) + 1;
if (px <= 0) {
if (screen > 1) { screen--; px = width - 10; } else { px = 0; }
}
}
if (keys['d']) {
px += dx;
switch (D) {
case 1: player = playerD1; break; case 2: player = playerD2; break;
case 3: player = playerD3; break; case 4: player = playerD4; break;
case 5: player = playerD5; break; case 6: player = playerD6; break;
}
switch (screen) {
case 1:
if ((px >= 303 && px <= 577 && py >= 0 && py <= 75) || (px >= 564 && px <= 601 && py >= 178 && py <= 205) || (px >= 404 && px <= 620 && py >= 266 && py <= height) || (px >= 172 && px <= 340 && py >= 280 && py <= height)) { px -= dx; }
break;
case 2:
if ((px >= 64 && px <= 227 && py >= 0 && py <= 180) || (px >= 333 && px <= width && py >= 0 && py <= 195)) { px -= dx; }
break;
}
D = (D % 6) + 1;
if (px >= width) {
if (screen < 3) { screen++; px = 10; } else { px = width; }
}
}
}
// screen 1 and 2 functions
function setup1() {
let delt1 = (height - 81) / 3;
let delt2 = 250 / 3;
let delt3 = (275 - 80) / 3;
let rand = 30;
NPC1 = [];
NPC2 = [];
NPC1.push(new NPC(87, (0 * delt1) + 81, 1.5, 80, height, npcDown[floor(random(0, 3))], false));
NPC1.push(new NPC(87, (1 * delt1) + random(-rand, rand) + 81, 1.5, 80, height, npcDown[floor(random(0, 3))], false));
NPC1.push(new NPC(87, (2 * delt1) + random(-rand, rand) + 81, 1.5, 80, height, npcDown[floor(random(0, 3))], false));
NPC1.push(new NPC(254, 250 - (0 * delt2), 1.5, 250, 0, npcUp[floor(random(0, 3))], true));
NPC1.push(new NPC(254, 250 - (1 * delt2) + random(-rand, rand), 1.5, 250, 0, npcUp[floor(random(0, 3))], true));
NPC1.push(new NPC(254, 250 - (2 * delt2) + random(-rand, rand), 1.5, 250, 0, npcUp[floor(random(0, 3))], true));
NPC1.push(new NPC(464, (0 * delt3) + 81, 1, 80, 275, npcDown[floor(random(0, 3))], false));
NPC1.push(new NPC(464, (1 * delt3) + random(-rand, rand) + 81, 1, 80, 275, npcDown[floor(random(0, 3))], false));
NPC1.push(new NPC(464, (2 * delt3) + random(-rand, rand) + 81, 1, 80, 275, npcDown[floor(random(0, 3))], false));
let delt4 = (height - 160) / 2;
let delt5 = (height - 180) / 2;
NPC2.push(new NPC(148, (0 * delt4) + 160, 1.5, height, 160, npcUp[floor(random(0, 3))], true));
NPC2.push(new NPC(148, (1 * delt4) + 160, 1.5, height, 160, npcUp[floor(random(0, 3))], true));
NPC2.push(new NPC(482, (0 * delt5) + 180, 1.5, height, 180, npcUp[floor(random(0, 3))], true));
NPC2.push(new NPC(482, (1 * delt5) + 180 + random(-rand, rand), 1.5, height, 180, npcUp[floor(random(0, 3))], true));
}
function screen1() {
for (let i = 0; i < NPC1.length; i++) {
let currentNPC = NPC1[i];
currentNPC.update();
currentNPC.display();
}
}
function screen2() {
for (let i = 0; i < NPC2.length; i++) {
let currentNPC = NPC2[i];
currentNPC.update();
currentNPC.display();
}
}
function hit() {
lives--;
if (lives <= 0) gameOver();
}
function gameOver() {
player = playerDead;
imageMode(CENTER);
image(player, px, py);
noLoop(); // Stop the loop for Game Over screen
push();
rectMode(CENTER);
stroke(110, 70, 30);
strokeWeight(5);
fill(200, 150, 100, 240);
rect(width / 2, height / 2, 300, 200);
textAlign(CENTER);
noStroke(); // <--- CRITICAL FIX: No stroke for text
textFont(textFont_game);
fill(110, 70, 30);
textSize(32);
text("Game Over", width / 2, 115);
textSize(20);
text("You are out of lives", width / 2, 180);
text("Press (R) to reset", width / 2, 210);
dx = 2;
dy = 2;
pop();
}
function restart() {
px = 30;
py = height / 2;
player = playerW1;
lives = 1;
screen = 1;
W = 1;
A = 1;
S = 1;
D = 1;
dx = 2;
dy = 2;
NPC1 = [];
NPC2 = [];
setup1();
lock = false;
info = false;
egg = false;
loop(); // Resume loop after restart
}
</script>
</body>
</html>