Updated webdev

This commit is contained in:
sam
2023-11-28 13:18:36 +01:00
parent e47ec307b7
commit 8a8353b645
3 changed files with 61 additions and 1 deletions

42
webdev/js/basicbullet.js Normal file
View File

@@ -0,0 +1,42 @@
class bullet {
//Een constructor voert eerst de code uit die er in staat voordat de rest van de class wordt uitgevoerd.
constructor(targetx, targety, radius, speed) {
//"This" moet gebruikt worden om de variabelen aan te maken in de class en het zorgt er voor dat de variabelen niet alleen in de constructor gebruikt kunnen worden,
//maar ook in de rest van de class
this.x = targetx;
this.y = targety;
this.radius = radius;
this.speed = speed;
// Set the initial position of the projectile to the player's position
let projectile = createVector(shotPosX, shotPosY);
x = directionX;
y = directionY;
// Calculate the initial direction
direction = createVector(targetX - projectile.x, targetY - projectile.y);
direction.normalize();
}
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.
fill(255, 0, 0);
circle(500, 500, 5);
projectile.add(p5.Vector.mult(direction, shotSpeed));
if (dist(projectile.x, projectile.y, directionX, directionY) <= radius) {
hit = true;
}
else if (projectile.x < 0 - 10 || projectile.x > width + 10 || projectile.y < 0 - 10 || projectile.y > height + 10) {
bounceX = projectile.x;
bounceY = projectile.y;
shot = false;
}
}
}