From 24c18521bb983062472b401e9a8a92bb243871e5 Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Tue, 5 Dec 2023 15:27:21 +0100 Subject: [PATCH] trying to add dash --- web/game.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/web/game.js b/web/game.js index 2878d95..4e9fc3d 100644 --- a/web/game.js +++ b/web/game.js @@ -11,10 +11,12 @@ let playerPosY = 300; let playerSpeed = 4; let booleanArray = window.booleanArray; let lives = 1; +let movingX = false; +let movingY = false; let bossPosX = width / 2; let bossPosY = 100; -let shotSpeed = 9; +let shotSpeed = 12; let projectile; let projSize = 5; let shot = false; @@ -98,15 +100,33 @@ function movementCheck() { function keyPressed() { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { playerPosX -= playerSpeed; + movingX = true; + } else { + movingX = false; } if (keyIsDown(RIGHT_ARROW) && playerPosX < width - radius) { playerPosX += playerSpeed; + movingX = true; + } else { + movingX = false; } if (keyIsDown(UP_ARROW) && playerPosY > 0 + radius) { playerPosY -= playerSpeed; + movingY = true; + } else { + movingY = false; } if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { playerPosY += playerSpeed; + movingY = true; + } else { + movingY = false; + } + if (key == ' ' && shot == false && lives != 0) { + if (movingX == true) { + playerPosX += 100; + + } } } @@ -211,22 +231,22 @@ function spawnRandomBullet() { bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (nextAttack == 2) { - shotPosX = random(0, 1000); - shotPosY = 600; + shotPosX = random(0, width); + shotPosY = height; bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (nextAttack == 3) { - shotPosX = 10; - shotPosY = random(0, 600); + shotPosX = 0; + shotPosY = random(0, height); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (nextAttack == 4) { - shotPosX = 1000; - shotPosY = random(0, 600); + shotPosX = width; + shotPosY = random(0, height); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (nextAttack == 5) { - shotPosX = random(0, 1000); + shotPosX = random(0, width); shotPosY = 0; bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } @@ -249,7 +269,7 @@ function spawnRandomBullet() { bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); } if (!(patern == 2)) { - bossPosX = 500; + bossPosX = width / 2; bossPosY = 100; } if (patern == 3) {