added bouncing bullets
This commit is contained in:
63
web/game.js
63
web/game.js
@@ -12,7 +12,8 @@ let playerSpeed = 3;
|
||||
let booleanArray = window.booleanArray;
|
||||
let lives = 2;
|
||||
|
||||
|
||||
let bossPosX = 500;
|
||||
let bossPosY = 100;
|
||||
let shotSpeed = 9;
|
||||
let projectile;
|
||||
let projSize = 5;
|
||||
@@ -22,6 +23,10 @@ let shotPosX;
|
||||
let shotPosY;
|
||||
|
||||
let nextAttack;
|
||||
let bounceX = bossPosX;
|
||||
let bounceY = bossPosY;
|
||||
let predictiveBounceX;
|
||||
let predictiveBounceY;
|
||||
|
||||
let time = 0;
|
||||
|
||||
@@ -59,6 +64,8 @@ function life() {
|
||||
if (key == ' ') {
|
||||
lives = 2;
|
||||
time = 0;
|
||||
bounceX = bossPosX;
|
||||
bounceY = bossPosY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +131,9 @@ function shoot(directionX, directionY) {
|
||||
projectile = null;
|
||||
hit = true;
|
||||
}
|
||||
else if (projectile.x < 0-10 || projectile.x > width+10 || projectile.y < 0-10 || projectile.y > height+10) {
|
||||
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;
|
||||
}
|
||||
@@ -153,29 +162,37 @@ function draw() {
|
||||
text(time, 10, 20);
|
||||
|
||||
if (shot == false || hit == true) {
|
||||
nextAttack = random([1,2,3,4]);
|
||||
text(nextAttack, 30, 50);
|
||||
if (nextAttack == 1) {
|
||||
shotPosX = 500;
|
||||
shotPosY = 100;
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 2) {
|
||||
shotPosX = random(0, 1000);
|
||||
shotPosY = 600;
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 3) {
|
||||
shotPosX = 0;
|
||||
shotPosY = random(0, 600);
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 4) {
|
||||
shotPosX = 1000;
|
||||
shotPosY = random(0, 600);
|
||||
let patern = random([1,2]);
|
||||
if (patern == 1) {
|
||||
nextAttack = random([1, 2, 3, 4]);
|
||||
text(nextAttack, 30, 50);
|
||||
if (nextAttack == 1) {
|
||||
shotPosX = 500;
|
||||
shotPosY = 100;
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 2) {
|
||||
shotPosX = random(0, 1000);
|
||||
shotPosY = 600;
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 3) {
|
||||
shotPosX = 0;
|
||||
shotPosY = random(0, 600);
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
if (nextAttack == 4) {
|
||||
shotPosX = 1000;
|
||||
shotPosY = random(0, 600);
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
}
|
||||
if (patern == 2) {
|
||||
shotPosX = bounceX;
|
||||
shotPosY = bounceY;
|
||||
shoot(playerPosX, playerPosY);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user