From 6d19f148d337dfd9b035c486188fdafe1e7cf3df Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Mon, 4 Dec 2023 13:26:09 +0100 Subject: [PATCH] temporarily deleted bouncing and added circling --- web/game.js | 88 +++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/web/game.js b/web/game.js index 1785408..87ebbe6 100644 --- a/web/game.js +++ b/web/game.js @@ -26,10 +26,10 @@ let initialPlayerPosX = playerPosX; let initialPlayerPosY = playerPosY; let nextAttack; -let bounceX = bossPosX; -let bounceY = bossPosY; -let predictiveBounceX; -let predictiveBounceY; +// let bounceX = bossPosX; +// let bounceY = bossPosY; +// let predictiveBounceX; +// let predictiveBounceY; let bullets = []; let direction; let framerate = 120; @@ -38,6 +38,13 @@ let time = 0; let shotPoint = 0; let angle = 0; +let patern = 2; +let suroundX = 300; +let suroundY = 300; +let x2; +let y2; + + //let myBullet = new bullet(); // the function setup() is called once when the page is loaded function setup() { @@ -58,7 +65,6 @@ function score() { function life() { textAlign(CENTER); - // text(lives, 500, 20); if (lives == 0) { fill(255, 0, 0); textSize(40); @@ -121,40 +127,6 @@ async function Movementloop() { }); } -// function shoot(directionX, directionY) { -// shot = true; -// hit = false; - -// if (!projectile) { -// // Set the initial position of the projectile to the player's position -// projectile = createVector(shotPosX, shotPosY); -// targetX = directionX; -// targetY = directionY; - -// // Calculate the initial direction -// direction = createVector(targetX - projectile.x, targetY - projectile.y); -// direction.normalize(); -// } - -// // Draw the small circle (projectile) -// fill(255, 0, 0); -// circle(projectile.x, projectile.y, projSize); - -// // Move the projectile towards the movable circle -// projectile.add(p5.Vector.mult(direction, shotSpeed)); - -// if (dist(projectile.x, projectile.y, directionX, directionY) <= radius) { -// projectile = null; -// hit = true; -// } -// else if (projectile.x < 0 - 10 || projectile.x > width + 10 || projectile.y < 0 - 10 || projectile.y > height + 10) { -// bounceX = projectile.x; -// bounceY = projectile.y; -// projectile = null; -// shot = false; -// } -// } - // the function draw() is called every frame function draw() { textSize(10); @@ -170,13 +142,25 @@ function draw() { movementCheck() // draw boss fill(255, 165, 0) - circle(500, 100, 50); + circle(x2, y2, 50); score(); textAlign(LEFT); text(int(time), 10, 20); randomAttackPattern() + if (patern == 2) { + suroundX += 2; + suroundY += 2; + let sinX = sin(suroundX); + let cosY = cos(suroundY); + x2 = map(sinX, -1, 1, playerPosX - 200, playerPosX + 200); + y2 = map(cosY, -1, 1, playerPosY - 200, playerPosY + 200); + //circle(x2, y2, 50); + } else { + x2 = bossPosX; + y2 = bossPosY; + } bullets.forEach(myBullet => { //zolang mybullet bestaat blijft hij drawen en updaten @@ -195,7 +179,6 @@ function draw() { function randomAttackPattern() { if (shot == false || hit == true) { - spawnRandomBullet() spawnRandomBullet() spawnRandomBullet() @@ -205,13 +188,13 @@ function randomAttackPattern() { function spawnRandomBullet() { - let patern = random([2]); + //patern = random([2]); if (patern == 1) { nextAttack = random([1, 2, 3, 4]); text(nextAttack, 30, 50); if (nextAttack == 1) { - shotPosX = 500; - shotPosY = 100; + shotPosX = bossPosX; + shotPosY = bossPosY; bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (nextAttack == 2) { @@ -231,13 +214,18 @@ function spawnRandomBullet() { } } if (patern == 2) { - shotPosX = bounceX; - shotPosY = bounceY; + + shotPosX = x2; + shotPosY = y2; bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } + if (!(patern == 2)) { + bossPosX = 500; + bossPosY = 100; + } if (patern == 3) { - shotPosX = 500; - shotPosY = 100; + shotPosX = bossPosX; + shotPosY = bossPosY; angle = 0; // changing the angle of the bullets for (let i = 0; i < 86; i++) { @@ -249,8 +237,8 @@ function spawnRandomBullet() { angle = 0; } if (patern == 4) { - shotPosX = 500; - shotPosY = 100; + shotPosX = bossPosX; + shotPosY = bossPosY; angle = 0; // changing the angle of the bullets for (let i = 0; i < 86; i++) {