1- import { squares , buildGameBoard , setGameBoard , roundOutTheGameboard , setLairText , setTitleScreen } from './game-board.js' ;
1+ import { squares , buildGameBoard , setGameBoard , roundOutTheGameboard , setLairText , setTitleScreen , reSetLairTextColor } from './game-board.js' ;
22import { flagToggled , startToggleTitleAndScoreScreen , endToggleTitleAndScoreScreen } from '../main.js' ;
33import { playSiren , stopSiren , switchToSiren2 , stopPacManEatingPelletsSound , playPacManEatingPelletsSound , playGhostEatenSounds , stopAllSounds , soundGameStart , soundPacManEatingPellets , soundPacManEatingFruit , soundGhostSiren1 , soundCutscene , soundDeath , soundEatingGhost , soundGhostRunningAway , soundGhostSiren2 , soundHighScore , soundPowerUp } from './audio.js' ;
44
@@ -344,24 +344,26 @@ export function control(x) {
344344 } // control
345345
346346function fruitScoreBonus ( ) {
347+ reSetLairTextColor ( "whitesmoke" ) ;
347348 soundPacManEatingFruit . play ( ) ;
348349 if ( level < 12 ) {
349350 score += fruitBonusValue [ level - 1 ] ;
350- squares [ 433 ] . style . color = 'whitesmoke' ;
351+ // squares[433].style.color = 'whitesmoke';
351352 squares [ 433 ] . innerHTML = fruitBonusValue [ level - 1 ] ;
352353 // console.log(`Fruit Eaten! ${fruitBonusValue[level-1]}`);
353354 fruitEaten = true ;
354355 squares [ pacmanCurrentIndex ] . classList . remove ( 'bonusFruit' ) ;
355356 squares [ 489 ] . innerHTML = '' ;
356357 } else {
357358 score += fruitBonusValue [ fruitBonusValue . length - 1 ] ;
358- squares [ 433 ] . style . color = 'whitesmoke' ;
359+ // squares[433].style.color = 'whitesmoke';
359360 squares [ 433 ] . innerHTML = fruitBonusValue [ fruitBonus . length - 1 ] ;
360361 // console.log(`Fruit Eaten! ${fruitBonusValue[level-1]}`);
361362 fruitEaten = true ;
362363 squares [ pacmanCurrentIndex ] . classList . remove ( 'bonusFruit' ) ;
363364 squares [ 489 ] . innerHTML = '' ;
364365 }
366+ // reSetLairTextColor();
365367}
366368
367369// Fruit Score
@@ -390,7 +392,8 @@ export function levelStart() {
390392 flagBonusLife = false ;
391393
392394 scoreDisplay . innerHTML = score ;
393-
395+
396+ reSetLairTextColor ( "orange" ) ;
394397 squares [ 431 ] . innerHTML = "R" ;
395398 squares [ 432 ] . innerHTML = "E" ;
396399 squares [ 433 ] . innerHTML = "A" ;
@@ -414,7 +417,8 @@ export function levelStart() {
414417 squares [ 433 ] . innerHTML = "" ;
415418 squares [ 434 ] . innerHTML = "" ;
416419 squares [ 435 ] . innerHTML = "" ;
417- squares [ 436 ] . innerHTML = "" ;
420+ squares [ 436 ] . innerHTML = "" ;
421+ reSetLairTextColor ( ) ;
418422
419423 // setPacManSpeed();
420424 speedStartPacMan = setInterval ( control , pacManSpeed ) ;
@@ -453,6 +457,23 @@ export function checkForGhostCatchesPacMan() {
453457 }
454458}
455459
460+ // Function to animate PacMan dying
461+ export function animatePacManDying ( ) {
462+ squares [ pacmanCurrentIndex ] . classList . add ( 'pacMan-move-die' ) ;
463+ setTimeout ( ( ) => {
464+ squares [ pacmanCurrentIndex ] . classList . remove ( 'pacMan-move-die' ) ;
465+ squares [ pacmanCurrentIndex ] . classList . remove ( 'pacMan' ) ;
466+ } , 1250 ) ;
467+
468+ setTimeout ( ( ) => {
469+ squares [ pacmanCurrentIndex ] . classList . add ( 'pacMan-explode' ) ;
470+ } , 1250 ) ;
471+
472+ setTimeout ( ( ) => {
473+ squares [ pacmanCurrentIndex ] . classList . remove ( 'pacMan-explode' ) ;
474+ } , 1500 ) ;
475+ }
476+
456477export function loseLife ( ) {
457478 stopAllSounds ( ) ;
458479 soundDeath . play ( ) ;
@@ -464,7 +485,8 @@ export function loseLife(){
464485
465486 if ( lives === 0 ) {
466487 clearInterval ( speedStartPacMan ) ;
467- squares [ pacmanCurrentIndex ] . classList . add ( 'pacMan-move-die' ) ;
488+ animatePacManDying ( )
489+
468490 resetGame ( ) ;
469491 setTimeout ( gameOver , 4000 ) ;
470492 // setTimeout(setTitleScreen, 8000);
@@ -473,7 +495,8 @@ export function loseLife(){
473495
474496 } else {
475497 clearInterval ( speedStartPacMan ) ;
476- squares [ pacmanCurrentIndex ] . classList . add ( 'pacMan-move-die' ) ;
498+ animatePacManDying ( )
499+
477500 setTimeout ( resetPacMan , 4000 ) ;
478501 }
479502 // ghostsEaten = 0;
@@ -518,6 +541,7 @@ function extraLife() {
518541
519542 resizeCurrentPacManLives ( ) ;
520543
544+ reSetLairTextColor ( "orange" ) ;
521545 squares [ 431 ] . innerHTML = "E" ;
522546 squares [ 432 ] . innerHTML = "X" ;
523547 squares [ 433 ] . innerHTML = "T" ;
@@ -532,6 +556,7 @@ function extraLife() {
532556 squares [ 434 ] . innerHTML = "" ;
533557 squares [ 435 ] . innerHTML = "" ;
534558 squares [ 436 ] . innerHTML = "" ;
559+ reSetLairTextColor ( ) ;
535560 } , 3000 ) ;
536561 }
537562 // if(score !== 0 && checkForBonusLife === 0 && flagBonusLife === false){
@@ -565,19 +590,20 @@ function resetGame(){
565590}
566591
567592function gameOver ( ) {
593+ reSetLairTextColor ( "red" ) ;
568594 checkForHighScore ( ) ;
569595 // localStorage.setItem("highScore", JSON.stringify(highScore));
570596 removePacMan ( ) ;
571597
572- squares [ 404 ] . style . color = 'red' ;
573- squares [ 405 ] . style . color = 'red' ;
574- squares [ 406 ] . style . color = 'red' ;
575- squares [ 407 ] . style . color = 'red' ;
576-
577- squares [ 432 ] . style . color = 'red' ;
578- squares [ 433 ] . style . color = 'red' ;
579- squares [ 434 ] . style . color = 'red' ;
580- squares [ 435 ] . style . color = 'red' ;
598+ // squares[404].style.color = 'red';
599+ // squares[405].style.color = 'red';
600+ // squares[406].style.color = 'red';
601+ // squares[407].style.color = 'red';
602+
603+ // squares[432].style.color = 'red';
604+ // squares[433].style.color = 'red';
605+ // squares[434].style.color = 'red';
606+ // squares[435].style.color = 'red';
581607
582608 squares [ 403 ] . innerHTML = "" ;
583609 squares [ 404 ] . innerHTML = "G" ;
@@ -594,16 +620,16 @@ function gameOver() {
594620 squares [ 436 ] . innerHTML = "" ;
595621
596622 setTimeout ( function ( ) {
597-
598- squares [ 404 ] . style . color = 'orange' ;
599- squares [ 405 ] . style . color = 'orange' ;
600- squares [ 406 ] . style . color = 'orange' ;
601- squares [ 407 ] . style . color = 'orange' ;
602-
603- squares [ 432 ] . style . color = 'orange' ;
604- squares [ 433 ] . style . color = 'orange' ;
605- squares [ 434 ] . style . color = 'orange' ;
606- squares [ 435 ] . style . color = 'orange' ;
623+ reSetLairTextColor ( "orange" ) ;
624+ // squares[404].style.color = 'orange';
625+ // squares[405].style.color = 'orange';
626+ // squares[406].style.color = 'orange';
627+ // squares[407].style.color = 'orange';
628+
629+ // squares[432].style.color = 'orange';
630+ // squares[433].style.color = 'orange';
631+ // squares[434].style.color = 'orange';
632+ // squares[435].style.color = 'orange';
607633
608634 squares [ 403 ] . innerHTML = "" ;
609635 squares [ 404 ] . innerHTML = "" ;
@@ -684,17 +710,19 @@ export function gameStart() {
684710}
685711
686712function clearFruitBonus1 ( ) {
713+ reSetLairTextColor ( "orange" ) ;
687714 squares [ 433 ] . innerHTML = '' ;
688- squares [ 433 ] . style . color = 'orange' ;
715+ // squares[433].style.color = 'orange';
689716 squares [ 489 ] . classList . remove ( 'bonusFruit' ) ;
690717 console . log ( 'clearFruitBonus1' ) ;
691718 squares [ 489 ] . innerHTML = '' ;
692719 fruitEaten = false ;
693720}
694721
695722function clearFruitBonus2 ( ) {
723+ reSetLairTextColor ( "orange" ) ;
696724 squares [ 433 ] . innerHTML = '' ;
697- squares [ 433 ] . style . color = 'orange' ;
725+ // squares[433].style.color = 'orange';
698726 squares [ 489 ] . classList . remove ( 'bonusFruit' ) ;
699727 console . log ( 'clearFruitBonus2' ) ;
700728 squares [ 489 ] . innerHTML = '' ;
@@ -977,13 +1005,14 @@ export function moveGhost(ghost) {
9771005 } // if(ghost.isScared)
9781006
9791007 if ( ghost . isScared && squares [ ghost . currentIndex ] . classList . contains ( 'pacMan' ) ) {
980-
1008+ reSetLairTextColor ( "whitesmoke" ) ;
9811009 playGhostEatenSounds ( ) ;
9821010
9831011 ghostsEaten += 1 ;
9841012 score += ghostsEaten * 400 ;
9851013 console . log ( `ghostsEaten score: ${ ghostsEaten * 400 } ` ) ;
986- squares [ 433 ] . style . color = 'whitesmoke' ;
1014+ // squares[433].style.color = 'whitesmoke';
1015+
9871016 squares [ 433 ] . innerHTML = ghostsEaten * 400 ;
9881017 setTimeout ( ( ) => { squares [ 433 ] . innerHTML = '' ; } , 5000 ) ;
9891018 // Set blinky to respawn inside the lair
@@ -995,6 +1024,7 @@ export function moveGhost(ghost) {
9951024 ghost . currentIndex = ghost . startIndex ;
9961025 }
9971026 squares [ ghost . currentIndex ] . classList . add ( ghost . className , 'ghost' , ghost . size , ghost . color , ghost . eyes ) ;
1027+ // reSetLairTextColor();
9981028 }
9991029 checkForGhostCatchesPacMan ( ) ;
10001030 // checkForHighScore();
0 commit comments