adde secodn attack (off screen) not random choice

This commit is contained in:
Mees Roelofsz
2023-11-26 19:07:12 +01:00
parent b65d21dca1
commit 406a044585

View File

@@ -18,8 +18,10 @@ let projectile;
let projSize = 5;
let shot;
let hit;
let shotPosX = 500;
let shotPosY = 100;
let shotPosX;
let shotPosY;
let nextAttack;
let time = 0;
@@ -123,7 +125,7 @@ function shoot(directionX, directionY) {
projectile = null;
hit = true;
}
else if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) {
else if (projectile.x < 0-10 || projectile.x > width+10 || projectile.y < 0-10 || projectile.y > height+10) {
projectile = null;
shot = false;
}
@@ -131,6 +133,7 @@ function shoot(directionX, directionY) {
// the function draw() is called every frame
function draw() {
shot = false;
textSize(10);
keyPressed();
life();
@@ -151,9 +154,17 @@ function draw() {
text(time, 10, 20);
if (shot == false || hit == true) {
nextAttack = random(1, 2);
if (nextAttack == 1) {
shotPosX = 500;
shotPosY = 100;
shoot(playerPosX, playerPosY);
} else {
shot = false;
}
if (nextAttack == 2) {
shotPosX = random(0, 1000);
shotPosY = 600;
shoot(playerPosX, playerPosY);
}
}
}