Skip to content

Commit 2ffcc14

Browse files
committed
add stamp
1 parent 21f761e commit 2ffcc14

File tree

12 files changed

+348
-185
lines changed

12 files changed

+348
-185
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
2+
.idea
23
bin
34
tmp
45
distribution

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ index: 4
1212
- 🚀 Feat: Add goToMousePointer to the sprite class.
1313
- 🚀 Feat: Add goToRandomPosition to the sprite class.
1414
- 🚀 Feat: switchCostumes now also accepts an integer for switching to a specific index.
15+
- 🚀 Feat: Allow for custom sorting of sprites by providing a Comparator via the `setSorter`-method of the stage.
1516
- 🐛 Fix: Random.randomInt did not work correct.
1617

1718
## 3.9.0
-177 KB
Loading

resources/build.xml

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@
8888
<mkdir dir="${project.bin}" />
8989
<mkdir dir="${project.libs}" />
9090
<mkdir dir="${project.libs}/windows-amd64" />
91-
<mkdir dir="${project.libs}/macos-x86_64" />
92-
<mkdir dir="${project.libs}/macos-aarch64" />
91+
<mkdir dir="${project.libs}/macos-universal" />
9392
<mkdir dir="${project.libs}/linux-amd64" />
9493
<mkdir dir="${project.libs}/linux-arm" />
9594
<mkdir dir="${project.libs}/linux-aarch64" />
@@ -101,13 +100,12 @@
101100

102101
<echo message="download dependencies ..." />
103102

104-
105103
<property name="jogl.url"
106104
value="https://download.processing.org/jogl/v2.4.0-rc-20210111y" />
107105

108106
<get dest="${project.libs}" skipexisting="true" ignoreerrors="true">
109107
<url
110-
url="https://github.com/micycle1/processing-core-4/releases/download/4.2/core-4.2.jar" />
108+
url="https://github.com/micycle1/processing-core-4/releases/download/4.2.1/core-4.2.1.jar" />
111109
<url url="${jogl.url}/gluegen-rt.jar" />
112110
<url url="${jogl.url}/jogl-all.jar" />
113111
<url
@@ -123,45 +121,36 @@
123121
</get>
124122

125123
<get dest="${project.libs}/linux-amd64" skipexisting="true" ignoreerrors="true">
126-
<url
127-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-linux-amd64.jar" />
128-
<url
129-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-linux-amd64.jar" />
124+
<url url="${jogl.url}/gluegen-rt-natives-linux-amd64.jar" />
125+
<url url="${jogl.url}/jogl-all-natives-linux-amd64.jar" />
130126
</get>
131127

132128
<get dest="${project.libs}/linux-arm" skipexisting="true" ignoreerrors="true">
133129
<url
134-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-linux-arm.jar" />
130+
url="https://jogamp.org/deployment/v2.5.0/jar/gluegen-rt-natives-linux-armv6hf.jar" />
135131
<url
136-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-linux-arm.jar" />
132+
url="https://jogamp.org/deployment/v2.5.0/jar/jogl-all-natives-linux-armv6hf.jar" />
137133
</get>
138134

139135
<get dest="${project.libs}/linux-aarch64" skipexisting="true" ignoreerrors="true">
140136
<url
141-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-linux-aarch64.jar" />
137+
url="https://jogamp.org/deployment/v2.5.0/jar/gluegen-rt-natives-linux-aarch64.jar" />
142138
<url
143-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-linux-aarch64.jar" />
139+
url="https://jogamp.org/deployment/v2.5.0/jar/jogl-all-natives-linux-aarch64.jar" />
144140
</get>
145141

146142
<get dest="${project.libs}/windows-amd64" skipexisting="true" ignoreerrors="true">
147143
<url
148-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-windows-amd64.jar" />
144+
url="https://jogamp.org/deployment/v2.5.0/jar/gluegen-rt-natives-windows-amd64.jar" />
149145
<url
150-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-windows-amd64.jar" />
146+
url="https://jogamp.org/deployment/v2.5.0/jar/jogl-all-natives-windows-amd64.jar" />
151147
</get>
152148

153-
<get dest="${project.libs}/macos-x86_64" skipexisting="true" ignoreerrors="true">
149+
<get dest="${project.libs}/macos-universal" skipexisting="true" ignoreerrors="true">
154150
<url
155-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-macos-x86_64.jar" />
151+
url="https://jogamp.org/deployment/v2.5.0/jar/gluegen-rt-natives-macosx-universal.jar" />
156152
<url
157-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-macos-x86_64.jar" />
158-
</get>
159-
160-
<get dest="${project.libs}/macos-aarch64" skipexisting="true" ignoreerrors="true">
161-
<url
162-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/gluegen-rt-natives-macos-aarch64.jar" />
163-
<url
164-
url="https://download.processing.org/jogl/v2.4.0-rc-20210111y/jogl-all-natives-macos-aarch64.jar" />
153+
url="https://jogamp.org/deployment/v2.5.0/jar/jogl-all-natives-macosx-universal.jar" />
165154
</get>
166155

167156
<if>
@@ -308,24 +297,10 @@
308297
</jar>
309298

310299
<jar
311-
jarfile="${project.tmp}/${project.name}/${folder}/${project.jar.name}-macos-x86_64.jar"
300+
jarfile="${project.tmp}/${project.name}/${folder}/${project.jar.name}-macos-universal.jar"
312301
basedir="${project.bin}">
313302
<zipgroupfileset dir="${project.libs}" includes="*.jar" />
314-
<zipgroupfileset dir="${project.libs}/macos-x86_64" includes="*.jar" />
315-
<manifest>
316-
<attribute name="Class-Path" value="${project.libs}" />
317-
<!-- Information about the program itself -->
318-
<attribute name="Implementation-Vendor" value="${author.name}" />
319-
<attribute name="Implementation-Title" value="${project.prettyName}" />
320-
<attribute name="Implementation-Version" value="${library.version}" />
321-
</manifest>
322-
</jar>
323-
324-
<jar
325-
jarfile="${project.tmp}/${project.name}/${folder}/${project.jar.name}-macos-aarch64.jar"
326-
basedir="${project.bin}">
327-
<zipgroupfileset dir="${project.libs}" includes="*.jar" />
328-
<zipgroupfileset dir="${project.libs}/macos-aarch64" includes="*.jar" />
303+
<zipgroupfileset dir="${project.libs}/macos-universal" includes="*.jar" />
329304
<manifest>
330305
<attribute name="Class-Path" value="${project.libs}" />
331306
<!-- Information about the program itself -->
@@ -381,10 +356,7 @@
381356
file="${project.dist.version}/tmp/${project.name}/library/${project.jar.name}-linux-aarch64.jar"
382357
todir="${project.dist}" />
383358
<move
384-
file="${project.dist.version}/tmp/${project.name}/library/${project.jar.name}-macos-x86_64.jar"
385-
todir="${project.dist}" />
386-
<move
387-
file="${project.dist.version}/tmp/${project.name}/library/${project.jar.name}-macos-aarch64.jar"
359+
file="${project.dist.version}/tmp/${project.name}/library/${project.jar.name}-macos-universal.jar"
388360
todir="${project.dist}" />
389361

390362
<copy file="resources/index.html" todir="${project.dist}" />

src/org/openpatch/scratch/Sprite.java

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openpatch.scratch;
22

3-
import java.util.ArrayList;
3+
import java.util.List;
44
import java.util.concurrent.ConcurrentHashMap;
55
import java.util.concurrent.CopyOnWriteArrayList;
66

@@ -16,6 +16,7 @@
1616
import org.openpatch.scratch.internal.Drawable;
1717
import org.openpatch.scratch.internal.Image;
1818
import org.openpatch.scratch.internal.Sound;
19+
import org.openpatch.scratch.internal.Stamp;
1920

2021
import processing.event.KeyEvent;
2122
import processing.event.MouseEvent;
@@ -36,6 +37,7 @@ public class Sprite implements Drawable {
3637
private final ConcurrentHashMap<String, Timer> timer;
3738
private final Pen pen;
3839
private Hitbox hitbox;
40+
private boolean hitboxDisabled = false;
3941
private final Text text;
4042

4143
public Sprite() {
@@ -78,6 +80,8 @@ public Sprite(Sprite s) {
7880
this.pen = new Pen(s.pen);
7981
this.text = new Text(s.text);
8082
this.stage = s.stage;
83+
this.hitbox = s.hitbox;
84+
this.hitboxDisabled = s.hitboxDisabled;
8185
}
8286

8387
public void addedToStage(Stage stage) {
@@ -475,6 +479,9 @@ public void setOnEdgeBounce(boolean b) {
475479
}
476480

477481
public void ifOnEdgeBounce() {
482+
if (this.hitboxDisabled)
483+
return;
484+
478485
var h = this.getHitbox();
479486

480487
if (h.intersects(this.stage.leftBorder)) {
@@ -798,6 +805,8 @@ public void removeTimer(String name) {
798805
* @return true if touching
799806
*/
800807
public boolean isTouchingMousePointer() {
808+
if (this.hitboxDisabled)
809+
return false;
801810

802811
var bounds = this.getHitbox().getPolygon().getBounds();
803812
double topLeftCornerX = bounds.getMinX();
@@ -849,6 +858,8 @@ public boolean isTouchingMousePointer() {
849858
* @return true if outside
850859
*/
851860
public boolean isTouchingEdge() {
861+
if (this.hitboxDisabled)
862+
return false;
852863
var h = this.getHitbox();
853864
return h.intersects(this.stage.topBorder) || h.intersects(this.stage.bottomBorder)
854865
|| h.intersects(this.stage.leftBorder) || h.intersects(this.stage.rightBorder);
@@ -889,6 +900,14 @@ public void setHitbox(Hitbox hitbox) {
889900
this.hitbox = hitbox;
890901
}
891902

903+
public void disableHitbox() {
904+
this.hitboxDisabled = true;
905+
}
906+
907+
public void enableHitbox() {
908+
this.hitboxDisabled = false;
909+
}
910+
892911
public Hitbox getHitbox() {
893912
Image currentCostume = null;
894913
if (this.costumes.size() > this.getCurrentCostumeIndex()) {
@@ -955,37 +974,23 @@ public Hitbox getHitbox() {
955974
}
956975

957976
public boolean isTouchingSprite(Sprite sprite) {
958-
if (sprite == null || !sprite.show)
977+
if (sprite == null || !sprite.show || sprite.hitboxDisabled)
959978
return false;
960979
return this.getHitbox().intersects(sprite.getHitbox());
961980
}
962981

963982
public boolean isTouchingSprite(Class<? extends Sprite> c) {
964-
for (Drawable d : this.stage.drawables) {
965-
if (c.isInstance(d) && this.isTouchingSprite((Sprite) d)) {
966-
return true;
967-
}
968-
}
969-
return false;
983+
return this.stage.sprites.stream().filter(s -> c.isInstance(s) && this.isTouchingSprite(s)).findFirst().isPresent();
970984
}
971985

972-
public Sprite getTouchingSprite(Class<? extends Sprite> c) {
973-
for (Drawable d : this.stage.drawables) {
974-
if (c.isInstance(d) && this.isTouchingSprite((Sprite) d)) {
975-
return (Sprite) d;
976-
}
977-
}
978-
return null;
986+
public <T extends Sprite> T getTouchingSprite(Class<T> c) {
987+
return (T) this.stage.sprites.stream().filter(s -> c.isInstance(s) && this.isTouchingSprite(s)).findFirst()
988+
.orElse(null);
979989
}
980990

981-
public ArrayList<Sprite> getTouchingSprites(Class<? extends Sprite> c) {
982-
ArrayList<Sprite> sprites = new ArrayList<>();
983-
for (Drawable d : this.stage.drawables) {
984-
if (c.isInstance(d) && this.isTouchingSprite((Sprite) d)) {
985-
sprites.add((Sprite) d);
986-
}
987-
}
988-
return sprites;
991+
public <T extends Sprite> List<T> getTouchingSprites(Class<T> c) {
992+
return (List<T>) this.stage.sprites.stream().filter(s -> c.isInstance(s) && this.isTouchingSprite(s))
993+
.toList();
989994
}
990995

991996
/**
@@ -1212,16 +1217,25 @@ public void broadcast(String message) {
12121217
public void whenIReceive(String message) {
12131218
}
12141219

1215-
public void stamp() {
1220+
public void stampToBackground() {
12161221
if (this.costumes.size() > 0) {
1217-
this.costumes.get(this.currentCostume)
1218-
.draw(
1219-
this.size,
1220-
this.direction,
1221-
this.x,
1222-
this.y,
1223-
this.rotationStyle,
1224-
true);
1222+
var stamp = new Stamp(this.costumes.get(this.currentCostume),
1223+
this.direction,
1224+
this.x,
1225+
this.y,
1226+
this.rotationStyle);
1227+
this.stage.backgroundStamps.add(stamp);
1228+
}
1229+
}
1230+
1231+
public void stampToForeground() {
1232+
if (this.costumes.size() > 0) {
1233+
var stamp = new Stamp(this.costumes.get(this.currentCostume),
1234+
this.direction,
1235+
this.x,
1236+
this.y,
1237+
this.rotationStyle);
1238+
this.stage.foregroundStamps.add(stamp);
12251239
}
12261240
}
12271241

@@ -1236,7 +1250,9 @@ public void draw() {
12361250
}
12371251

12381252
if (Applet.getInstance().isDebug()) {
1239-
this.getHitbox().draw();
1253+
if (!this.hitboxDisabled) {
1254+
this.getHitbox().draw();
1255+
}
12401256
}
12411257
this.text.setPosition(
12421258
this.x + this.getWidth() * 0.9 / 2,

0 commit comments

Comments
 (0)