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