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