perfekted colorjump

This commit is contained in:
2026-02-16 21:07:30 +01:00
parent e1515200ab
commit 410f7b4027

View File

@@ -32,6 +32,7 @@ public class ColorJump extends StatelessGame {
Block.PINK_CONCRETE
);
private Block currentBlock;
private Block blockLastRound;
private double roundTime = 5;
private final double multiplierNextRoundTime = 0.9;
@@ -56,6 +57,8 @@ public class ColorJump extends StatelessGame {
this.generate();
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
if(this.currentBlock == this.blockLastRound) this.nextRound();
this.blockLastRound = this.currentBlock;
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
this.getPlayers().forEach(player -> {
player.getInventory().clear();
@@ -80,15 +83,31 @@ public class ColorJump extends StatelessGame {
if(this.roundTime > 0.5)
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
long secondsLeft = Math.max(0, (long) this.roundTime);
long totalMillis = (long) (this.roundTime * 1000);
long startTime = System.currentTimeMillis();
for (int i = Math.min(3, (int) secondsLeft); i >= 0; i--) {
int level = i;
scheduler.scheduleTask(() -> {
this.getPlayers().forEach(player -> player.setLevel(level));
if (!this.isRunning) return stop;
long elapsed = System.currentTimeMillis() - startTime;
long remaining = totalMillis - elapsed;
if (remaining <= 0) {
this.getPlayers().forEach(player -> {
player.setExp(0f);
player.setLevel(0);
});
return stop;
}, TaskSchedule.seconds(secondsLeft-i));
}
float progress = (float) remaining / totalMillis;
this.getPlayers().forEach(player -> {
player.setExp(progress);
player.setLevel((int) Math.ceil(remaining / 1000.0));
});
return TaskSchedule.millis(50); // 1 Tick (20 TPS)
}, TaskSchedule.millis(0));
}
private void generate() {