aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-05-14 22:30:41 -0500
committerMark Powers <markppowers0@gmail.com>2020-05-14 22:30:41 -0500
commit7e469de9bc435b622eb415bf403727780ff95f4c (patch)
tree338a04bed2d022a72111cc1c2c4525f517b8772d /src
parent67d08e1f07d6eb261b98e90e6c803d64c22c1969 (diff)
Add switchable vents
Diffstat (limited to 'src')
-rw-r--r--src/paperflight/static/draw.js2
-rw-r--r--src/paperflight/static/items.js4
-rw-r--r--src/paperflight/static/levels.js6
-rw-r--r--src/paperflight/static/update.js17
4 files changed, 18 insertions, 11 deletions
diff --git a/src/paperflight/static/draw.js b/src/paperflight/static/draw.js
index a4d5310..0be9ae9 100644
--- a/src/paperflight/static/draw.js
+++ b/src/paperflight/static/draw.js
@@ -45,7 +45,7 @@ function drawVent() {
ctx.fillRect(this.x, this.y, this.width, 10)
// every 1/3 seconds spawn new air vents
// (since this is purely cosmetic, updates to it are in here)
- if (t % Math.floor(fps / 3) == 0) {
+ if ((this.state == -1 || this.state == switchState) && t % Math.floor(fps / 3) == 0) {
for (var j = 0; j <= this.width; j += 20) {
this.wind.push({
x: this.x + j,
diff --git a/src/paperflight/static/items.js b/src/paperflight/static/items.js
index 09c9888..96f4767 100644
--- a/src/paperflight/static/items.js
+++ b/src/paperflight/static/items.js
@@ -3,12 +3,12 @@
* appear in a level.
*/
-function constructVent(x, y, width, height){
+function constructVent(x, y, width, height, state=-1){
return {
draw: drawVent,
update: updateVent,
wind: [],
- x, y, width, height
+ x, y, width, height, state
}
}
function constructCoin(x, y, radius=10){
diff --git a/src/paperflight/static/levels.js b/src/paperflight/static/levels.js
index 70bd326..bf3a301 100644
--- a/src/paperflight/static/levels.js
+++ b/src/paperflight/static/levels.js
@@ -56,4 +56,10 @@ levels[6].items.push(
constructRect(300, 400, 60, 60, 0),
constructRect(400, 400, 60, 60, 1),
constructRect(500, 400, 60, 60, 2),
+)
+
+levels[7] = createLevel("Turn on the vent", 0, 40, 460)
+levels[7].items.push(
+ constructSwitch(120, 400, 30, 60, 2),
+ constructVent(200, 550, 60, 300, 1),
) \ No newline at end of file
diff --git a/src/paperflight/static/update.js b/src/paperflight/static/update.js
index 0b44089..642e993 100644
--- a/src/paperflight/static/update.js
+++ b/src/paperflight/static/update.js
@@ -8,7 +8,7 @@ function update() {
plane.x += plane.vx * plane.dir
plane.y += plane.vy
}
- if (!isPlaneInBox({ x: plane.width, y: plane.height, width: width - (2*plane.width), height: height - (2*plane.height) })) {
+ if (!isPlaneInBox({ x: plane.width, y: plane.height, width: width - (2 * plane.width), height: height - (2 * plane.height) })) {
gameOver()
}
currLevel.items.forEach(item => {
@@ -17,18 +17,19 @@ function update() {
if (atExit()) {
setLevel(currLevelIndex + 1)
}
- if(gameIsOver){
+ if (gameIsOver) {
window.clearInterval(gameInterval)
}
}
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
- })) {
+ if ((this.state == -1 || this.state == switchState)
+ && isPlaneInBox({
+ x: this.x,
+ y: this.y - this.height,
+ width: this.width,
+ height: this.height
+ })) {
plane.y -= 2
}
}