diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-05-14 10:51:54 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-05-14 10:51:54 -0500 |
commit | 4d3aba7167fbfd5e002714e3c4a577cc17f18af0 (patch) | |
tree | db97fe441f8075e86551c55d20606ff4d958f4a9 /src/paperflight/index.html | |
parent | c5d5990eecd254f3d5daf33a6c9cd394dcba2058 (diff) |
Refactor updates, fix gameover, add level changing
Diffstat (limited to 'src/paperflight/index.html')
-rw-r--r-- | src/paperflight/index.html | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/paperflight/index.html b/src/paperflight/index.html index ef26a03..a620a1c 100644 --- a/src/paperflight/index.html +++ b/src/paperflight/index.html @@ -24,7 +24,9 @@ <script> var username = undefined - var score, plane, gameInterval, currLevelIndex, currLevel, t, collected, startLevel, switchState + var score, plane, gameInterval, currLevelIndex, + currLevel, t, collected, startLevel, switchState, + gameIsOver var DEFAULT_VX = 3 var DEFAULT_VY = 0.5 @@ -48,11 +50,12 @@ if (gameInterval) { clearInterval(gameInterval) } + gameIsOver = false score = 0 t = 0 plane = { x: 30, - y: height / 4, + y: 100, vx: DEFAULT_VX, vy: DEFAULT_VY, width: 30, @@ -66,28 +69,39 @@ }, 1000 / fps) } function setLevel(to) { + plane.x = 30 + plane.y = 100 + plane.dir= 1 currLevelIndex = to - currLevel = levels[currLevelIndex] - currLevel.items = currLevel.items.slice() - currLevel.items.forEach(item => { - if("collected" in item){ - item.collected = false + if (to in levels) { + currLevel = levels[currLevelIndex] + currLevel.items = currLevel.items.slice() + currLevel.items.forEach(item => { + if ("collected" in item) { + item.collected = false + } + }) + collected = 0 + switchState = 0 + startLevel = false + } else { + currLevel = { + title: "YOU WIN!", + coinsNeeded: 0, + exit: { + x: -100, + y: -100, + radius: 0 + }, + items: [] } - }) - collected = 0 - switchState = 0 - startLevel = false + } } function atExit() { - return (Math.sqrt(Math.pow(plane.x - currLevel.exit.x, 2) + Math.pow(plane.y - currLevel.exit.y, 2)) < 20 - || Math.sqrt(Math.pow(plane.x + plane.width - currLevel.exit.x, 2) + Math.pow(plane.y - currLevel.exit.y, 2)) < 20) - && collected >= currLevel.coinsNeeded + return isPlaneInCircle(currLevel.exit) && collected >= currLevel.coinsNeeded } function gameOver() { - ctx.font = "20px Courier" - ctx.fillStyle = "black" - ctx.fillText("Game Over!", 200, 200); - window.clearInterval(gameInterval) + gameIsOver = true } function keyDown(e) { startLevel = true |