Skip to content

Commit 242e963

Browse files
Merge pull request #16 from gvinayakgupta/master
Added basic background music and few location images
2 parents bc61daa + c632b08 commit 242e963

8 files changed

Lines changed: 11027 additions & 6858 deletions

File tree

package-lock.json

Lines changed: 10985 additions & 6853 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"react": "^16.13.1",
1010
"react-dom": "^16.13.1",
1111
"react-p5": "^1.3.2",
12-
"react-scripts": "^3.4.3"
12+
"react-scripts": "^4.0.0"
1313
},
1414
"scripts": {
1515
"start": "react-scripts start",

public/images/allMart.jpg

37.2 KB
Loading

public/images/building.jpg

49.8 KB
Loading

public/images/foodies.jpg

37.8 KB
Loading

public/images/library.jpg

38.8 KB
Loading

public/sound/themeSong.mp3

1.87 MB
Binary file not shown.

src/App.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from 'react';
22
import Sketch from 'react-p5';
3+
import "p5/lib/addons/p5.sound";
34

45
function App() {
5-
let font, font2, anna, annaG, chai, coffee, pac, pac1;
6+
let font, font2, anna, annaG, chai, coffee, pac, pac1, song;
7+
let lib, libPos, main, mainPos;
8+
let mart, martPos, foodies, foodiesPos;
69
let gameState = "SS";
710
let score = 0;
811
let end_text = "Game Over";
@@ -30,6 +33,11 @@ function App() {
3033
coffee = p5.loadImage("/images/coffee.svg");
3134
pac1 = p5.loadImage("/images/pac.gif");
3235
pac = p5.loadImage("/images/pac-left.gif");
36+
lib = p5.loadImage("/images/library.jpg");
37+
main = p5.loadImage("/images/building.jpg");
38+
mart = p5.loadImage("/images/allMart.jpg");
39+
foodies = p5.loadImage("/images/foodies.jpg");
40+
song = p5.loadSound("/sound/themeSong.mp3");
3341
};
3442

3543
const distance = (x1, y1, x2, y2) => Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
@@ -51,16 +59,22 @@ function App() {
5159
p5.fill(252);
5260
maze(p5);
5361
CheckOrientaion(p5);
62+
console.log(song);
63+
5464
};
5565
const draw = p5 => {
5666
p5.background(0)
5767
if (gameState === "SS") {
68+
p5.masterVolume(0.05);
5869
StartScreen(p5);
5970
} else if (gameState === "LevelSplash") {
71+
p5.masterVolume(0.05);
6072
LevelSplash(p5);
6173
} else if (gameState === "game") {
74+
p5.masterVolume(0.1);
6275
GameScreen(p5);
6376
} else if (gameState === "go") {
77+
p5.masterVolume(0.2);
6478
GameOver(p5);
6579
} else if (gameState === "Rotate") {
6680
Rotate(p5);
@@ -112,6 +126,7 @@ function App() {
112126
}
113127

114128
const GameOver = (p5) => {
129+
// song.pause();
115130
p5.fill(255);
116131
p5.textFont(font2);
117132
p5.textSize(3.8 * standardSize);
@@ -179,6 +194,7 @@ function App() {
179194
}
180195

181196
const touchStarted = (p5) => {
197+
if(!song.isPlaying()) song.play();
182198
if (gameState === "SS") {
183199
Start_Resume(p5);
184200
} else if (gameState === "go") {
@@ -210,6 +226,7 @@ function App() {
210226
}
211227

212228
const keyPressed = p5 => {
229+
if(!song.isPlaying()) song.play();
213230
if (p5.keyCode === p5.ENTER) {
214231
if (gameState === "SS") { Start_Resume(p5); }
215232
else if (gameState === "go") { setHS(); gameState = "SS"; score = 0; levelNo = 1; maze(p5); }
@@ -350,13 +367,13 @@ function App() {
350367
var pCount = 7;
351368
var addedPac = false;
352369
const level = [
353-
['*', '*', '*', '*', '', '', '', '', '*', '*', '*', '*', '*', '*', '', '', '', '', '*', '*', '*', '*'],
370+
['*', '*', '*', '*', '', '', '', '', 'm', '*', '*', '*', '*', '*', '', '', '', '', '*', '*', '*', '*'],
354371
['*', '', '', '', '', '', '', '', '', '', '*', '*', '', '', '', '', '', '', '', '', '', '*'],
355-
['*', '', '*', '*', '', '', '', '*', '*', '', '*', '*', '', '*', '*', '', '', '', '*', '*', '', '*'],
372+
['*', '', 'a', '*', '', '', '', '*', '*', '', '*', '*', '', '*', '*', '', '', '', 'f', '*', '', '*'],
356373
['*', '', '*', '*', '', '', '', '', '', '*', '', '', '*', '', '', '', '', '', '*', '*', '', '*'],
357374
['*', '', '*', '', '', '', '', '*', '*', '', '', '', '', '*', '*', '', '', '', '', '*', '', '*'],
358375
['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
359-
['', '*', '*', '', '', '', '*', '', '', '*', '*', '*', '*', '', '', '*', '', '', '', '', '*', ''],
376+
['', '*', '*', '', '', '', '*', '', '', 'l', '*', '*', '*', '', '', '*', '', '', '', '', '*', ''],
360377
['', '', '', '', '', '', '*', '*', '*', '', '*', '*', '', '*', '*', '*', '', '', '', '', '', '*'],
361378
['', '*', '*', '', '', '', '*', '', '', '', '', '', '', '', '', '*', '', '', '', '', '', '*'],
362379
['*', '', '*', '', '', '', '*', '', '*', '*', '*', '*', '*', '*', '', '*', '', '', '', '', '', '*'],
@@ -392,6 +409,22 @@ function App() {
392409
else if (level[i][j] === 'eout') {
393410
Gates.push({ x: (j - 11 + 1 / 2), y: (i - 6 + 1 / 2) });
394411
}
412+
else if (level[i][j] === 'l') {
413+
Blocks.push({ x: (j - 11 + 1 / 2), y: (i - 6 + 1 / 2) });
414+
libPos = {x: (j-10 + 1/4), y: (i-6+1/4)};
415+
}
416+
else if (level[i][j] === 'm') {
417+
Blocks.push({ x: (j - 11 + 1 / 2), y: (i - 6 + 1 / 2) });
418+
mainPos = {x: (j-9 + 1/4), y: (i-6+1/2)};
419+
}
420+
else if (level[i][j] === 'a') {
421+
Blocks.push({ x: (j - 11 + 1 / 2), y: (i - 6 + 1 / 2) });
422+
martPos = {x: (j-11 + 1/4), y: (i-6+1/4)};
423+
}
424+
else if (level[i][j] === 'f') {
425+
Blocks.push({ x: (j - 11 + 1 / 2), y: (i - 6 + 1 / 2) });
426+
foodiesPos = {x: (j-11 + 1/4), y: (i-6+1/4)};
427+
}
395428
}
396429
}
397430
}
@@ -403,6 +436,10 @@ function App() {
403436
for (i = 0; i < Powers.length; i++) p5.image(chai, (Powers[i].x - 1 / 2) * standardSize, (Powers[i].y - 1 / 2) * standardSize, standardSize, standardSize);
404437
for (i = 0; i < Enemies.length; i++) p5.image((pacman.power && Enemies[i].state === 1) ? annaG : anna, (Enemies[i].x - 1 / 2) * standardSize, (Enemies[i].y - 1 / 2) * standardSize, 7 * standardSize / 8, 7 * standardSize / 8);
405438
p5.image(pacman.mouth === 1 ? pac1 : pac, (pacman.x - 0.5) * standardSize, (pacman.y - 0.5) * standardSize, standardSize, standardSize);
439+
p5.image(lib, libPos.x * standardSize, libPos.y * standardSize, 1.5*standardSize, 1.5*standardSize);
440+
p5.image(main, mainPos.x * standardSize, mainPos.y * standardSize, 1.5*standardSize, 2*standardSize);
441+
p5.image(mart, martPos.x * standardSize, martPos.y * standardSize, 1.5*standardSize, 1.5*standardSize);
442+
p5.image(foodies, foodiesPos.x * standardSize, foodiesPos.y * standardSize, 1.5*standardSize, 1.5*standardSize);
406443
}
407444

408445
return (

0 commit comments

Comments
 (0)