From 406a044585fd52d4d9ac926868ce096740c04457 Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Sun, 26 Nov 2023 19:07:12 +0100 Subject: [PATCH] adde secodn attack (off screen) not random choice --- web/game.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/web/game.js b/web/game.js index b69bf2e..73d6f65 100644 --- a/web/game.js +++ b/web/game.js @@ -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,10 +154,18 @@ function draw() { text(time, 10, 20); if (shot == false || hit == true) { - shoot(playerPosX, playerPosY); - } else { - shot = false; - } + nextAttack = random(1, 2); + if (nextAttack == 1) { + shotPosX = 500; + shotPosY = 100; + shoot(playerPosX, playerPosY); + } + if (nextAttack == 2) { + shotPosX = random(0, 1000); + shotPosY = 600; + shoot(playerPosX, playerPosY); + } + } } } \ No newline at end of file