sam
2023-12-06 13:28:40 +01:00

View File

@@ -46,6 +46,8 @@ let y4;
let x5; let x5;
let y5; let y5;
let homescreenOn = false; let homescreenOn = false;
let chosen = false;
let bulletAmount = 10; let bulletAmount = 10;
//let myBullet = new bullet(); //let myBullet = new bullet();
// the function setup() is called once when the page is loaded // the function setup() is called once when the page is loaded
@@ -84,6 +86,7 @@ function life() {
hasMoved = false; hasMoved = false;
bullets = []; bullets = [];
shot = false; shot = false;
chosen = false;
} }
} }
@@ -95,7 +98,7 @@ function movementCheck() {
} }
} }
function keyPressed() { async function keyPressed() {
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
playerPosX -= playerSpeed; playerPosX -= playerSpeed;
} }
@@ -108,23 +111,15 @@ 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) {
function wait(waitTime){ return new Promise(resolve => {
startTime = time; setTimeout(() => {
if (startTime + waitTime > time){ resolve(true);
return true; }, waitTime);
} });
} }
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
@@ -232,6 +227,20 @@ function draw() {
} }
} }
async function randPatern () {
patern = random([1,2]);
chosen = true;
if (patern == 1) {
await wait(3000);
chosen = false;
}
if (patern == 2) {
await wait(5000);
chosen = false;
}
}
function randomAttackPattern() { function randomAttackPattern() {
if (shot == false || hit == true) { if (shot == false || hit == true) {
for (i = 0; i < bulletAmount; i++) { for (i = 0; i < bulletAmount; i++) {
@@ -241,8 +250,10 @@ function randomAttackPattern() {
} }
function spawnRandomBullet() { function spawnRandomBullet() {
if (chosen == false) {
randPatern();
}
patern = random([1,2]);
if (patern == 1) { if (patern == 1) {
nextAttack = random([1, 2, 3, 4, 5]); nextAttack = random([1, 2, 3, 4, 5]);
//text(nextAttack, 30, 50); //text(nextAttack, 30, 50);