added particle effects and sounds
This commit is contained in:
@@ -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.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
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.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.coordinate.Vec;
|
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.instance.block.Block;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
// TODO: Sound Effects, Partikel und Info für Score
|
// TODO: Info für Score
|
||||||
|
|
||||||
class TurtleGame extends StatelessGame {
|
class TurtleGame extends StatelessGame {
|
||||||
private final int radius;
|
private final int radius;
|
||||||
@@ -28,6 +31,7 @@ class TurtleGame extends StatelessGame {
|
|||||||
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
|
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
|
||||||
private final ArrayList<Entity> snacks = new ArrayList<>();
|
private final ArrayList<Entity> snacks = new ArrayList<>();
|
||||||
private final ArrayList<Entity> bombs = new ArrayList<>();
|
private final ArrayList<Entity> bombs = new ArrayList<>();
|
||||||
|
private final Block snackBlock = Block.SUNFLOWER.withProperty("half", "upper");
|
||||||
private double speed;
|
private double speed;
|
||||||
private final double maxSpeedIncrease;
|
private final double maxSpeedIncrease;
|
||||||
|
|
||||||
@@ -72,38 +76,52 @@ class TurtleGame extends StatelessGame {
|
|||||||
Vec targetDirection = direction.withY(0).normalize().mul(this.speed);
|
Vec targetDirection = direction.withY(0).normalize().mul(this.speed);
|
||||||
turtle.setVelocity(targetDirection);
|
turtle.setVelocity(targetDirection);
|
||||||
|
|
||||||
List<Entity> hitSnacks = this.snacks.stream()
|
this.snacks.stream()
|
||||||
.filter(snack -> snack.getBoundingBox().intersectBox(turtle.getPosition().sub(snack.getPosition()), turtle.getBoundingBox()))
|
.filter(snack -> snack.getBoundingBox().intersectBox(turtle.getPosition().sub(snack.getPosition()), turtle.getBoundingBox()))
|
||||||
.toList();
|
.toList()
|
||||||
List<Entity> hitBombs = this.bombs.stream()
|
.forEach(snack -> {
|
||||||
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
|
this.eat(p, snack);
|
||||||
.toList();
|
|
||||||
|
|
||||||
hitSnacks.forEach(snack -> {
|
|
||||||
this.snacks.remove(snack);
|
|
||||||
snack.remove();
|
|
||||||
this.generateNewSnack();
|
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 -> {
|
this.bombs.stream()
|
||||||
p.setGameMode(GameMode.SPECTATOR);
|
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
|
||||||
p.setFlying(true);
|
.toList()
|
||||||
turtle.removePassenger(p);
|
.forEach(bomb -> {
|
||||||
turtle.remove();
|
this.explode(p, bomb);
|
||||||
turtle.kill();
|
|
||||||
this.bombs.remove(bomb);
|
|
||||||
bomb.remove();
|
|
||||||
this.generateNewBomb(2);
|
this.generateNewBomb(2);
|
||||||
this.getScore().insertResult(p, this.scoreMap.get(p));
|
|
||||||
this.speed += this.maxSpeedIncrease / this.getPlayers().size();
|
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
|
@Override
|
||||||
protected boolean onPlayerJoin(Player p) {
|
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) {
|
if(this.turtlePlayerMap.get(p) == null) {
|
||||||
EntityCreature turtle = new EntityCreature(EntityType.TURTLE);
|
EntityCreature turtle = new EntityCreature(EntityType.TURTLE);
|
||||||
this.turtlePlayerMap.put(p, turtle);
|
this.turtlePlayerMap.put(p, turtle);
|
||||||
@@ -147,7 +165,7 @@ class TurtleGame extends StatelessGame {
|
|||||||
private void generateNewSnack() {
|
private void generateNewSnack() {
|
||||||
Entity snack = new Entity(EntityType.FALLING_BLOCK);
|
Entity snack = new Entity(EntityType.FALLING_BLOCK);
|
||||||
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
|
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
|
||||||
meta.setBlock(Block.SUNFLOWER.withProperty("half", "upper"));
|
meta.setBlock(this.snackBlock.withProperty("half", "upper"));
|
||||||
snack.setInstance(this);
|
snack.setInstance(this);
|
||||||
Pos spawnPosition = this.newSpawnPosition(snack);
|
Pos spawnPosition = this.newSpawnPosition(snack);
|
||||||
if(spawnPosition == null) {
|
if(spawnPosition == null) {
|
||||||
|
Reference in New Issue
Block a user