Skip to content

Commit 3b548ee

Browse files
committed
fix edge detection
1 parent e7f7a31 commit 3b548ee

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ index: 4
44
lang: en
55
---
66

7+
## 4.15.1
8+
9+
- 🐛 Fix: Edge detection not working correctly.
10+
711
## 4.15.0
812

913
- 🚀 Feat: All methods return a color now return a Color object.

resources/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ author.url=https://openpatch.org
4040
# This is NOT a direct link to where to download it.
4141

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

4545

4646
# Set the category (or categories) of your Library from the following list:

src/org/openpatch/scratch/Sprite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,16 @@ public void ifOnEdgeBounce() {
643643

644644
if (h.intersects(this.stage.leftBorder)) {
645645
this.setDirection(-this.getDirection());
646+
this.setX(-this.stage.getWidth() / 2 + this.getWidth() / 2);
646647
} else if (h.intersects(this.stage.rightBorder)) {
647648
this.setDirection(-this.getDirection());
649+
this.setX(this.stage.getWidth() / 2 - this.getWidth() / 2);
648650
} else if (h.intersects(this.stage.topBorder)) {
649651
this.setDirection(-this.getDirection() - 180);
652+
this.setY(this.stage.getHeight() / 2 - this.getHeight() / 2);
650653
} else if (h.intersects(this.stage.bottomBorder)) {
651654
this.setDirection(-this.getDirection() - 180);
655+
this.setY(-this.stage.getHeight() / 2 + this.getHeight() / 2);
652656
}
653657
}
654658

src/org/openpatch/scratch/Stage.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,18 @@ public Stage(int width, final int height, boolean fullScreen, String assets) {
200200
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2);
201201
this.rightBorder = new Hitbox(p);
202202

203-
p = new Polygon();
204-
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2);
205-
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2 + 5);
206-
p.addPoint(this.getWidth() / 2, this.getHeight() / 2 + 5);
207-
p.addPoint(this.getWidth() / 2, this.getHeight() / 2);
208-
this.topBorder = new Hitbox(p);
209-
210203
p = new Polygon();
211204
p.addPoint(-this.getWidth() / 2, -this.getHeight() / 2);
212205
p.addPoint(-this.getWidth() / 2, -this.getHeight() / 2 - 5);
213206
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2 - 5);
214207
p.addPoint(this.getWidth() / 2, -this.getHeight() / 2);
208+
this.topBorder = new Hitbox(p);
209+
210+
p = new Polygon();
211+
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2);
212+
p.addPoint(-this.getWidth() / 2, this.getHeight() / 2 + 5);
213+
p.addPoint(this.getWidth() / 2, this.getHeight() / 2 + 5);
214+
p.addPoint(this.getWidth() / 2, this.getHeight() / 2);
215215
this.bottomBorder = new Hitbox(p);
216216
}
217217

0 commit comments

Comments
 (0)