develop-turtleGame #6

Merged
Pupsi merged 32 commits from develop-turtleGame into develop 2025-10-15 20:21:27 +00:00
2 changed files with 14 additions and 44 deletions
Showing only changes of commit 75314748da - Show all commits
@@ -6,6 +6,7 @@ import eu.mhsl.minenet.minigames.score.PointsWinScore;
import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
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;
@@ -18,7 +19,6 @@ 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.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle; import net.minestom.server.particle.Particle;
import net.minestom.server.scoreboard.Sidebar;
import net.minestom.server.sound.SoundEvent; 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;
@@ -30,18 +30,15 @@ class TurtleGame extends StatelessGame {
private final int radius; private final int radius;
private final Map<Player, EntityCreature> turtlePlayerMap = new WeakHashMap<>(); private final Map<Player, EntityCreature> turtlePlayerMap = new WeakHashMap<>();
private final Map<Player, Integer> scoreMap = new WeakHashMap<>(); private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
private final Map<Player, Sidebar> sidebarMap = new HashMap<>();
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 final Block snackBlock = Block.SUNFLOWER.withProperty("half", "upper");
private double speed; private double speed;
private final double maxSpeedIncrease;
public TurtleGame(int radius, int startSpeed) { public TurtleGame(int radius, int startSpeed) {
super(Dimension.OVERWORLD.key, "Turtle Game", new PointsWinScore()); super(Dimension.OVERWORLD.key, "Turtle Game", new PointsWinScore());
this.radius = radius; this.radius = radius;
this.speed = startSpeed; this.speed = startSpeed;
this.maxSpeedIncrease = (double) this.radius / 4;
this.eventNode() this.eventNode()
.addListener(PlayerTickEvent.class, this::onPlayerTick); .addListener(PlayerTickEvent.class, this::onPlayerTick);
1
@@ -84,7 +81,10 @@ class TurtleGame extends StatelessGame {
.forEach(snack -> { .forEach(snack -> {
this.eat(p, snack); this.eat(p, snack);
this.generateNewSnack(); this.generateNewSnack();
if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 4 == 0) this.generateNewBomb(); if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 4 == 0) {
this.generateNewBomb();
this.speed += 0.4;
}
}); });
this.bombs.stream() this.bombs.stream()
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox())) .filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
@@ -92,10 +92,7 @@ class TurtleGame extends StatelessGame {
.forEach(bomb -> { .forEach(bomb -> {
this.explode(p, bomb); this.explode(p, bomb);
this.generateNewBomb(2); this.generateNewBomb(2);
this.speed += this.maxSpeedIncrease / this.getPlayers().size(); this.speed += 0.3;
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("1",
Component.text("Speed: ").color(NamedTextColor.BLUE)
.append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED))));
}); });
} }
} }
@@ -108,9 +105,7 @@ class TurtleGame extends StatelessGame {
this.snacks.remove(snack); this.snacks.remove(snack);
snack.remove(); snack.remove();
this.scoreMap.put(p, this.scoreMap.get(p) + 1); this.scoreMap.put(p, this.scoreMap.get(p) + 1);
this.sidebarMap.get(p).updateLineContent("0", p.setLevel(this.scoreMap.get(p));
Component.text("Score: ").color(NamedTextColor.GREEN)
.append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)));
} }
protected void explode(Player p, Entity bomb) { protected void explode(Player p, Entity bomb) {
1
@@ -126,9 +121,6 @@ class TurtleGame extends StatelessGame {
this.getScore().insertResult(p, this.scoreMap.get(p)); this.getScore().insertResult(p, this.scoreMap.get(p));
this.bombs.remove(bomb); this.bombs.remove(bomb);
bomb.remove(); bomb.remove();
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
} }
@Override @Override
@@ -138,33 +130,7 @@ class TurtleGame extends StatelessGame {
this.turtlePlayerMap.put(p, turtle); this.turtlePlayerMap.put(p, turtle);
} }
this.scoreMap.putIfAbsent(p, 0); this.scoreMap.putIfAbsent(p, 0);
this.sidebarMap.putIfAbsent(p, new Sidebar(Component.text("Info:").color(NamedTextColor.GOLD))); p.setLevel(this.scoreMap.get(p));
Sidebar sidebar = this.sidebarMap.get(p);
sidebar.createLine(new Sidebar.ScoreboardLine(
"0",
Component.text("Score: ").color(NamedTextColor.GREEN)
.append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)),
3,
Sidebar.NumberFormat.blank()
));
sidebar.createLine(new Sidebar.ScoreboardLine(
"1",
Component.text("Speed: ").color(NamedTextColor.BLUE)
.append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED)),
2,
Sidebar.NumberFormat.blank()
));
sidebar.createLine(new Sidebar.ScoreboardLine(
"2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED)),
1,
Sidebar.NumberFormat.blank()
));
sidebar.addViewer(p);
this.sidebarMap.values().forEach(bar -> bar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
EntityCreature turtle = this.turtlePlayerMap.get(p); EntityCreature turtle = this.turtlePlayerMap.get(p);
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> { MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
@@ -181,7 +147,6 @@ class TurtleGame extends StatelessGame {
protected void onPlayerLeave(Player p) { protected void onPlayerLeave(Player p) {
EntityCreature turtle = this.turtlePlayerMap.get(p); EntityCreature turtle = this.turtlePlayerMap.get(p);
turtle.remove(); turtle.remove();
this.sidebarMap.get(p).removeViewer(p);
} }
@Override @Override
@@ -205,6 +170,9 @@ class TurtleGame extends StatelessGame {
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(this.snackBlock.withProperty("half", "upper")); meta.setBlock(this.snackBlock.withProperty("half", "upper"));
meta.setCustomName(Component.text("Snack").color(NamedTextColor.WHITE));
meta.setCustomNameVisible(true);
meta.setHasGlowingEffect(true);
snack.setInstance(this); snack.setInstance(this);
Pos spawnPosition = this.newSpawnPosition(snack); Pos spawnPosition = this.newSpawnPosition(snack);
if(spawnPosition == null) { if(spawnPosition == null) {
2
@@ -225,6 +193,8 @@ class TurtleGame extends StatelessGame {
Entity bomb = new Entity(EntityType.FALLING_BLOCK); Entity bomb = new Entity(EntityType.FALLING_BLOCK);
FallingBlockMeta meta = (FallingBlockMeta) bomb.getEntityMeta(); FallingBlockMeta meta = (FallingBlockMeta) bomb.getEntityMeta();
meta.setBlock(Block.TNT); meta.setBlock(Block.TNT);
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
Pupsi marked this conversation as resolved Outdated
Outdated
Review

statt teleport direkt bei setInstance als zweiter Parameter die Position übergeben

statt teleport direkt bei setInstance als zweiter Parameter die Position übergeben
meta.setCustomNameVisible(true);
bomb.setInstance(this); bomb.setInstance(this);
Pos spawnPosition = this.newSpawnPosition(bomb, 2); Pos spawnPosition = this.newSpawnPosition(bomb, 2);
if(spawnPosition == null) { if(spawnPosition == null) {
4
@@ -27,7 +27,7 @@ public class TurtleGameFactory implements GameFactory {
public ConfigManager configuration() { public ConfigManager configuration() {
return new ConfigManager() return new ConfigManager()
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30, 40)) .addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30, 40))
.addOption(new NumericOption("startSpeed", Material.LEATHER_BOOTS, TranslatedComponent.byId("game_TurtleGame#startSpeed"), 2, 4, 6, 8)); .addOption(new NumericOption("startSpeed", Material.LEATHER_BOOTS, TranslatedComponent.byId("game_TurtleGame#startSpeed"), 2, 4, 6, 8, 10));
} }
@Override @Override