added wait function + delay between random patern
This commit is contained in:
41
web/game.js
41
web/game.js
@@ -45,6 +45,7 @@ let x4;
|
|||||||
let y4;
|
let y4;
|
||||||
let x5;
|
let x5;
|
||||||
let y5;
|
let y5;
|
||||||
|
let chosen = false;
|
||||||
|
|
||||||
let bulletAmount = 10;
|
let bulletAmount = 10;
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ function life() {
|
|||||||
hasMoved = false;
|
hasMoved = false;
|
||||||
bullets = [];
|
bullets = [];
|
||||||
shot = false;
|
shot = false;
|
||||||
|
chosen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +97,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 +110,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
|
||||||
@@ -205,6 +199,19 @@ function draw() {
|
|||||||
bullets = bullets.filter(bullet => !bullet.hit);
|
bullets = bullets.filter(bullet => !bullet.hit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
@@ -215,8 +222,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);
|
||||||
|
Reference in New Issue
Block a user