Skip to content

Commit

Permalink
Merge branch 'implementation' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
meronbrouwer committed Dec 15, 2023
2 parents d69e04b + 779b2f5 commit 274a18f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ a random location:

```java
@Override
public void onCollision(Collider collidingObject){
public void onCollision(List<Collider> collidingObject){
setAnchorLocation(
new Coordinate2D(new Random().nextInt((int)(getSceneWidth()
- getWidth())),
Expand Down Expand Up @@ -122,7 +122,7 @@ decreased, and the `healthText` changed:

```java
@Override
public void onCollision(Collider collidingObject){
public void onCollision(List<Collider> collidingObject){
setAnchorLocation(new Coordinate2D(
new Random().nextInt((int)(getSceneWidth()-getWidth())),
new Random().nextInt((int)(getSceneHeight()-getHeight())))
Expand Down
26 changes: 19 additions & 7 deletions docs/more-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ the following way:

```java
@Override
public void onCollision(Collider collidingObject){
public void onCollision(List<Collider> collidingObject){
var popSound = new SoundClip("audio/pop.mp3");
popSound.play();

Expand Down Expand Up @@ -217,18 +217,30 @@ handler for collisions on Hanny in the following way:

```java
@Override
public void onCollision(Collider collidingObject){
if (collidingObject instanceof AirBubble){
public void onCollision(List<Collider> collidingObject) {
var airBubbleCollision = false;
var enemyCollision = false;

for (Collider collider : collidingObject) {
if (collider instanceof AirBubble) {
airBubbleCollision = true;
} else {
enemyCollision = true;
}
}

if (airBubbleCollision) {
bubblesPoppedText.setText(++bubblesPopped);
} else {
}
if (enemyCollision) {
healthText.setText(--health);

if (health == 0){
if (health == 0) {
this.waterworld.setActiveScene(2);
} else {
setAnchorLocation(new Coordinate2D(
new Random().nextInt((int)(getSceneWidth() - getWidth())),
new Random().nextInt((int)(getSceneHeight() - getHeight()))));
new Random().nextInt((int) (getSceneWidth() - getWidth())),
new Random().nextInt((int) (getSceneHeight() - getHeight()))));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<groupId>com.github.han-yaeger</groupId>
<artifactId>tutorial</artifactId>
<version>2021.2022.1</version>
<version>2023.2024</version>

<name>Yaeger tutorial: Waterworld</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>16</java.version>
<java.version>21</java.version>
</properties>

<build>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.github.han-yaeger</groupId>
<artifactId>yaeger</artifactId>
<version>2021.2022.3</version>
<version>2023.2024</version>
</dependency>
</dependencies>
</project>
25 changes: 19 additions & 6 deletions src/main/java/com/github/hanyaeger/tutorial/entities/Bubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.github.hanyaeger.api.media.SoundClip;
import com.github.hanyaeger.api.scenes.SceneBorder;
import com.github.hanyaeger.tutorial.entities.map.Coral;
import com.github.hanyaeger.tutorial.entities.swordfish.HitBox;
import com.github.hanyaeger.tutorial.entities.swordfish.SwordFish;

import java.util.List;

public abstract class Bubble extends DynamicCircleEntity implements Collided, Collider, SceneBorderCrossingWatcher {

Expand All @@ -22,15 +26,24 @@ public Bubble(Coordinate2D initialLocation, double speed) {
}

@Override
public void onCollision(Collider collidingObject) {
if (collidingObject instanceof Coral) {
return;
public void onCollision(List<Collider> collidingObject) {
var shouldPop = false;

for (Collider collider : collidingObject) {
if (collider instanceof Sharky ||
collider instanceof Hanny ||
collider instanceof HitBox) {
shouldPop = true;
break;
}
}
if (shouldPop) {

var popSound = new SoundClip("audio/pop.mp3");
popSound.play();
var popSound = new SoundClip("audio/pop.mp3");
popSound.play();

remove();
remove();
}
}

@Override
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/github/hanyaeger/tutorial/entities/Hanny.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.hanyaeger.tutorial.entities.text.HealthText;
import javafx.scene.input.KeyCode;

import java.util.List;
import java.util.Random;
import java.util.Set;

Expand Down Expand Up @@ -52,12 +53,28 @@ public void onPressedKeysChange(Set<KeyCode> pressedKeys) {
}

@Override
public void onCollision(Collider collidingObject) {
if (collidingObject instanceof Coral) {
public void onCollision(List<Collider> collidingObject) {
var coralCollision = false;
var airBubbleCollision = false;
var enemyCollision = false;

for (Collider collider : collidingObject) {
if (collider instanceof Coral) {
coralCollision = true;
} else if (collider instanceof AirBubble) {
airBubbleCollision = true;
} else {
enemyCollision = true;
}
}

if (coralCollision) {
setSpeed(0);
} else if (collidingObject instanceof AirBubble) {
}
if (airBubbleCollision) {
bubblesPoppedText.setText(++bubblesPopped);
} else {
}
if (enemyCollision) {
healthText.setText(--health);

if (health == 0) {
Expand Down

0 comments on commit 274a18f

Please sign in to comment.