heb angle toegevoegd aan basicbullets+ raar patern

This commit is contained in:
Mees Roelofsz
2023-11-30 21:49:56 +01:00
parent 68d9ecba9e
commit e98ce2415d
2 changed files with 7 additions and 5 deletions

View File

@@ -235,10 +235,9 @@ function spawnRandomBullet(){
shotPosY = 100;
angle = 0;
// changing the angle of the bullets
for (let i = 0; i < 180; i++) {
let angleChange = map(i, 0, 50, 0, 360); // Example: linear change
bullets.push(new bullet(0, angle + angleChange, radius, shotSpeed, shotPosX, shotPosY, hasMoved));
// angle += 360 / 50;
for (let i = 0; i < 140; i++) {
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, angle, shotPosX, shotPosY, hasMoved));
angle += 360 / 50;
}
}

View File

@@ -1,8 +1,9 @@
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) {
constructor(targetx, targety, radius, speed, angle) {
//"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.angle = radians(angle);
this.targetx = targetx;
this.targety = targety;
this.x = 500;
@@ -23,6 +24,8 @@ class bullet {
this.direction = createVector(this.targetx - this.projectile.x, this.targety - this.projectile.y);
this.direction.normalize();
this.direction.rotate(this.angle);
}