fixed timer, cleanup junk and improved bullets

This commit is contained in:
Sam
2023-11-30 15:02:24 +01:00
parent d703a82a7f
commit 559621835f
2 changed files with 44 additions and 60 deletions

View File

@@ -22,6 +22,9 @@ let hit = false;
let shotPosX;
let shotPosY;
let initialPlayerPosX = playerPosX;
let initialPlayerPosY = playerPosY;
let nextAttack;
let bounceX = bossPosX;
let bounceY = bossPosY;
@@ -30,7 +33,7 @@ let predictiveBounceY;
let bullets = [];
let direction;
let framerate = 120;
let hasMoved = false;
let time = 0;
//let myBullet = new bullet();
@@ -40,7 +43,6 @@ function setup() {
createCanvas(width, height);
frameRate(framerate);
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed);
// disable the outline of shapes
Movementloop()
@@ -48,21 +50,13 @@ function setup() {
}
async function score() {
while (true) {
function score() {
time += 1 / framerate;
await sleep(1000);
}
}
function life() {
textAlign(CENTER);
text(lives, 500, 20);
if (hit == true) {
hit = false;
lives -= 1;
}
if (lives == 0) {
fill(255, 0, 0);
textSize(40);
@@ -79,6 +73,12 @@ function life() {
}
}
function movementCheck() {
if (playerPosX != initialPlayerPosX && playerPosY != initialPlayerPosY) {
hasMoved = true;
}
}
function keyPressed() {
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
playerPosX -= playerSpeed;
@@ -161,14 +161,14 @@ function draw() {
// draw player
fill(0, 255, 255)
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
movementCheck()
// draw boss
fill(255, 165, 0)
circle(500, 100, 50);
score();
textAlign(LEFT);
text(time, 10, 20);
text(int(time), 10, 20);
randomAttackPattern()
@@ -186,6 +186,7 @@ function draw() {
function randomAttackPattern(){
if (shot == false || hit == true) {
spawnRandomBullet()
spawnRandomBullet()
spawnRandomBullet()
@@ -202,29 +203,29 @@ function spawnRandomBullet(){
if (nextAttack == 1) {
shotPosX = 500;
shotPosY = 100;
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
}
if (nextAttack == 2) {
shotPosX = random(0, 1000);
shotPosY = 600;
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
}
if (nextAttack == 3) {
shotPosX = 0;
shotPosY = random(0, 600);
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
}
if (nextAttack == 4) {
shotPosX = 1000;
shotPosY = random(0, 600);
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
}
}
if (patern == 2) {
shotPosX = bounceX;
shotPosY = bounceY;
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
}
}