diff --git a/web/game.js b/web/game.js index 1526cb0..bcbc1a2 100644 --- a/web/game.js +++ b/web/game.js @@ -46,6 +46,8 @@ let y4; let x5; let y5; let homescreenOn = false; +let chosen = false; + let bulletAmount = 10; //let myBullet = new bullet(); // the function setup() is called once when the page is loaded @@ -84,6 +86,7 @@ function life() { hasMoved = false; bullets = []; shot = false; + chosen = false; } } @@ -95,7 +98,7 @@ function movementCheck() { } } -function keyPressed() { +async function keyPressed() { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { playerPosX -= playerSpeed; } @@ -108,23 +111,15 @@ function keyPressed() { if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { 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; - } +function wait(waitTime) { + return new Promise(resolve => { + setTimeout(() => { + resolve(true); + }, waitTime); + }); } - async function Movementloop() { window.addEventListener('booleanArrayUpdated', function (event) { // 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() { if (shot == false || hit == true) { for (i = 0; i < bulletAmount; i++) { @@ -241,8 +250,10 @@ function randomAttackPattern() { } function spawnRandomBullet() { + if (chosen == false) { + randPatern(); + } - patern = random([1,2]); if (patern == 1) { nextAttack = random([1, 2, 3, 4, 5]); //text(nextAttack, 30, 50);