diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-05-13 21:59:10 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-05-13 21:59:10 -0500 |
commit | cd8b5ef7da2116c20c6b4fa22fa94282fac49bda (patch) | |
tree | b2731adc51f0a215fc7796a396df131998f8b153 | |
parent | 1855e0c673b06399ca89aa0c705d30b1a9ea3b97 (diff) |
Add height to vent
-rw-r--r-- | src/paperflight/index.html | 3 | ||||
-rw-r--r-- | src/paperflight/static/draw.js | 24 | ||||
-rw-r--r-- | src/paperflight/static/levels.js | 33 | ||||
-rw-r--r-- | src/paperflight/static/update.js | 5 |
4 files changed, 44 insertions, 21 deletions
diff --git a/src/paperflight/index.html b/src/paperflight/index.html index 731b92e..9432244 100644 --- a/src/paperflight/index.html +++ b/src/paperflight/index.html @@ -22,7 +22,7 @@ <script> var username = undefined - var score, plane, gameInterval, currLevelIndex, currLevel, t, collected, startLevel + var score, plane, gameInterval, currLevelIndex, currLevel, t, collected, startLevel, switchState var DEFAULT_VX = 3 var DEFAULT_VY = 0.5 @@ -48,6 +48,7 @@ } score = 0 t = 0 + switchState = 0 plane = { x: 30, y: height / 4, diff --git a/src/paperflight/static/draw.js b/src/paperflight/static/draw.js index fe0cad5..de64e27 100644 --- a/src/paperflight/static/draw.js +++ b/src/paperflight/static/draw.js @@ -10,7 +10,7 @@ function draw() { ctx.fillStyle = "#222" ctx.font = "20px Courier" - ctx.fillText(`Level ${currLevelIndex} (${collected}/${currLevel.coinsNeeded}) - Time ${Math.round(t / fps / 60)}:${Math.round(t / fps) % 60}`, 20, 20) + ctx.fillText(`Level ${currLevelIndex} (${collected}/${currLevel.coinsNeeded}) - ${currLevel.title} - Time ${Math.round(t / fps / 60)}:${Math.round(t / fps) % 60}`, 20, 20) } function drawPlane() { @@ -36,8 +36,8 @@ function drawVent() { ctx.fillStyle = "#ccc" ctx.fillRect(this.x, this.y, this.width, 10) ctx.fillStyle = "white" - var yDelta = Math.sin(t / 30) * 40 - for (var i = this.y; i > 30; i -= 60) { + var yDelta = Math.sin(t / 30) * 40 + for (var i = 0; i < this.height; i+= 60) { ctx.fillRect(this.x, this.y - i + yDelta, 1, 8) ctx.fillRect(this.x+this.width/2-2, this.y - i + yDelta/2, 1, 12) ctx.fillRect(this.x+this.width-2, this.y - i + yDelta, 1, 8) @@ -71,4 +71,22 @@ function drawExit(exit) { ctx.beginPath() ctx.arc(exit.x, exit.y, 20, 0, Math.PI * 2) ctx.fill() +} +function drawSwitch(){ + ctx.fillStyle = "black" + ctx.fillRect(this.x, this.y, this.width, this.height) +} +function drawSwitchRect(){ + if(switchState == this.state){ + ctx.fillStyle = "blue" + ctx.fillRect(this.x, this.y, this.width, this.height) + } else { + ctx.stokeStyle = "blue" + ctx.setLineDash([5, 5]); + ctx.beginPath() + ctx.moveTo(this.x, this.y) + ctx.lineTo(this.x + this.width, this.y + this.height) + ctx.lineTo(this.x + this.width, this.y + this.height) + ctx.lineTo(this.x, this.y) + } }
\ No newline at end of file diff --git a/src/paperflight/static/levels.js b/src/paperflight/static/levels.js index d826095..a7116b4 100644 --- a/src/paperflight/static/levels.js +++ b/src/paperflight/static/levels.js @@ -2,24 +2,17 @@ var levels = { 1: { coinsNeeded: 5, exit: { - x: 40, + x: 40, y: 460 }, + title: "Downwards Dash", items: [{ draw: drawVent, update: updateVent, x: 420, y: 580, - width: 60 - }, - { - draw: drawRamp, - update: updateRamp, - x: 0, - y: 0, - slope: 0, - width: 800, - height: 40 + width: 60, + height: 600 }, { draw: drawCoin, @@ -33,7 +26,8 @@ var levels = { update: updateVent, x: 120, y: 100, - width: 280 + width: 280, + height: 100 }, { draw: drawBlock, @@ -69,7 +63,7 @@ var levels = { update: updateRamp, x: 70, y: 410, - slope: 2/5, + slope: 2 / 5, width: 200, height: 10 }, @@ -78,7 +72,7 @@ var levels = { update: updateRamp, x: 70, y: 470, - slope: 2/5, + slope: 2 / 5, width: 200, height: 10 }, @@ -89,6 +83,15 @@ var levels = { y: 405, radius: 10 }, - ] + { + draw: drawRamp, + update: updateRamp, + x: 0, + y: 0, + slope: 0, + width: 800, + height: 40 + }, + ] } }
\ No newline at end of file diff --git a/src/paperflight/static/update.js b/src/paperflight/static/update.js index 296308f..226d015 100644 --- a/src/paperflight/static/update.js +++ b/src/paperflight/static/update.js @@ -17,7 +17,8 @@ function update() { } } function updateVent() { - if (plane.x >= this.x - plane.width && plane.x <= this.x + this.width && plane.y < this.y) { + if (plane.x >= this.x - plane.width && plane.x <= this.x + this.width && this.y - this.height < plane.y && plane.y < this.y) { + // console.log(plane.y, this.y, this.y-this.height) plane.y -= 2 } } @@ -45,4 +46,4 @@ function updateCoin(){ this.collected = true collected++ } -}
\ No newline at end of file +} |