sam
2023-12-05 15:49:11 +01:00

View File

@@ -1,7 +1,7 @@
//--------------------Game-------------------- //--------------------Game--------------------
// Game variables // Game variables
const width = 1000; const width = 1260;
const height = 600; const height = 620;
// Player variables // Player variables
const playerSize = 10; const playerSize = 10;
@@ -12,9 +12,9 @@ let playerSpeed = 4;
let booleanArray = window.booleanArray; let booleanArray = window.booleanArray;
let lives = 1; let lives = 1;
let bossPosX = 500; 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;
@@ -75,7 +75,7 @@ function life() {
fill(255, 0, 0); fill(255, 0, 0);
textSize(40); textSize(40);
textAlign(CENTER); textAlign(CENTER);
text("Game Over", 500, 300); text("Game Over", width/2, height/2);
if (key == ' ') { if (key == ' ') {
lives = 1; lives = 1;
time = 0; time = 0;
@@ -110,8 +110,23 @@ function keyPressed() {
if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) {
playerPosY += playerSpeed; playerPosY += playerSpeed;
} }
if (key == 'e') {
// adding a quick movement button that moves you further in the direction your already moving
playerSpeed += 2;
wait(2);
} else {
playerSpeed = 4;
}
} }
function wait(waitTime){
startTime = time;
if (startTime + waitTime > time){
return true;
}
}
async function Movementloop() { async function Movementloop() {
window.addEventListener('booleanArrayUpdated', function (event) { window.addEventListener('booleanArrayUpdated', function (event) {
// event.detail contains the booleanArray // event.detail contains the booleanArray
@@ -174,8 +189,8 @@ function draw() {
circle(x4, y4, 50); circle(x4, y4, 50);
circle(x5, y5, 50); circle(x5, y5, 50);
} else { } else {
x2 = bossPosX; x2 = width / 2;
y2 = bossPosY; y2 = 100;
} }
bullets.forEach(myBullet => { bullets.forEach(myBullet => {
@@ -213,22 +228,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));
} }
@@ -251,7 +266,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) {