From 6714c1190bafcedd08bbca2b663d4e7c87571dd0 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:29:37 +0000 Subject: [PATCH 1/8] updating p5js version --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index e2f71a0..ab18c32 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@
- + From 8e2128a523bf58675432661a12bfcd2d9f595c52 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:30:08 +0000 Subject: [PATCH 2/8] Asteroid class modified to add the concept of a bonus asteroid with color --- src/asteroid.js | 11 +++++++++-- src/debri.js | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/asteroid.js b/src/asteroid.js index 1dcf9b4..b186480 100644 --- a/src/asteroid.js +++ b/src/asteroid.js @@ -5,6 +5,13 @@ class Asteroid extends Debri { this.movementX = random(-1, 1); this.debri = []; this.exploded = false; + this.isBonus = false; + this.color = undefined; + } + + setIsBonus(value) { + this.isBonus = value; + if (value) this.color = color(random(150, 200), random(150, 200), random(150, 200)); } hasExploded() { @@ -40,7 +47,7 @@ class Asteroid extends Debri { } draw() { - super.draw(); - this.debri.forEach(debri => debri.draw()); + super.draw(this.color); + this.debri.forEach(debri => debri.draw(this.color)); } } \ No newline at end of file diff --git a/src/debri.js b/src/debri.js index c9ef14a..04dda5c 100644 --- a/src/debri.js +++ b/src/debri.js @@ -42,10 +42,11 @@ class Debri { return p5.Vector.add(p1, p2).div(2); } - draw() { + draw(color) { push(); beginShape(); - noFill(); + if (color) fill(color); + else noFill(); stroke(255); for (let i = 0; i < this.verticies.length; i++) { const { x, y } = this.verticies[i]; From 370c9d8e1a412364c813c433681275ee6d10aea0 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:30:27 +0000 Subject: [PATCH 3/8] Ship class modified to add more bullets when in bonus time --- src/ship.js | 256 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 150 insertions(+), 106 deletions(-) diff --git a/src/ship.js b/src/ship.js index 08e2402..1220dac 100644 --- a/src/ship.js +++ b/src/ship.js @@ -1,108 +1,152 @@ class Ship { - constructor(x, y, bulletMovement, initialHearts, bulletsLimit) { - this.x = x; - this.y = y; - this.hearts = initialHearts; - this.score = 0; - this.bullets = new MovableObjects(0, -bulletMovement); - this.bulletsLimit = bulletsLimit; - } - - getBullets() { - return this.bullets.collection; - } - - getScore() { - return this.score; - } - - deleteBullet(index) { - this.bullets.deleteByIndex(index); - } - - setShootSoundEffect(soundEffect) { - soundEffect.setVolume(0.02); - this.shootSoundEffect = soundEffect; - } - - setHeartImage(image) { - this.heartImage = image; - } - - setScoreFont(font) { - this.scoreFont = font; - } - - shoot() { - if (this.bullets.size() < this.bulletsLimit) { - this.shootSoundEffect.play(); - this.bullets.add({ - x: mapXLimits(mouseX), - y: height - 50, - }); - } - } - - incrementScore(inc) { - this.score += inc; - } - - decrementHearts() { - this.hearts--; - } - - hasAnyHeartsLeft() { - return this.hearts > 0; - } - - draw(x) { - this.drawScore(); - if (!gameOver) { - this.drawHearts(); - this.drawBullets(); - let translateX = mapXLimits(x); - push(); - translate(translateX, this.y); - rectMode(CENTER); - noStroke(); - fill(255); - rect(0, 0, 60, 20); - rect(0, -20, 20, 20); - pop(); - } - } - - drawBullets() { - if (this.bullets.size() > 0) this.bullets.move((x, y) => y < 0); - this.bullets.draw((x, y) => { - translate(x, y); - fill(255); - noStroke(); - rect(0, 0, 2, 10); - }); - } - - drawHearts() { - for (let i = 0; i < this.hearts; i++) { - const xPos = (20 * i) + 20; - const offset = 25 * i; - image(this.heartImage, xPos + offset, 25, 35, 35, 0, 0); - } - } - - drawScore() { - push(); - fill(255); - textFont(this.scoreFont); - textSize(15); - if (!gameOver) { - text(`Score: ${this.score}`, 20, 100); - } else { - text("Final Score", (width / 2) - 80, 75); - if (this.score === 0) text(this.score, (width / 2) - 10, 110); - else if (this.score < 1000) text(this.score, (width / 2) - 20, 110); - else text(this.score, (width / 2) - 30, 110); - } - pop(); - } + constructor(x, y, bulletMovement, initialHearts, bulletsLimit) { + this.x = x; + this.y = y; + this.hearts = initialHearts; + this.score = 0; + this.bullets = new MovableObjects(0, -bulletMovement); + this.bulletsLimit = bulletsLimit; + this.multShooterEnabled = false; + } + + getBullets() { + return this.bullets.collection; + } + + getScore() { + return this.score; + } + + deleteBullet(index) { + this.bullets.deleteByIndex(index); + } + + setShootSoundEffect(soundEffect) { + soundEffect.setVolume(0.02); + this.shootSoundEffect = soundEffect; + } + + setHeartImage(image) { + this.heartImage = image; + } + + setScoreFont(font) { + this.scoreFont = font; + } + + setAdditionalShots(difficulty) { + if (globalDifficulty === "EASY") this.additionalShots = 1; + else if (globalDifficulty === "MEDIUM") this.additionalShots = 2; + else if (globalDifficulty === "HARD") this.additionalShots = 4; + } + + shoot() { + const limit = this.multShooterEnabled ? this.bulletsLimit * (this.additionalShots + 1) : this.bulletsLimit; + if (this.bullets.size() < limit) { + this.shootSoundEffect.play(); + if (this.multShooterEnabled) { + for (let i = 0; i < this.additionalShots + 1; i++) { + const xOffset = this.additionalShots > 3 ? 5 * this.additionalShots : 0; + const xInOffset = this.addiotnalShots > 3 ? 15 : 20; + this.bullets.add({ + x: (mapXLimits(mouseX) + ((xInOffset * i) - xInOffset)) - xOffset, + y: height - (i % 2 == 0 ? 25 : 50), + }); + } + } else { + this.bullets.add({ + x: mapXLimits(mouseX), + y: height - 50 + }); + } + } + } + + incrementScore(inc) { + this.score += inc; + } + + decrementHearts() { + this.hearts--; + } + + hasAnyHeartsLeft() { + return this.hearts > 0; + } + + hasMultShooter() { + return this.multShooterEnabled; + } + + enableMultShooter() { + this.bonusTime = new Date(); + this.multShooterEnabled = true; + } + + draw(x) { + if (this.multShooterEnabled) { + const diff = new Date().getTime() - this.bonusTime.getTime(); + if (((diff % 60000) / 1000).toFixed(0) >= 10) { + this.multShooterEnabled = false; + this.bullets.deleteAll(); + } + } + this.drawScore(); + if (!gameOver) { + this.drawHearts(); + this.drawBullets(); + let translateX = mapXLimits(x); + push(); + translate(translateX, this.y); + rectMode(CENTER); + noStroke(); + fill(255); + rect(0, 0, 60, 20); + rect(0, -20, 20, 20); + pop(); + } + } + + drawBullets() { + if (this.bullets.size() > 0) this.bullets.move((x, y) => y < 0); + if (this.multShooterEnabled) { + this.bullets.drawBatch((x, y) => { + translate(x, y); + fill(255); + noStroke(); + rect(0, 0, 2, 10); + }, this.additionalShots + 1); + } else { + this.bullets.draw((x, y) => { + translate(x, y); + fill(255); + noStroke(); + rect(0, 0, 2, 10); + }); + } + } + + drawHearts() { + for (let i = 0; i < this.hearts; i++) { + const xPos = (20 * i) + 20; + const offset = 25 * i; + image(this.heartImage, xPos + offset, 25, 35, 35, 0, 0); + } + } + + drawScore() { + push(); + fill(255); + textFont(this.scoreFont); + textSize(15); + if (!gameOver) { + text(`Score: ${this.score}`, 20, 100); + } else { + text("Final Score", (width / 2) - 80, 75); + if (this.score === 0) text(this.score, (width / 2) - 10, 110); + else if (this.score < 1000) text(this.score, (width / 2) - 20, 110); + else text(this.score, (width / 2) - 30, 110); + } + pop(); + } } From 30c78f16d11c33ac5198138f95585c5e09d9319e Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:30:54 +0000 Subject: [PATCH 4/8] Movable class modified to add drawBatch function to draw several items at once --- src/movable.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/movable.js b/src/movable.js index a952c23..5a6d80e 100644 --- a/src/movable.js +++ b/src/movable.js @@ -10,28 +10,47 @@ class MovableObjects { }); } } - + add(movable) { this.collection.push(movable); } - + deleteByIndex(idx) { this.collection.splice(idx, 1); } - + + deleteAll() { + this.collection = []; + } + size() { return this.collection.length; } - + draw(drawFn) { for (let i = 0; i < this.collection.length; i++) { - let { x, y } = this.collection[i]; + let { x, y, angle } = this.collection[i]; push(); - drawFn(x, y); + drawFn(x, y, angle); pop(); } } - + + drawBatch(drawFn, batchSize) { + angleMode(RADIANS); + const end = round(this.collection.length / batchSize); + for (let i = 0; i < end; i++) { + for (let j = i * batchSize; j < (i * batchSize) + batchSize; j++) { + if (this.collection[j]) { + let { x, y } = this.collection[j]; + push(); + drawFn(x, y); + pop(); + } + } + } + } + move(condition, shouldResetY) { for (let i = 0; i < this.collection.length; i++) { let { x, y } = this.collection[i]; From 7fef649a37c5c23e354448843ce12765908d7a35 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:31:12 +0000 Subject: [PATCH 5/8] adjustments for when a bonus asteroid is hit --- sketch.js | 70 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/sketch.js b/sketch.js index c508f41..6050c72 100644 --- a/sketch.js +++ b/sketch.js @@ -48,21 +48,39 @@ function setup() { createCanvas(windowWidth, windowHeight); gui = createGui(); easyButton = createButton("Restart Game [Easy]", (width / 2) - 375, (height / 2) + 100, 230, 40); + easyButton.visible = false; + easyButton.setStyle({ + strokeBg: color(255), + fillBg: color(95, 220, 227), + fillLabel: color(0), + fillBgHover: color(140, 232, 237), + fillLabelHover: color(0), + strokeBgHover: color(255), + }); + mediumButton = createButton("Restart Game [Medium]", (width / 2) - 125, (height / 2) + 100, 250, 40); + mediumButton.visible = false; + mediumButton.setStyle({ + strokeBg: color(255), + fillBg: color(245, 186, 91), + fillLabel: color(0), + fillBgHover: color(250, 201, 122), + fillLabelHover: color(0), + strokeBgHover: color(255) + }); + hardButton = createButton("Restart Game [Hard]", (width / 2) + 145, (height / 2) + 100, 230, 40); + hardButton.visible = false; + hardButton.setStyle({ + strokeBg: color(255), + fillBg: color(255, 130, 84), + fillLabel: color(0), + fillBgHover: color(250, 156, 122), + fillLabelHover: color(0), + strokeBgHover: color(255) + }); + buttons = [easyButton, mediumButton, hardButton]; - for (button of buttons) { - button.visible = false; - button.setStyle({ - strokeBg: color(255), - fillBg: color(0), - fillLabel: color(255), - fillBgActive: color(255), - fillLabelActive: color(0), - fillBgHover: color(255), - fillLabelHover: color(0) - }); - } restartGame("EASY"); } @@ -84,6 +102,7 @@ function draw() { drawStars(); drawAsteroids(); drawDifficulty(); + drawBonusText(); ship.draw(mouseX); if (!ship.hasAnyHeartsLeft() || gameOver) { asteroids = []; @@ -133,6 +152,7 @@ function restartGame(difficulty) { ship.setShootSoundEffect(shootEffect); ship.setHeartImage(heartImage); ship.setScoreFont(psFont); + ship.setAdditionalShots(difficulty); stars = new MovableObjects(0, starsMovement, numberOfStars); buttons.forEach(button => button.visible = false); asteroids = Array(numberOfInitialAsteroids) @@ -156,10 +176,14 @@ function drawAsteroids() { if (!gameOver) { if (frameCount % 50 === 0) { for (let i = 0; i < asteroidsToAdd; i++) { - asteroids.push(new Asteroid(random(50, width - 50), random(10, 20))); + const asteroid = new Asteroid(random(50, width - 50), random(10, 20)); + if (random() < 0.15 && !ship.hasMultShooter()) { + asteroid.setIsBonus(true); + } + asteroids.push(asteroid); } } - + for (let i = 0; i < asteroids.length; i++) { const asteroid = asteroids[i]; const idxBullet = asteroid.isHitBy(ship.getBullets()); @@ -168,13 +192,14 @@ function drawAsteroids() { asteroids.splice(i, 1); continue; } - + if (!asteroid.hasExploded() && idxBullet >= 0) { ship.incrementScore(scoreIncrement * scoreMultiplier); asteroid.explode(explodeEffect); ship.deleteBullet(idxBullet); + if (asteroid.isBonus && !ship.hasMultShooter()) ship.enableMultShooter(); } - + asteroid.move(); asteroid.draw(); } @@ -187,13 +212,24 @@ function drawDifficulty() { textFont(psFont); textSize(12); if (globalDifficulty === "EASY") fill(68, 161, 160); - else if(globalDifficulty === "MEDIUM") fill(238, 184, 104); + else if (globalDifficulty === "MEDIUM") fill(238, 184, 104); else if (globalDifficulty === "HARD") fill(250, 0, 63); text(`Difficulty [${globalDifficulty}]`, 20, 130); pop(); } } +function drawBonusText() { + if (ship.hasMultShooter() && !gameOver) { + push(); + fill(150, 0, 100); + textFont(psFont); + textSize(10); + text("Bonus [ACTIVE]", 20, 160); + pop(); + } +} + function drawAttribution() { push(); fill(255); From 2e2a30ff53b12106b9bb7b095f05b4e9c9d3e741 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:38:00 +0000 Subject: [PATCH 6/8] fix indentation --- sketch.js | 2 +- src/ship.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sketch.js b/sketch.js index 6050c72..2f7f0fb 100644 --- a/sketch.js +++ b/sketch.js @@ -152,7 +152,7 @@ function restartGame(difficulty) { ship.setShootSoundEffect(shootEffect); ship.setHeartImage(heartImage); ship.setScoreFont(psFont); - ship.setAdditionalShots(difficulty); + ship.setAdditionalShots(); stars = new MovableObjects(0, starsMovement, numberOfStars); buttons.forEach(button => button.visible = false); asteroids = Array(numberOfInitialAsteroids) diff --git a/src/ship.js b/src/ship.js index 1220dac..f992e81 100644 --- a/src/ship.js +++ b/src/ship.js @@ -34,7 +34,7 @@ class Ship { this.scoreFont = font; } - setAdditionalShots(difficulty) { + setAdditionalShots() { if (globalDifficulty === "EASY") this.additionalShots = 1; else if (globalDifficulty === "MEDIUM") this.additionalShots = 2; else if (globalDifficulty === "HARD") this.additionalShots = 4; From c048f366a856fb4841b111ab6dbb473012134347 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:40:11 +0000 Subject: [PATCH 7/8] fix indentation --- src/ship.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ship.js b/src/ship.js index f992e81..a4714fc 100644 --- a/src/ship.js +++ b/src/ship.js @@ -140,7 +140,7 @@ class Ship { textFont(this.scoreFont); textSize(15); if (!gameOver) { - text(`Score: ${this.score}`, 20, 100); + text(`Score: ${this.score}`,20, 100); } else { text("Final Score", (width / 2) - 80, 75); if (this.score === 0) text(this.score, (width / 2) - 10, 110); From 1eb11ecdbdbac2bd0d5a1f35393854b848325b71 Mon Sep 17 00:00:00 2001 From: Miguel Manjarres <54128874+DevTony101@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:41:32 +0000 Subject: [PATCH 8/8] fix indentation --- src/ship.js | 300 ++++++++++++++++++++++++++-------------------------- 1 file changed, 150 insertions(+), 150 deletions(-) diff --git a/src/ship.js b/src/ship.js index a4714fc..67bad79 100644 --- a/src/ship.js +++ b/src/ship.js @@ -1,152 +1,152 @@ class Ship { - constructor(x, y, bulletMovement, initialHearts, bulletsLimit) { - this.x = x; - this.y = y; - this.hearts = initialHearts; - this.score = 0; - this.bullets = new MovableObjects(0, -bulletMovement); - this.bulletsLimit = bulletsLimit; - this.multShooterEnabled = false; - } - - getBullets() { - return this.bullets.collection; - } - - getScore() { - return this.score; - } - - deleteBullet(index) { - this.bullets.deleteByIndex(index); - } - - setShootSoundEffect(soundEffect) { - soundEffect.setVolume(0.02); - this.shootSoundEffect = soundEffect; - } - - setHeartImage(image) { - this.heartImage = image; - } - - setScoreFont(font) { - this.scoreFont = font; - } - - setAdditionalShots() { - if (globalDifficulty === "EASY") this.additionalShots = 1; - else if (globalDifficulty === "MEDIUM") this.additionalShots = 2; - else if (globalDifficulty === "HARD") this.additionalShots = 4; - } - - shoot() { - const limit = this.multShooterEnabled ? this.bulletsLimit * (this.additionalShots + 1) : this.bulletsLimit; - if (this.bullets.size() < limit) { - this.shootSoundEffect.play(); - if (this.multShooterEnabled) { - for (let i = 0; i < this.additionalShots + 1; i++) { - const xOffset = this.additionalShots > 3 ? 5 * this.additionalShots : 0; - const xInOffset = this.addiotnalShots > 3 ? 15 : 20; - this.bullets.add({ - x: (mapXLimits(mouseX) + ((xInOffset * i) - xInOffset)) - xOffset, - y: height - (i % 2 == 0 ? 25 : 50), - }); - } - } else { - this.bullets.add({ - x: mapXLimits(mouseX), - y: height - 50 - }); - } - } - } - - incrementScore(inc) { - this.score += inc; - } - - decrementHearts() { - this.hearts--; - } - - hasAnyHeartsLeft() { - return this.hearts > 0; - } - - hasMultShooter() { - return this.multShooterEnabled; - } - - enableMultShooter() { - this.bonusTime = new Date(); - this.multShooterEnabled = true; - } - - draw(x) { - if (this.multShooterEnabled) { - const diff = new Date().getTime() - this.bonusTime.getTime(); - if (((diff % 60000) / 1000).toFixed(0) >= 10) { - this.multShooterEnabled = false; - this.bullets.deleteAll(); - } - } - this.drawScore(); - if (!gameOver) { - this.drawHearts(); - this.drawBullets(); - let translateX = mapXLimits(x); - push(); - translate(translateX, this.y); - rectMode(CENTER); - noStroke(); - fill(255); - rect(0, 0, 60, 20); - rect(0, -20, 20, 20); - pop(); - } - } - - drawBullets() { - if (this.bullets.size() > 0) this.bullets.move((x, y) => y < 0); - if (this.multShooterEnabled) { - this.bullets.drawBatch((x, y) => { - translate(x, y); - fill(255); - noStroke(); - rect(0, 0, 2, 10); - }, this.additionalShots + 1); - } else { - this.bullets.draw((x, y) => { - translate(x, y); - fill(255); - noStroke(); - rect(0, 0, 2, 10); - }); - } - } - - drawHearts() { - for (let i = 0; i < this.hearts; i++) { - const xPos = (20 * i) + 20; - const offset = 25 * i; - image(this.heartImage, xPos + offset, 25, 35, 35, 0, 0); - } - } - - drawScore() { - push(); - fill(255); - textFont(this.scoreFont); - textSize(15); - if (!gameOver) { - text(`Score: ${this.score}`,20, 100); - } else { - text("Final Score", (width / 2) - 80, 75); - if (this.score === 0) text(this.score, (width / 2) - 10, 110); - else if (this.score < 1000) text(this.score, (width / 2) - 20, 110); - else text(this.score, (width / 2) - 30, 110); - } - pop(); - } + constructor(x, y, bulletMovement, initialHearts, bulletsLimit) { + this.x = x; + this.y = y; + this.hearts = initialHearts; + this.score = 0; + this.bullets = new MovableObjects(0, -bulletMovement); + this.bulletsLimit = bulletsLimit; + this.multShooterEnabled = false; + } + + getBullets() { + return this.bullets.collection; + } + + getScore() { + return this.score; + } + + deleteBullet(index) { + this.bullets.deleteByIndex(index); + } + + setShootSoundEffect(soundEffect) { + soundEffect.setVolume(0.02); + this.shootSoundEffect = soundEffect; + } + + setHeartImage(image) { + this.heartImage = image; + } + + setScoreFont(font) { + this.scoreFont = font; + } + + setAdditionalShots() { + if (globalDifficulty === "EASY") this.additionalShots = 1; + else if (globalDifficulty === "MEDIUM") this.additionalShots = 2; + else if (globalDifficulty === "HARD") this.additionalShots = 4; + } + + shoot() { + const limit = this.multShooterEnabled ? this.bulletsLimit * (this.additionalShots + 1) : this.bulletsLimit; + if (this.bullets.size() < limit) { + this.shootSoundEffect.play(); + if (this.multShooterEnabled) { + for (let i = 0; i < this.additionalShots + 1; i++) { + const xOffset = this.additionalShots > 3 ? 5 * this.additionalShots : 0; + const xInOffset = this.addiotnalShots > 3 ? 15 : 20; + this.bullets.add({ + x: (mapXLimits(mouseX) + ((xInOffset * i) - xInOffset)) - xOffset, + y: height - (i % 2 == 0 ? 25 : 50), + }); + } + } else { + this.bullets.add({ + x: mapXLimits(mouseX), + y: height - 50 + }); + } + } + } + + incrementScore(inc) { + this.score += inc; + } + + decrementHearts() { + this.hearts--; + } + + hasAnyHeartsLeft() { + return this.hearts > 0; + } + + hasMultShooter() { + return this.multShooterEnabled; + } + + enableMultShooter() { + this.bonusTime = new Date(); + this.multShooterEnabled = true; + } + + draw(x) { + if (this.multShooterEnabled) { + const diff = new Date().getTime() - this.bonusTime.getTime(); + if (((diff % 60000) / 1000).toFixed(0) >= 10) { + this.multShooterEnabled = false; + this.bullets.deleteAll(); + } + } + this.drawScore(); + if (!gameOver) { + this.drawHearts(); + this.drawBullets(); + let translateX = mapXLimits(x); + push(); + translate(translateX, this.y); + rectMode(CENTER); + noStroke(); + fill(255); + rect(0, 0, 60, 20); + rect(0, -20, 20, 20); + pop(); + } + } + + drawBullets() { + if (this.bullets.size() > 0) this.bullets.move((x, y) => y < 0); + if (this.multShooterEnabled) { + this.bullets.drawBatch((x, y) => { + translate(x, y); + fill(255); + noStroke(); + rect(0, 0, 2, 10); + }, this.additionalShots + 1); + } else { + this.bullets.draw((x, y) => { + translate(x, y); + fill(255); + noStroke(); + rect(0, 0, 2, 10); + }); + } + } + + drawHearts() { + for (let i = 0; i < this.hearts; i++) { + const xPos = (20 * i) + 20; + const offset = 25 * i; + image(this.heartImage, xPos + offset, 25, 35, 35, 0, 0); + } + } + + drawScore() { + push(); + fill(255); + textFont(this.scoreFont); + textSize(15); + if (!gameOver) { + text(`Score: ${this.score}`, 20, 100); + } else { + text("Final Score", (width / 2) - 80, 75); + if (this.score === 0) text(this.score, (width / 2) - 10, 110); + else if (this.score < 1000) text(this.score, (width / 2) - 20, 110); + else text(this.score, (width / 2) - 30, 110); + } + pop(); + } }