diff --git a/Logic.pde b/Logic.pde index a7d960a..3a6b705 100644 --- a/Logic.pde +++ b/Logic.pde @@ -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; } diff --git a/Projectile.pde b/Projectile.pde index 6745666..a0edac0 100644 --- a/Projectile.pde +++ b/Projectile.pde @@ -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(); } diff --git a/Wall.pde b/Wall.pde index 8191ab3..6c1a851 100644 --- a/Wall.pde +++ b/Wall.pde @@ -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); } diff --git a/reflectingProjectiles.pde b/reflectingProjectiles.pde index 9426dba..991a0e2 100644 --- a/reflectingProjectiles.pde +++ b/reflectingProjectiles.pde @@ -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);