From 1b31f9cd1543bfedef14e39651be4e1f6e0d0f5e Mon Sep 17 00:00:00 2001 From: Tom Tibs Date: Wed, 24 Jul 2019 00:10:01 -0500 Subject: [PATCH] actually letting the horses finish the race now --- .idea/workspace.xml | 28 +++++++++++++--------------- game.js | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ad4f758..3026f88 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,6 @@ - - @@ -48,8 +46,8 @@ - - + + @@ -77,8 +75,8 @@ - - + + @@ -122,8 +120,8 @@ horseheigh ctx. finalplaces - rect canvas + rect cyclesRemaining @@ -240,25 +238,25 @@ - - + - + @@ -357,15 +355,15 @@ - - + + - - + + diff --git a/game.js b/game.js index b5764cd..9b672b3 100644 --- a/game.js +++ b/game.js @@ -34,6 +34,7 @@ const horses = []; const finalPlaces = []; let finishLineScan = 0; +let fanfarePlayedFlag = false; // sound effect triggers @@ -78,6 +79,11 @@ function gameLoop(){ break; case "finished": + //quick and dirty fanfare check + if (!fanfarePlayedFlag){ + playFanfare(); + fanfarePlayedFlag = true; + } CTX.clearRect(0, 0, WIDTH, HEIGHT); drawResults(BG_CTX, WIDTH, HEIGHT, horseHeight, finalPlaces); default: @@ -194,9 +200,13 @@ function runRace(ctx,bg_ctx){ } // horses.splice(foundHorseIndex); if (finalPlaces.length === 4){ - gameState = "finished"; + // gameState = "finished"; stopGallop(); - playFanfare(); + + // this will actually set the gamestate to finished for every frame, but it shouldnt matter since the gamestate never goes anywhere after finsihed + setTimeout(() => { + gameState = "finished"; + }, 2000) } finishLineScan -= finishLineSpeed; }