temporarily deleted bouncing and added circling
This commit is contained in:
88
web/game.js
88
web/game.js
@@ -26,10 +26,10 @@ let initialPlayerPosX = playerPosX;
|
|||||||
let initialPlayerPosY = playerPosY;
|
let initialPlayerPosY = playerPosY;
|
||||||
|
|
||||||
let nextAttack;
|
let nextAttack;
|
||||||
let bounceX = bossPosX;
|
// let bounceX = bossPosX;
|
||||||
let bounceY = bossPosY;
|
// let bounceY = bossPosY;
|
||||||
let predictiveBounceX;
|
// let predictiveBounceX;
|
||||||
let predictiveBounceY;
|
// let predictiveBounceY;
|
||||||
let bullets = [];
|
let bullets = [];
|
||||||
let direction;
|
let direction;
|
||||||
let framerate = 120;
|
let framerate = 120;
|
||||||
@@ -38,6 +38,13 @@ let time = 0;
|
|||||||
let shotPoint = 0;
|
let shotPoint = 0;
|
||||||
let angle = 0;
|
let angle = 0;
|
||||||
|
|
||||||
|
let patern = 2;
|
||||||
|
let suroundX = 300;
|
||||||
|
let suroundY = 300;
|
||||||
|
let x2;
|
||||||
|
let y2;
|
||||||
|
|
||||||
|
|
||||||
//let myBullet = new bullet();
|
//let myBullet = new bullet();
|
||||||
// the function setup() is called once when the page is loaded
|
// the function setup() is called once when the page is loaded
|
||||||
function setup() {
|
function setup() {
|
||||||
@@ -58,7 +65,6 @@ function score() {
|
|||||||
|
|
||||||
function life() {
|
function life() {
|
||||||
textAlign(CENTER);
|
textAlign(CENTER);
|
||||||
// text(lives, 500, 20);
|
|
||||||
if (lives == 0) {
|
if (lives == 0) {
|
||||||
fill(255, 0, 0);
|
fill(255, 0, 0);
|
||||||
textSize(40);
|
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
|
// the function draw() is called every frame
|
||||||
function draw() {
|
function draw() {
|
||||||
textSize(10);
|
textSize(10);
|
||||||
@@ -170,13 +142,25 @@ function draw() {
|
|||||||
movementCheck()
|
movementCheck()
|
||||||
// draw boss
|
// draw boss
|
||||||
fill(255, 165, 0)
|
fill(255, 165, 0)
|
||||||
circle(500, 100, 50);
|
circle(x2, y2, 50);
|
||||||
|
|
||||||
score();
|
score();
|
||||||
textAlign(LEFT);
|
textAlign(LEFT);
|
||||||
text(int(time), 10, 20);
|
text(int(time), 10, 20);
|
||||||
|
|
||||||
randomAttackPattern()
|
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 => {
|
bullets.forEach(myBullet => {
|
||||||
//zolang mybullet bestaat blijft hij drawen en updaten
|
//zolang mybullet bestaat blijft hij drawen en updaten
|
||||||
@@ -195,7 +179,6 @@ function draw() {
|
|||||||
|
|
||||||
function randomAttackPattern() {
|
function randomAttackPattern() {
|
||||||
if (shot == false || hit == true) {
|
if (shot == false || hit == true) {
|
||||||
|
|
||||||
spawnRandomBullet()
|
spawnRandomBullet()
|
||||||
spawnRandomBullet()
|
spawnRandomBullet()
|
||||||
spawnRandomBullet()
|
spawnRandomBullet()
|
||||||
@@ -205,13 +188,13 @@ function randomAttackPattern() {
|
|||||||
|
|
||||||
function spawnRandomBullet() {
|
function spawnRandomBullet() {
|
||||||
|
|
||||||
let patern = random([2]);
|
//patern = random([2]);
|
||||||
if (patern == 1) {
|
if (patern == 1) {
|
||||||
nextAttack = random([1, 2, 3, 4]);
|
nextAttack = random([1, 2, 3, 4]);
|
||||||
text(nextAttack, 30, 50);
|
text(nextAttack, 30, 50);
|
||||||
if (nextAttack == 1) {
|
if (nextAttack == 1) {
|
||||||
shotPosX = 500;
|
shotPosX = bossPosX;
|
||||||
shotPosY = 100;
|
shotPosY = bossPosY;
|
||||||
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
|
||||||
}
|
}
|
||||||
if (nextAttack == 2) {
|
if (nextAttack == 2) {
|
||||||
@@ -231,13 +214,18 @@ function spawnRandomBullet() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (patern == 2) {
|
if (patern == 2) {
|
||||||
shotPosX = bounceX;
|
|
||||||
shotPosY = bounceY;
|
shotPosX = x2;
|
||||||
|
shotPosY = y2;
|
||||||
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
|
||||||
}
|
}
|
||||||
|
if (!(patern == 2)) {
|
||||||
|
bossPosX = 500;
|
||||||
|
bossPosY = 100;
|
||||||
|
}
|
||||||
if (patern == 3) {
|
if (patern == 3) {
|
||||||
shotPosX = 500;
|
shotPosX = bossPosX;
|
||||||
shotPosY = 100;
|
shotPosY = bossPosY;
|
||||||
angle = 0;
|
angle = 0;
|
||||||
// changing the angle of the bullets
|
// changing the angle of the bullets
|
||||||
for (let i = 0; i < 86; i++) {
|
for (let i = 0; i < 86; i++) {
|
||||||
@@ -249,8 +237,8 @@ function spawnRandomBullet() {
|
|||||||
angle = 0;
|
angle = 0;
|
||||||
}
|
}
|
||||||
if (patern == 4) {
|
if (patern == 4) {
|
||||||
shotPosX = 500;
|
shotPosX = bossPosX;
|
||||||
shotPosY = 100;
|
shotPosY = bossPosY;
|
||||||
angle = 0;
|
angle = 0;
|
||||||
// changing the angle of the bullets
|
// changing the angle of the bullets
|
||||||
for (let i = 0; i < 86; i++) {
|
for (let i = 0; i < 86; i++) {
|
||||||
|
Reference in New Issue
Block a user