Skip to content

Commit

Permalink
Updated checkEdge method
Browse files Browse the repository at this point in the history
  • Loading branch information
nbourre committed Aug 26, 2024
1 parent 4c503d5 commit 4a03bb3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions s02_forces_01/Mover.pde
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
class Mover extends GraphicObject {
float w = 25;
float h = 25;
float diameter = 25;
float radius = 13;

PVector tempLoc = new PVector();

void checkEdges() {
if (location.x < 0 || location.x > width) {
tempLoc.x = location.x;
tempLoc.y = location.y;

tempLoc.add(velocity);

if (tempLoc.x - radius < 0 || tempLoc.x + radius > width) {
velocity.x = -velocity.x;
}

if (location.y < 0 || location.y > height) {
if (tempLoc.y - radius < 0 || tempLoc.y + radius > height) {
velocity.y = -velocity.y;
}
}
Expand All @@ -30,7 +37,7 @@ class Mover extends GraphicObject {
stroke(strokeColor);
strokeWeight(strokeWeight);

ellipse(0, 0, w, h);
ellipse(0, 0, diameter, diameter);

popMatrix();
}
Expand Down

0 comments on commit 4a03bb3

Please sign in to comment.