improved speed mechanic and bomb spawning, added countdown for last player
This commit is contained in:
@@ -125,18 +125,26 @@ class TurtleGame extends StatelessGame {
|
||||
}
|
||||
|
||||
protected void explode(Player p, Entity bomb) {
|
||||
Turtle turtle = this.turtlePlayerMap.get(p);
|
||||
this.letPlayerLoose(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.destroy();
|
||||
this.getScore().insertResult(p, this.turtlePlayerMap.get(p).getScore());
|
||||
if(this.getLeftPlayers().size() == 1) this.setTimeLimit(10);
|
||||
this.bombs.remove(bomb);
|
||||
bomb.remove();
|
||||
}
|
||||
|
||||
protected void letPlayerLoose(Player p) {
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
p.setFlying(true);
|
||||
this.turtlePlayerMap.get(p).destroy();
|
||||
this.getScore().insertResult(p, this.turtlePlayerMap.get(p).getScore());
|
||||
}
|
||||
|
||||
protected List<Player> getLeftPlayers() {
|
||||
return this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
this.turtlePlayerMap.putIfAbsent(p, new Turtle(p, this.startSpeed));
|
||||
@@ -200,7 +208,7 @@ class TurtleGame extends StatelessGame {
|
||||
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
|
||||
meta.setCustomNameVisible(true);
|
||||
bomb.setInstance(this);
|
||||
Pos spawnPosition = this.newSpawnPosition(bomb, 2);
|
||||
Pos spawnPosition = this.newSpawnPosition(bomb, false);
|
||||
if(spawnPosition == null) {
|
||||
bomb.remove();
|
||||
return;
|
||||
@@ -211,11 +219,11 @@ class TurtleGame extends StatelessGame {
|
||||
|
||||
@Nullable
|
||||
private Pos newSpawnPosition(Entity entity) {
|
||||
return this.newSpawnPosition(entity, 0);
|
||||
return this.newSpawnPosition(entity, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pos newSpawnPosition(Entity entity, double border) {
|
||||
private Pos newSpawnPosition(Entity entity, boolean nearPlayers) {
|
||||
Pos spawnPosition;
|
||||
int counter = 0;
|
||||
boolean isInRadius, collides;
|
||||
@@ -227,10 +235,15 @@ class TurtleGame extends StatelessGame {
|
||||
int z = this.rnd.nextInt(-this.radius+2, this.radius-2);
|
||||
spawnPosition = new Pos(x, 1, z).add(0.5, 0, 0.5);
|
||||
Pos checkPosition = spawnPosition;
|
||||
isInRadius = checkPosition.distance(0, 1, 0) < this.radius-3;
|
||||
isInRadius = checkPosition.distance(0, 1, 0) < this.radius-2;
|
||||
collides = this.getEntities().stream()
|
||||
.filter(e -> !e.equals(entity))
|
||||
.anyMatch(e -> entity.getBoundingBox().growSymmetrically(border, border, border).intersectBox(e.getPosition().sub(checkPosition), e.getBoundingBox()));
|
||||
.anyMatch(e -> entity.getBoundingBox().intersectBox(e.getPosition().sub(checkPosition), e.getBoundingBox()));
|
||||
if(!collides && !nearPlayers) collides = this.turtlePlayerMap.values().stream()
|
||||
.filter(turtle -> !turtle.equals(entity))
|
||||
.anyMatch(turtle -> entity.getBoundingBox()
|
||||
.growSymmetrically(turtle.getBombBorder(), 1, turtle.getBombBorder())
|
||||
.intersectBox(turtle.getPosition().sub(checkPosition), turtle.getBoundingBox()));
|
||||
counter++;
|
||||
} while (!isInRadius || collides);
|
||||
return spawnPosition;
|
||||
@@ -242,4 +255,9 @@ class TurtleGame extends StatelessGame {
|
||||
this.generateNewBomb((int) Math.ceil(this.snacks.size() * 0.5));
|
||||
this.turtlePlayerMap.values().forEach(Turtle::startBoostRefill);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
this.getLeftPlayers().forEach(this::letPlayerLoose);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ public class Turtle extends EntityCreature {
|
||||
private final Player player;
|
||||
private int score = 0;
|
||||
private double speed;
|
||||
private final double boostSpeedAmount = 4;
|
||||
private double boostSpeedMultiplier = 1;
|
||||
private float boostChargeLevel = 0f;
|
||||
private Task boostTask;
|
||||
private Task boostRefillTask;
|
||||
@@ -47,8 +47,8 @@ public class Turtle extends EntityCreature {
|
||||
this.removePassenger(this.player);
|
||||
this.remove();
|
||||
this.kill();
|
||||
this.boostRefillTask.cancel();
|
||||
this.boostTask.cancel();
|
||||
if(this.boostRefillTask.isAlive()) this.boostRefillTask.cancel();
|
||||
if(this.boostTask.isAlive()) this.boostTask.cancel();
|
||||
}
|
||||
|
||||
public void adaptView() {
|
||||
@@ -60,7 +60,7 @@ public class Turtle extends EntityCreature {
|
||||
public void move() {
|
||||
this.adaptView();
|
||||
Vec direction = this.player.getPosition().direction();
|
||||
Vec movementVector = direction.withY(0).normalize().mul(this.speed);
|
||||
Vec movementVector = direction.withY(0).normalize().mul(this.speed * this.boostSpeedMultiplier);
|
||||
this.setVelocity(movementVector);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Turtle extends EntityCreature {
|
||||
|
||||
public void boostSpeed() {
|
||||
if(this.boostChargeLevel <= 0f) return;
|
||||
this.speed += this.boostSpeedAmount;
|
||||
this.boostSpeedMultiplier = 3.5;
|
||||
this.boostTask = MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||
if(this.boostChargeLevel <= 0f) {
|
||||
this.cancelBoost();
|
||||
@@ -85,7 +85,7 @@ public class Turtle extends EntityCreature {
|
||||
public void cancelBoost() {
|
||||
if(!this.boostTask.isAlive()) return;
|
||||
this.boostTask.cancel();
|
||||
this.speed -= this.boostSpeedAmount;
|
||||
this.boostSpeedMultiplier = 1;
|
||||
}
|
||||
|
||||
public void addSpeed(double amount) {
|
||||
@@ -96,6 +96,11 @@ public class Turtle extends EntityCreature {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public double getBombBorder() {
|
||||
// 1 bei speed 2; 2 bei speed 4; 4 bei speed 8
|
||||
return Math.clamp((this.speed * this.boostSpeedMultiplier) / 2, 1.5, 4);
|
||||
}
|
||||
|
||||
public void increaseScore() {
|
||||
this.score += 1;
|
||||
this.player.setLevel(this.score);
|
||||
|
Reference in New Issue
Block a user