trying to add dash

This commit is contained in:
Mees Roelofsz
2023-12-05 15:27:21 +01:00
parent 6ae68876c1
commit 24c18521bb

View File

@@ -11,10 +11,12 @@ let playerPosY = 300;
let playerSpeed = 4; let playerSpeed = 4;
let booleanArray = window.booleanArray; let booleanArray = window.booleanArray;
let lives = 1; let lives = 1;
let movingX = false;
let movingY = false;
let bossPosX = width / 2; let bossPosX = width / 2;
let bossPosY = 100; let bossPosY = 100;
let shotSpeed = 9; let shotSpeed = 12;
let projectile; let projectile;
let projSize = 5; let projSize = 5;
let shot = false; let shot = false;
@@ -98,15 +100,33 @@ function movementCheck() {
function keyPressed() { function keyPressed() {
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
playerPosX -= playerSpeed; playerPosX -= playerSpeed;
movingX = true;
} else {
movingX = false;
} }
if (keyIsDown(RIGHT_ARROW) && playerPosX < width - radius) { if (keyIsDown(RIGHT_ARROW) && playerPosX < width - radius) {
playerPosX += playerSpeed; playerPosX += playerSpeed;
movingX = true;
} else {
movingX = false;
} }
if (keyIsDown(UP_ARROW) && playerPosY > 0 + radius) { if (keyIsDown(UP_ARROW) && playerPosY > 0 + radius) {
playerPosY -= playerSpeed; playerPosY -= playerSpeed;
movingY = true;
} else {
movingY = false;
} }
if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) {
playerPosY += playerSpeed; 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)); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
} }
if (nextAttack == 2) { if (nextAttack == 2) {
shotPosX = random(0, 1000); shotPosX = random(0, width);
shotPosY = 600; shotPosY = height;
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
} }
if (nextAttack == 3) { if (nextAttack == 3) {
shotPosX = 10; shotPosX = 0;
shotPosY = random(0, 600); shotPosY = random(0, height);
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
} }
if (nextAttack == 4) { if (nextAttack == 4) {
shotPosX = 1000; shotPosX = width;
shotPosY = random(0, 600); shotPosY = random(0, height);
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0)); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
} }
if (nextAttack == 5) { if (nextAttack == 5) {
shotPosX = random(0, 1000); shotPosX = random(0, width);
shotPosY = 0; shotPosY = 0;
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 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)); bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved, 0));
} }
if (!(patern == 2)) { if (!(patern == 2)) {
bossPosX = 500; bossPosX = width / 2;
bossPosY = 100; bossPosY = 100;
} }
if (patern == 3) { if (patern == 3) {