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