11import React from 'react' ;
22import Sketch from 'react-p5' ;
3+ import "p5/lib/addons/p5.sound" ;
34
45function 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