diff options
Diffstat (limited to 'src/paperflight/static')
-rw-r--r-- | src/paperflight/static/draw.js | 10 | ||||
-rw-r--r-- | src/paperflight/static/items.js | 1 | ||||
-rw-r--r-- | src/paperflight/static/update.js | 21 |
3 files changed, 18 insertions, 14 deletions
diff --git a/src/paperflight/static/draw.js b/src/paperflight/static/draw.js index 0c940b6..4646581 100644 --- a/src/paperflight/static/draw.js +++ b/src/paperflight/static/draw.js @@ -82,10 +82,12 @@ function drawRamp() { ctx.fill() } function drawCoin() { - ctx.fillStyle = "yellow" - ctx.beginPath(); - ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2) - ctx.fill() + if (!this.collected) { + ctx.fillStyle = "yellow" + ctx.beginPath(); + ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2) + ctx.fill() + } } function drawExit(exit) { ctx.fillStyle = "green" diff --git a/src/paperflight/static/items.js b/src/paperflight/static/items.js index 16ea754..47a434e 100644 --- a/src/paperflight/static/items.js +++ b/src/paperflight/static/items.js @@ -15,6 +15,7 @@ function constructCoin(x, y, radius=10){ return { draw: drawCoin, update: updateCoin, + collected: false, x, y, radius } } diff --git a/src/paperflight/static/update.js b/src/paperflight/static/update.js index 3a61647..2a2a949 100644 --- a/src/paperflight/static/update.js +++ b/src/paperflight/static/update.js @@ -14,7 +14,6 @@ function update() { currLevel.items.forEach(item => { item.update() }) - currLevel.items = currLevel.items.filter(item => !item.collected) if (atExit()) { console.log("exit!") } @@ -22,10 +21,11 @@ function update() { function updateVent() { // Custom box since vent height is upwards if (isPlaneInBox({ - x: this.x, - y: this.y-this.height, - width: this.width, - height: this.height})) { + x: this.x, + y: this.y - this.height, + width: this.width, + height: this.height + })) { plane.y -= 2 } } @@ -43,15 +43,16 @@ function updateRamp() { } } function updateCoin() { - if (Math.sqrt(Math.pow(plane.x - this.x, 2) + Math.pow(plane.y - this.y, 2)) < this.radius - || Math.sqrt(Math.pow(plane.x + plane.width - this.x, 2) + Math.pow(plane.y - this.y, 2)) < this.radius) { + if (!this.collected + && (Math.sqrt(Math.pow(plane.x - this.x, 2) + Math.pow(plane.y - this.y, 2)) < this.radius + || Math.sqrt(Math.pow(plane.x + plane.width - this.x, 2) + Math.pow(plane.y - this.y, 2)) < this.radius)) { this.collected = true collected++ } } function updateSwitch() { - if(isPlaneInBox(this)){ - if(!this.inBox){ + if (isPlaneInBox(this)) { + if (!this.inBox) { this.inBox = true switchState = (switchState + 1) % this.stateCount } @@ -60,7 +61,7 @@ function updateSwitch() { } } function updateSwitchRect() { - if(isPlaneInBox(this) && switchState == this.state){ + if (isPlaneInBox(this) && switchState == this.state) { gameOver() } }
\ No newline at end of file |