added timer and better hit registration
This commit is contained in:
32
web/game.js
32
web/game.js
@@ -29,6 +29,7 @@ let predictiveBounceX;
|
||||
let predictiveBounceY;
|
||||
let bullets = [];
|
||||
let direction;
|
||||
let framerate = 120;
|
||||
|
||||
let time = 0;
|
||||
|
||||
@@ -38,7 +39,7 @@ function setup() {
|
||||
// create a canvas element and append it to the body
|
||||
|
||||
createCanvas(width, height);
|
||||
frameRate(120);
|
||||
frameRate(framerate);
|
||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed);
|
||||
|
||||
// disable the outline of shapes
|
||||
@@ -46,9 +47,11 @@ function setup() {
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function score() {
|
||||
while (true) {
|
||||
time += 1;
|
||||
time += 1 / framerate;
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +74,7 @@ function life() {
|
||||
time = 0;
|
||||
bounceX = bossPosX;
|
||||
bounceY = bossPosY;
|
||||
hit = false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -167,13 +170,8 @@ function draw() {
|
||||
textAlign(LEFT);
|
||||
text(time, 10, 20);
|
||||
|
||||
if (shot == false || hit == true) {
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
}
|
||||
|
||||
randomAttackPattern()
|
||||
|
||||
bullets.forEach(myBullet => {
|
||||
//zolang mybullet bestaat blijft hij drawen en updaten
|
||||
@@ -181,16 +179,22 @@ function draw() {
|
||||
myBullet.draw();
|
||||
});
|
||||
//blijf de bullet tekenen zolang hit false is
|
||||
bullets = bullets.filter(bullet => {
|
||||
const { hit, shot } = bullet.update(playerPosX, playerPosY);
|
||||
bullet.draw();
|
||||
return !hit; // als hit true is dan wordt de bullet verwijderd
|
||||
});
|
||||
bullets = bullets.filter(bullet => !bullet.hit);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function randomAttackPattern(){
|
||||
if (shot == false || hit == true) {
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
spawnRandomBullet()
|
||||
}
|
||||
}
|
||||
|
||||
function spawnRandomBullet(){
|
||||
|
||||
let patern = random([1,2]);
|
||||
if (patern == 1) {
|
||||
nextAttack = random([1, 2, 3, 4]);
|
||||
|
Reference in New Issue
Block a user