Skip to content

Commit

Permalink
fix edge detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebarkmin committed Dec 29, 2024
1 parent e7f7a31 commit 3b548ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ index: 4
lang: en
---

## 4.15.1

- 🐛 Fix: Edge detection not working correctly.

## 4.15.0

- 🚀 Feat: All methods return a color now return a Color object.
Expand Down
2 changes: 1 addition & 1 deletion resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ author.url=https://openpatch.org
# This is NOT a direct link to where to download it.

library.url=https://github.com/openpatch/scratch-for-java
library.version=4.15.0
library.version=4.15.1


# Set the category (or categories) of your Library from the following list:
Expand Down
4 changes: 4 additions & 0 deletions src/org/openpatch/scratch/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,16 @@ public void ifOnEdgeBounce() {

if (h.intersects(this.stage.leftBorder)) {
this.setDirection(-this.getDirection());
this.setX(-this.stage.getWidth() / 2 + this.getWidth() / 2);
} else if (h.intersects(this.stage.rightBorder)) {
this.setDirection(-this.getDirection());
this.setX(this.stage.getWidth() / 2 - this.getWidth() / 2);
} else if (h.intersects(this.stage.topBorder)) {
this.setDirection(-this.getDirection() - 180);
this.setY(this.stage.getHeight() / 2 - this.getHeight() / 2);
} else if (h.intersects(this.stage.bottomBorder)) {
this.setDirection(-this.getDirection() - 180);
this.setY(-this.stage.getHeight() / 2 + this.getHeight() / 2);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/org/openpatch/scratch/Stage.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ public Stage(int width, final int height, boolean fullScreen, String assets) {
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2);
this.rightBorder = new Hitbox(p);

p = new Polygon();
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2);
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2 + 5);
p.addPoint(this.getWidth() / 2, this.getHeight() / 2 + 5);
p.addPoint(this.getWidth() / 2, this.getHeight() / 2);
this.topBorder = new Hitbox(p);

p = new Polygon();
p.addPoint(-this.getWidth() / 2, -this.getHeight() / 2);
p.addPoint(-this.getWidth() / 2, -this.getHeight() / 2 - 5);
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2 - 5);
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2);
this.topBorder = new Hitbox(p);

p = new Polygon();
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2);
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2 + 5);
p.addPoint(this.getWidth() / 2, this.getHeight() / 2 + 5);
p.addPoint(this.getWidth() / 2, this.getHeight() / 2);
this.bottomBorder = new Hitbox(p);
}

Expand Down

0 comments on commit 3b548ee

Please sign in to comment.