From 78c95b29f79fe15306eed0d596121cf31751417d Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Nov 2023 22:38:17 +0100 Subject: [PATCH] Removed off screen bullets that was causing lag --- web/game.js | 7 ++++++- web/js/basicbullet.js | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/game.js b/web/game.js index c9b784b..7872ce4 100644 --- a/web/game.js +++ b/web/game.js @@ -178,8 +178,13 @@ function draw() { bullets.forEach(myBullet => { //zolang mybullet bestaat blijft hij drawen en updaten - ({ hit, shot } = myBullet.update(playerPosX, playerPosY)); + ({ hit, shot, isOffScreen } = myBullet.update(playerPosX, playerPosY)); myBullet.draw(); + + if (isOffScreen == true) { + myBullet.hit = true; + shot = false; + } }); //blijf de bullet tekenen zolang hit false is bullets = bullets.filter(bullet => !bullet.hit); diff --git a/web/js/basicbullet.js b/web/js/basicbullet.js index 3754c0a..f13b7c9 100644 --- a/web/js/basicbullet.js +++ b/web/js/basicbullet.js @@ -45,7 +45,9 @@ class bullet { } else if (this.projectile.x < 0 - 10 || this.projectile.x > width + 10 || this.projectile.y < 0 - 10 || this.projectile.y > height + 10) { shot = false; } + let isOffScreen = this.projectile.x < 0 || this.projectile.x > width || this.projectile.y < 0 || this.projectile.y > height; - return { hit, shot }; + + return { hit, shot, isOffScreen}; } } \ No newline at end of file