added player radius for correct collision

This commit is contained in:
Mees Roelofsz
2024-01-19 10:16:37 +01:00
parent 5fa2f1e68a
commit f5f9efc137

View File

@@ -32,7 +32,7 @@ class bullet {
pop(); pop();
} }
update(targetx, targety, hasMoved) { update(targetx, targety, hasMoved, radius) {
// keeps the projetile updated so hit collision can be checked // keeps the projetile updated so hit collision can be checked
this.targetx = targetx; this.targetx = targetx;
this.targety = targety; this.targety = targety;
@@ -43,7 +43,7 @@ class bullet {
let shot = true; let shot = true;
let travelled = false; let travelled = false;
// check if the projectile has hit the player // check if the projectile has hit the player
if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius) { if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius + radius) {
hit = true; hit = true;
shot = false; shot = false;
// if the projectile has hit the player and the player has lives left, remove a life // if the projectile has hit the player and the player has lives left, remove a life