aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-05-14 10:29:07 -0500
committerMark Powers <markppowers0@gmail.com>2020-05-14 10:29:07 -0500
commitc5d5990eecd254f3d5daf33a6c9cd394dcba2058 (patch)
tree60cc8a229afe44fa4b4189e1016895fadee58ef9
parentae74d0d38196c14ea79cef2444f508c649c57580 (diff)
Fix coin not respawning on reset
-rw-r--r--src/paperflight/index.html5
-rw-r--r--src/paperflight/static/draw.js10
-rw-r--r--src/paperflight/static/items.js1
-rw-r--r--src/paperflight/static/update.js21
4 files changed, 23 insertions, 14 deletions
diff --git a/src/paperflight/index.html b/src/paperflight/index.html
index 26540b4..ef26a03 100644
--- a/src/paperflight/index.html
+++ b/src/paperflight/index.html
@@ -69,6 +69,11 @@
currLevelIndex = to
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
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