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