Merge branch 'main' of https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-2/cuujooceevii61
This commit is contained in:
41
web/game.js
41
web/game.js
@@ -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,22 +111,14 @@ 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) {
|
||||||
startTime = time;
|
return new Promise(resolve => {
|
||||||
if (startTime + waitTime > time){
|
setTimeout(() => {
|
||||||
return true;
|
resolve(true);
|
||||||
|
}, waitTime);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function Movementloop() {
|
async function Movementloop() {
|
||||||
window.addEventListener('booleanArrayUpdated', function (event) {
|
window.addEventListener('booleanArrayUpdated', function (event) {
|
||||||
@@ -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);
|
||||||
|
Reference in New Issue
Block a user