added particle effects and sounds

This commit is contained in:
2025-10-04 15:39:19 +02:00
parent 382d850605
commit 2a6f2f2a44

View File

@@ -3,7 +3,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.PointsWinScore;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.sound.Sound;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
@@ -14,13 +14,16 @@ import net.minestom.server.event.player.PlayerTickEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle;
import net.minestom.server.sound.SoundEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.CompletableFuture;
// TODO: Sound Effects, Partikel und Info für Score
// TODO: Info für Score
class TurtleGame extends StatelessGame {
private final int radius;
@@ -28,6 +31,7 @@ class TurtleGame extends StatelessGame {
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
private final ArrayList<Entity> snacks = new ArrayList<>();
private final ArrayList<Entity> bombs = new ArrayList<>();
private final Block snackBlock = Block.SUNFLOWER.withProperty("half", "upper");
private double speed;
private final double maxSpeedIncrease;
@@ -72,38 +76,52 @@ class TurtleGame extends StatelessGame {
Vec targetDirection = direction.withY(0).normalize().mul(this.speed);
turtle.setVelocity(targetDirection);
List<Entity> hitSnacks = this.snacks.stream()
this.snacks.stream()
.filter(snack -> snack.getBoundingBox().intersectBox(turtle.getPosition().sub(snack.getPosition()), turtle.getBoundingBox()))
.toList();
List<Entity> hitBombs = this.bombs.stream()
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
.toList();
hitSnacks.forEach(snack -> {
this.snacks.remove(snack);
snack.remove();
.toList()
.forEach(snack -> {
this.eat(p, snack);
this.generateNewSnack();
this.scoreMap.put(p, this.scoreMap.get(p) + 1);
if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 3 == 0) this.generateNewBomb();
});
hitBombs.forEach(bomb -> {
p.setGameMode(GameMode.SPECTATOR);
p.setFlying(true);
turtle.removePassenger(p);
turtle.remove();
turtle.kill();
this.bombs.remove(bomb);
bomb.remove();
this.bombs.stream()
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
.toList()
.forEach(bomb -> {
this.explode(p, bomb);
this.generateNewBomb(2);
this.getScore().insertResult(p, this.scoreMap.get(p));
this.speed += this.maxSpeedIncrease / this.getPlayers().size();
});
}
}
protected void eat(Player p, Entity snack) {
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EAT, Sound.Source.MASTER, 1f, 1f), snack.getPosition());
Material snackMaterial = this.snackBlock.registry().material();
if(snackMaterial == null) snackMaterial = Material.DIRT;
p.sendPacket(new ParticlePacket(Particle.ITEM.withItem(ItemStack.of(snackMaterial)), p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8));
this.snacks.remove(snack);
snack.remove();
this.scoreMap.put(p, this.scoreMap.get(p) + 1);
}
protected void explode(Player p, Entity bomb) {
EntityCreature turtle = this.turtlePlayerMap.get(p);
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.MASTER, 2f, 1f), bomb.getPosition());
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.MASTER, 2f, 1f), bomb.getPosition());
p.sendPacket(new ParticlePacket(Particle.EXPLOSION, p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8));
p.setGameMode(GameMode.SPECTATOR);
p.setFlying(true);
turtle.removePassenger(p);
turtle.remove();
turtle.kill();
this.getScore().insertResult(p, this.scoreMap.get(p));
this.bombs.remove(bomb);
bomb.remove();
}
@Override
protected boolean onPlayerJoin(Player p) {
p.getInventory().setItemStack(0, ItemStack.builder(Material.BARRIER).customName(Component.text("Reset Snack")).build());
if(this.turtlePlayerMap.get(p) == null) {
EntityCreature turtle = new EntityCreature(EntityType.TURTLE);
this.turtlePlayerMap.put(p, turtle);
@@ -147,7 +165,7 @@ class TurtleGame extends StatelessGame {
private void generateNewSnack() {
Entity snack = new Entity(EntityType.FALLING_BLOCK);
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
meta.setBlock(Block.SUNFLOWER.withProperty("half", "upper"));
meta.setBlock(this.snackBlock.withProperty("half", "upper"));
snack.setInstance(this);
Pos spawnPosition = this.newSpawnPosition(snack);
if(spawnPosition == null) {