put bullet direction into update

This commit is contained in:
sam
2023-11-28 16:00:01 +01:00
parent b8ddc4dc05
commit ee7f031775

View File

@@ -24,7 +24,6 @@ class bullet {
this.direction = createVector(this.targetX - this.projectile.x, this.targetY - this.projectile.y);
this.direction.normalize();
this.projectile.add(p5.Vector.mult(this.direction, this.speed));
}
@@ -32,11 +31,14 @@ class bullet {
draw() {
//push en pop zorgen er voor dat de code tussen push en pop een eigen canvas heeft. Dus dat er meerdere projectielen tegelijk kunnen zijn.
push();
fill(0, 255, 0);
circle(500, 500, this.radius);
pop();
// Set the initial position of the projectile to the player's position
this.projectile.add(p5.Vector.mult(this.direction, this.speed));
if (dist(this.projectile.x, this.projectile.y, this.directionX, this.directionY) <= this.radius) {
@@ -50,5 +52,10 @@ class bullet {
}
// // Move the projectile towards the movable circle
update() {
this.projectile.add(p5.Vector.mult(this.direction, this.speed));
}
}