@@ -32,12 +32,7 @@ function App() {
3232 pac = p5 . loadImage ( "/images/pac-left.gif" ) ;
3333 } ;
3434
35- const distance = ( x1 , y1 , x2 , y2 ) => {
36- console . log ( x1 , y1 , x2 , y2 ) ;
37- var dx = x1 - x2 ;
38- var dy = y1 - y2 ;
39- return Math . sqrt ( dx * dx + dy * dy ) ;
40- } ;
35+ const distance = ( x1 , y1 , x2 , y2 ) => Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;
4136
4237 const setup = ( p5 , canvasParentRef ) => {
4338 var vw , vh ;
@@ -74,6 +69,7 @@ function App() {
7469
7570 const StartScreen = ( p5 ) => {
7671 p5 . fill ( 255 ) ;
72+ clearInterval ( enemInterval ) ;
7773 p5 . text ( "TAP OR PRESS ENTER TO START" , 0 , 0 )
7874 if ( localStorage . getItem ( 'highscore' ) !== null ) p5 . text ( `HighScore ${ localStorage . getItem ( 'highscore' ) } ` , 0 , 50 ) ;
7975 } ;
@@ -127,6 +123,7 @@ function App() {
127123 p5 . text ( "Tap or Press Enter To restart" , 2.7 * standardSize , 2.7 * standardSize ) ;
128124 p5 . textFont ( font ) ;
129125 p5 . textSize ( standardSize / 2 ) ;
126+ clearInterval ( enemInterval ) ;
130127 }
131128
132129 const windowResized = p5 => {
@@ -150,7 +147,6 @@ function App() {
150147 gameState = "LevelSplash"
151148 setTimeout ( ( ) => {
152149 gameState = "game" ;
153- clearInterval ( enemInterval ) ;
154150 enemInterval = setInterval ( ( ) => {
155151 moveEnemies ( p5 ) ;
156152 } , 800 - levelNo * 100 ) ;
@@ -249,30 +245,28 @@ function App() {
249245 if ( flag === true ) {
250246 pacman . x = newx ;
251247 pacman . y = newy ;
252- }
253- for ( i = 0 ; i < Foods . length ; i ++ ) {
254- dis = distance ( newx , newy , Foods [ i ] . x , Foods [ i ] . y ) ;
255- if ( dis < 1 ) {
256- score += 1 ;
257- Foods . splice ( i , 1 ) ;
258- i -- ;
248+ for ( i = 0 ; i < Foods . length ; i ++ ) {
249+ dis = distance ( newx , newy , Foods [ i ] . x , Foods [ i ] . y ) ;
250+ if ( dis < 1 ) {
251+ score += 1 ;
252+ Foods . splice ( i , 1 ) ;
253+ i -- ;
254+ }
259255 }
260- }
261- for ( i = 0 ; i < Powers . length ; i ++ ) {
262- dis = distance ( newx , newy , Powers [ i ] . x , Powers [ i ] . y ) ;
263- if ( dis < 1 ) {
264- score += 5 ;
265- pacman . power = true ;
266- Powers . splice ( i , 1 ) ;
267- i -- ;
256+ for ( i = 0 ; i < Powers . length ; i ++ ) {
257+ dis = distance ( newx , newy , Powers [ i ] . x , Powers [ i ] . y ) ;
258+ if ( dis < 1 ) {
259+ score += 5 ;
260+ pacman . power = true ;
261+ Powers . splice ( i , 1 ) ;
262+ i -- ;
263+ }
268264 }
269- }
270- for ( i = 0 ; i < Enemies . length ; i ++ ) {
271- dis = distance ( newx , newy , Enemies [ i ] . x , Enemies [ i ] . y ) ;
272- if ( dis < 1 ) {
273- console . log ( dis , newx , newy , Enemies [ i ] . x , Enemies [ i ] . y ) ;
274- console . log ( "Check this" ) ;
275- HandleEnePacCollision ( p5 , i ) ;
265+ for ( i = 0 ; i < Enemies . length ; i ++ ) {
266+ dis = distance ( newx , newy , Enemies [ i ] . x , Enemies [ i ] . y ) ;
267+ if ( dis < 1 ) {
268+ HandleEnePacCollision ( p5 , i ) ;
269+ }
276270 }
277271 }
278272 }
@@ -339,12 +333,10 @@ function App() {
339333 if ( flag === true ) {
340334 Enemies [ i ] . x = newx ;
341335 Enemies [ i ] . y = newy ;
342- } else
343- dis = distance ( newx , newy , pacman . x , pacman . y ) ;
344- if ( dis < 1 ) {
345- console . log ( dis , newx , newy , pacman . x , pacman . y ) ;
346- console . log ( "Check this" ) ;
347- HandleEnePacCollision ( p5 , i ) ;
336+ dis = distance ( newx , newy , pacman . x , pacman . y ) ;
337+ if ( dis < 1 ) {
338+ HandleEnePacCollision ( p5 , i ) ;
339+ }
348340 }
349341 }
350342 }
@@ -354,7 +346,7 @@ function App() {
354346 Foods = [ ] ;
355347 Powers = [ ] ;
356348 Enemies = [ ] ;
357- var fCount = 10 ;
349+ var fCount = 172 ;
358350 var pCount = 7 ;
359351 var addedPac = false ;
360352 const level = [
@@ -410,7 +402,7 @@ function App() {
410402 for ( i = 0 ; i < Foods . length ; i ++ ) p5 . image ( coffee , ( Foods [ i ] . x - 1 / 2 ) * standardSize , ( Foods [ i ] . y - 1 / 2 ) * standardSize , standardSize , standardSize ) ;
411403 for ( i = 0 ; i < Powers . length ; i ++ ) p5 . image ( chai , ( Powers [ i ] . x - 1 / 2 ) * standardSize , ( Powers [ i ] . y - 1 / 2 ) * standardSize , standardSize , standardSize ) ;
412404 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 ) ;
413- p5 . image ( pacman . mouth === 1 ? pac1 : pac , ( pacman . x - 0.5 ) * standardSize , ( pacman . y - 0.5 ) * standardSize , standardSize , standardSize ) ;
405+ p5 . image ( pacman . mouth === 1 ? pac1 : pac , ( pacman . x - 0.5 ) * standardSize , ( pacman . y - 0.5 ) * standardSize , standardSize , standardSize ) ;
414406 }
415407
416408 return (
0 commit comments