From b190a905eced00fdc09788b00b364a53923b7882 Mon Sep 17 00:00:00 2001 From: JakeWelch131 Date: Mon, 2 Dec 2024 18:43:16 -0500 Subject: [PATCH 1/7] adding cortana to end of level boss fights --- Main Project/cortanaFight.js | 2 +- Main Project/gameObject.js | 16 ++++++++++++++-- Main Project/player.js | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Main Project/cortanaFight.js b/Main Project/cortanaFight.js index 69dd56a..7a4a5a0 100644 --- a/Main Project/cortanaFight.js +++ b/Main Project/cortanaFight.js @@ -143,7 +143,7 @@ function draw() { player.movePlayer(); player.checkCollisionEnemies(minions); player.checkCollisionProjectiles(inkProjectiles); - player.drawRudderAndSails(); + //player.drawRudderAndSails(); player.checkCollisionTreasureIslands(gameObjects); boss.drawBoss(); diff --git a/Main Project/gameObject.js b/Main Project/gameObject.js index 7b2cc84..a9872a2 100644 --- a/Main Project/gameObject.js +++ b/Main Project/gameObject.js @@ -40,8 +40,20 @@ class GameObject { if (currentLevel > highestLevel) { localStorage.setItem("highestLevelBeat", currentLevel.toString()); } - //do this last!!! - window.location.href = 'bossFight.html'; + // Generate a random number between 0 and 1 + let randomNum = Math.floor(Math.random() * 2); + + // Use a switch statement to handle the different cases + switch (randomNum) { + case 0: + window.location.href = 'bossFight.html'; + break; + case 1: + window.location.href = 'cortanaFight.html'; + break; + default: + console.error('Unexpected random number:', randomNum); + } } } } diff --git a/Main Project/player.js b/Main Project/player.js index 20b4e74..9da57a8 100644 --- a/Main Project/player.js +++ b/Main Project/player.js @@ -28,7 +28,7 @@ class Player { // this.hitIsland = false; this.hitIsland = false; this.playerImage; - this.sailImage; + this.sailImage = './assets/shiplvl1BackSail.png'; this.health = parseInt(localStorage.getItem('playerHealth')) || 10; this.lastCollisionTime = 0; //Tracks the time of last collision this.cannonDamage = parseInt(localStorage.getItem('cannons')) || 1; From e5f7450a92d3f73404293ec76ac8578ac0b2e760 Mon Sep 17 00:00:00 2001 From: Jake Welch Date: Tue, 3 Dec 2024 12:36:14 -0500 Subject: [PATCH 2/7] finished cortana and modified tetris to have a scoring system and pay the player after game ends --- Main Project/cortana.js | 76 ++++++++++-------------------------- Main Project/cortanaFight.js | 61 ++++++++++++++--------------- Main Project/enemy.js | 4 +- Main Project/player.js | 41 ++++++++++++++++++- Main Project/tetris.html | 8 +++- Main Project/tetris.js | 40 ++++++++++++++++++- 6 files changed, 137 insertions(+), 93 deletions(-) diff --git a/Main Project/cortana.js b/Main Project/cortana.js index 67a3d43..6e5bad6 100644 --- a/Main Project/cortana.js +++ b/Main Project/cortana.js @@ -96,11 +96,11 @@ class Boss { return tentacle; } */ - harpoonAttack(player, harpoonImage) { + harpoonAttack(player, harpoonImage, harpoonArray) { if (this.isDead) return; // Harpoon attack - if (!this.harpoon) { - this.harpoon = { + + let harpoon = { x: this.x, y: this.y, length: 300, @@ -110,17 +110,6 @@ class Boss { hasHit: false, duration: 1000, // Harpoon duration in milliseconds // Set up a timer to remove the tentacle after the specified duration - expireTimeout(){ - setTimeout(() => { - this.expire(); - }, this.duration) - }, - expire() { - this.hasHit = false; // Reset hasHit flag - // Remove the tentacle from the tentacles array - tentacles = tentacles.filter(tentacle => tentacle !== this); - clearTimeout(this.expireTimeout); // Clear the timeout - }, draw: function() { push(); translate(this.x, this.y); // Move origin to the harpoon's coordinates @@ -128,50 +117,22 @@ class Boss { imageMode(CENTER); // Set image mode to CENTER image(harpoonImage, this.length / 2 + 30, -this.width / 2, this.length, this.width); // Draw the harpoon image pop(); - }, - hitPlayer(player) { - if (!this.hasHit) { - // Calculate the end point of the tentacle - let endX = this.x + this.length * cos(this.angle); - let endY = this.y + this.length * sin(this.angle); - - // Check if the player is within the tentacle's reach - let distance = dist(player.x, player.y, endX, endY); - if (distance < player.size / 2) { - player.takeDamage(1); - this.hasHit = true; - return true; - } - } - return false; - }, - isExpired: function() { - return millis() - this.creationTime >= this.duration; - }, + }, dragPlayer: function(player) { // Apply a force to drag the player closer to the boss let forceX = (this.x - player.x) * 0.25; let forceY = (this.y - player.y) * 0.25; player.x += forceX; player.y += forceY; - }, - resetHit: function() { - setInterval(() => { - this.hasHit = false; - }, 1000); } + }; - } - // Check for collision and drag the player if hit - /*if (this.harpoon.hitPlayer()) { - this.draw(); - player.takeDamage(1); - this.harpoon.dragPlayer(player); - }*/ - return this.harpoon; + + harpoonArray.push(harpoon); + console.log("harpoon array size in function: " + harpoonArray.length); } - attack(player, minionImage, tentacleImage, projectilesArray, projectileImage) { + attack(player, minionImage, tentacleImage, projectilesArray, projectileImage, harpoonArray) { const currentTime = millis(); if (currentTime - this.lastAttackTime >= 5000) { this.lastAttackTime = currentTime; @@ -179,14 +140,17 @@ class Boss { //let attackType = 2; switch (attackType) { case 0: - console.log("Spawning minions"); - return this.spawnMinions(minionImage); - case 1: - console.log("Shooting ink"); - return this.shootInk(player, projectilesArray); - case 2: - console.log("Tentacle smash"); - return this.harpoonAttack(player, tentacleImage); + console.log("minions assemble"); + return this.spawnMinions(minionImage); + case 1: + this.shootInk(player, projectilesArray); + console.log("cannon attack"); + break; + case 2: + this.harpoonAttack(player, tentacleImage, harpoonArray); + console.log("Harpoon array size in attack: " + harpoonArray.length); + break; + } } diff --git a/Main Project/cortanaFight.js b/Main Project/cortanaFight.js index d76761b..0580fe3 100644 --- a/Main Project/cortanaFight.js +++ b/Main Project/cortanaFight.js @@ -14,7 +14,7 @@ let frameCount = 0; let minions = []; let inkProjectiles = []; -let tentacles = []; +let harpoons = []; let boss; @@ -77,26 +77,10 @@ function setup() { const defeatMessage = document.getElementById('defeat-message'); // Initialize the boss with the new constructor - boss = new Boss(450, 250, 1, healthBarContainer, healthBar, defeatMessage); // Example position and health + boss = new Boss(450, 250, 20, healthBarContainer, healthBar, defeatMessage); // Example position and health boss.bossImage = bossImage; - setInterval(() => { - const attack = boss.attack(player, minionImage, tentacleImage, inkProjectiles, cannonBallImage); - if (attack) { - if (Array.isArray(attack)) { - // for (let i = 0; i < attack.length; i++) { - // attack[i].playerImage = minionImage; - // attack[i].string = "minion"; - // } - minions = minions.concat(attack); - } else if (attack.move) { - inkProjectiles = inkProjectiles.concat(attack); - } else if (attack.draw) { - tentacles.push(attack); - } - } - }, 5000); // 5000 milliseconds = 5 seconds - + // Draw and move minions //camera to follow player @@ -121,7 +105,7 @@ function setup() { function draw() { background(0, 0, 0, 0); //image(backgroundImage, mapXSize / 2 - mapXSize, mapYSize / 2 - mapYSize, mapXSize * 2, mapYSize * 2); - + //console.log("harpoon size outside attack: " + harpoons.length); //border lines stroke(255, 255, 255); line(0, mapXSize, 0, 0); @@ -138,6 +122,21 @@ function draw() { controllerInput(); + setInterval(() => { + const attack = boss.attack(player, minionImage, tentacleImage, inkProjectiles, cannonBallImage, harpoons); + //console.log("harpoon array size at attack invocation: " + harpoons.length); + if (attack) { + if (Array.isArray(attack)) { + // for (let i = 0; i < attack.length; i++) { + // attack[i].playerImage = minionImage; + // attack[i].string = "minion"; + // } + minions = minions.concat(attack); + console.log("Spawning minions"); + } + } + }, 5000); // 5000 milliseconds = 5 seconds + player.drawPlayer(); @@ -161,6 +160,7 @@ function draw() { }); // Draw and move ink projectiles + inkProjectiles.forEach((ink, index) => { ink.image = cannonBallImage; ink.move(); @@ -173,18 +173,15 @@ function draw() { console.log("I've been hit! Health: " + player.health); } }); - - // Draw tentacles and remove them after 1 second - tentacles.forEach((tentacle, index) => { - if (millis() - tentacle.creationTime >= 1000) { - console.log("Tentacle expired"); - tentacles.splice(index, 1); // Remove the tentacle after 1 second - } else { - console.log("Tentacle hit"); - tentacle.draw(); - tentacle.hitPlayer(player); - tentacle.dragPlayer(player); - } + //console.log("harpoon array size: " + harpoons.length); + // Draw harpoons and remove them after 1 second + + harpoons.forEach((harpoon, index) => { + harpoon.draw(); + player.checkCollisionHarpoon(harpoon); + setTimeout(() => { + harpoons.splice(index, 1); + }, 1000); }); diff --git a/Main Project/enemy.js b/Main Project/enemy.js index 51b4f73..5035ada 100644 --- a/Main Project/enemy.js +++ b/Main Project/enemy.js @@ -33,7 +33,7 @@ class Enemy { image(minionImage, this.x, this.y, this.size, this.size); imageMode(CORNER); //returns draw mode to default tint('none'); - console.log("Enemy health: " + this.health); + //console.log("Enemy health: " + this.health); // fill(255, 0, 0); // Set the fill color to red // ellipseMode(CENTER); // Set the ellipse mode to center @@ -68,7 +68,7 @@ class Enemy { // Check if there is a collision if (distance < projectile.size / 2 + this.size / 2) { this.health -= player.cannonDamage; - console.log("Enemy hit! Health: " + this.health); + //console.log("Enemy hit! Health: " + this.health); projectiles.splice(index, 1); } diff --git a/Main Project/player.js b/Main Project/player.js index 20b4e74..13dc5f8 100644 --- a/Main Project/player.js +++ b/Main Project/player.js @@ -411,6 +411,46 @@ class Player { } } + checkCollisionHarpoon(harpoon) { + let hit = false; + const currentTime = Date.now(); + const collisionCooldown = 1000; // Cooldown period in milliseconds (e.g., 1000ms = 1 second) + + // Check for collision along the entire length of the harpoon + const numSegments = 10; // Number of segments to check along the harpoon + for (let i = 0; i <= numSegments; i++) { + let t = i / numSegments; + let checkX = harpoon.x + t * harpoon.length * cos(harpoon.angle); + let checkY = harpoon.y + t * harpoon.length * sin(harpoon.angle); + + // Check if the player is within the tentacle's reach + let distance = dist(player.x, player.y, checkX, checkY); + if (distance < player.size / 2) { + hit = true; + break; // Exit the loop if a collision is detected + } + } + + if (hit && (currentTime - this.lastCollisionTime) > collisionCooldown) { + this.takeDamage(1); // Decrease player health by 1 + this.lastCollisionTime = currentTime; // Update the last collision time + harpoon.dragPlayer(player); + } + + + if (hit && this.timer === 0) { + this.hitEnemy = true; + this.timer = 60; + } + else { + if (this.timer <= 50) { + this.hitEnemy = false; + } + if (this.timer > 0) + this.timer--; + } + } + updateCoinCount() { document.getElementById('coinCount').innerText = this.currency; @@ -589,4 +629,3 @@ if (typeof document !== 'undefined') { }); } -module.exports = Player; \ No newline at end of file diff --git a/Main Project/tetris.html b/Main Project/tetris.html index 5fccf2e..6c7f862 100644 --- a/Main Project/tetris.html +++ b/Main Project/tetris.html @@ -19,7 +19,13 @@ - +
Dabloons:
+