This commit is contained in:
Baipyrus 2022-08-16 10:02:18 +02:00
parent 402fe7e3bc
commit 945d1ae961
4 changed files with 35 additions and 18 deletions

View File

@ -10,7 +10,7 @@ PVector intersect(PVector A, PVector B, PVector C, PVector D) {
}
// https://math.stackexchange.com/questions/65503/point-reflection-over-a-line
boolean reflect(Projectile p, Wall w) {
void reflect(Projectile p, Wall w) {
// Position -> Next : A -> B
// Wall.start -> Wall.end : C -> D
final PVector A = p.position.copy();
@ -37,8 +37,5 @@ boolean reflect(Projectile p, Wall w) {
PVector newVelocity = PVector.sub(E, I);
newVelocity.setMag(p.velocity.mag());
p.velocity = newVelocity.copy();
return true;
}
return false;
}

View File

@ -17,6 +17,14 @@ class Projectile {
for (int i = 0; i < walls.size(); i++)
reflect(this, walls.get(i));
// Reflect any other projectile across this projectile's path
// for (int j = 0; j < projectiles.size(); j++) {
// Projectile A = projectiles.get(j);
// if (A != this) {
// Wall B = new Wall(position, next);
// reflect(A, B);
// }
// }
position = next.copy();
}

View File

@ -10,6 +10,8 @@ class Wall {
stroke(255);
fill(255);
line(start.x, start.y, end.x, end.y);
stroke(0,0,255);
fill(0,0,255);
ellipse(start.x, start.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
ellipse(end.x, end.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
}

View File

@ -1,4 +1,5 @@
final int SHOOTING_COOLDOWN = 1;
final float BALL_AMOUNT = 5000;
final int SHOOTING_COOLDOWN = 10;
final float PROJECTILE_RADIUS = 10;
final float VELOCITY_MAGNITUDE = 2;
final float HEADING_LINE_LENGTH = 50;
@ -16,7 +17,7 @@ boolean dragType = false;
PVector userPosition, userVelocity;
void setup() {
fullScreen();
fullScreen(P3D);
mouse = new PVector(width, height/2);
@ -57,17 +58,25 @@ void setup() {
new PVector(100, 100)
));
final PVector center = new PVector(width/2, height/2);
for (float a = 0; a < TWO_PI; a+=0.01) {
PVector v = new PVector(
cos(a) * HEADING_LINE_LENGTH,
sin(a) * HEADING_LINE_LENGTH
);
projectiles.add(new Projectile(
PVector.add(center, v),
PVector.mult(PVector.div(v, v.mag()), VELOCITY_MAGNITUDE)
));
}
// for (int i = 0; i < 20; i++) {
// walls.add(new Wall(
// new PVector(random(width), random(height)),
// new PVector(random(width), random(height))
// ));
// }
// final PVector center = new PVector(width/2, height/2);
// final float INCREMENT = TWO_PI / BALL_AMOUNT;
// for (float a = 0; a < TWO_PI; a+=INCREMENT) {
// PVector v = new PVector(
// cos(a) * HEADING_LINE_LENGTH,
// sin(a) * HEADING_LINE_LENGTH
// );
// projectiles.add(new Projectile(
// PVector.add(center, v),
// PVector.mult(PVector.div(v, v.mag()), VELOCITY_MAGNITUDE)
// ));
// }
}
void draw() {
@ -82,7 +91,8 @@ void draw() {
p.move();
}
mouse = new PVector(width, height / 2);
// mouse = new PVector(width, height / 2);
mouse = new PVector(mouseX, mouseY);
stroke(255,0,0);
fill(255,0,0);
ellipse(userPosition.x, userPosition.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);