clean up
This commit is contained in:
parent
402fe7e3bc
commit
945d1ae961
|
@ -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
|
// 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
|
// Position -> Next : A -> B
|
||||||
// Wall.start -> Wall.end : C -> D
|
// Wall.start -> Wall.end : C -> D
|
||||||
final PVector A = p.position.copy();
|
final PVector A = p.position.copy();
|
||||||
|
@ -37,8 +37,5 @@ boolean reflect(Projectile p, Wall w) {
|
||||||
PVector newVelocity = PVector.sub(E, I);
|
PVector newVelocity = PVector.sub(E, I);
|
||||||
newVelocity.setMag(p.velocity.mag());
|
newVelocity.setMag(p.velocity.mag());
|
||||||
p.velocity = newVelocity.copy();
|
p.velocity = newVelocity.copy();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,14 @@ class Projectile {
|
||||||
for (int i = 0; i < walls.size(); i++)
|
for (int i = 0; i < walls.size(); i++)
|
||||||
reflect(this, walls.get(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();
|
position = next.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
Wall.pde
2
Wall.pde
|
@ -10,6 +10,8 @@ class Wall {
|
||||||
stroke(255);
|
stroke(255);
|
||||||
fill(255);
|
fill(255);
|
||||||
line(start.x, start.y, end.x, end.y);
|
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(start.x, start.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
||||||
ellipse(end.x, end.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
ellipse(end.x, end.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 PROJECTILE_RADIUS = 10;
|
||||||
final float VELOCITY_MAGNITUDE = 2;
|
final float VELOCITY_MAGNITUDE = 2;
|
||||||
final float HEADING_LINE_LENGTH = 50;
|
final float HEADING_LINE_LENGTH = 50;
|
||||||
|
@ -16,7 +17,7 @@ boolean dragType = false;
|
||||||
PVector userPosition, userVelocity;
|
PVector userPosition, userVelocity;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
fullScreen();
|
fullScreen(P3D);
|
||||||
|
|
||||||
mouse = new PVector(width, height/2);
|
mouse = new PVector(width, height/2);
|
||||||
|
|
||||||
|
@ -57,17 +58,25 @@ void setup() {
|
||||||
new PVector(100, 100)
|
new PVector(100, 100)
|
||||||
));
|
));
|
||||||
|
|
||||||
final PVector center = new PVector(width/2, height/2);
|
// for (int i = 0; i < 20; i++) {
|
||||||
for (float a = 0; a < TWO_PI; a+=0.01) {
|
// walls.add(new Wall(
|
||||||
PVector v = new PVector(
|
// new PVector(random(width), random(height)),
|
||||||
cos(a) * HEADING_LINE_LENGTH,
|
// new PVector(random(width), random(height))
|
||||||
sin(a) * HEADING_LINE_LENGTH
|
// ));
|
||||||
);
|
// }
|
||||||
projectiles.add(new Projectile(
|
|
||||||
PVector.add(center, v),
|
// final PVector center = new PVector(width/2, height/2);
|
||||||
PVector.mult(PVector.div(v, v.mag()), VELOCITY_MAGNITUDE)
|
// 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() {
|
void draw() {
|
||||||
|
@ -82,7 +91,8 @@ void draw() {
|
||||||
p.move();
|
p.move();
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse = new PVector(width, height / 2);
|
// mouse = new PVector(width, height / 2);
|
||||||
|
mouse = new PVector(mouseX, mouseY);
|
||||||
stroke(255,0,0);
|
stroke(255,0,0);
|
||||||
fill(255,0,0);
|
fill(255,0,0);
|
||||||
ellipse(userPosition.x, userPosition.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
ellipse(userPosition.x, userPosition.y, PROJECTILE_RADIUS*2, PROJECTILE_RADIUS*2);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user