perfekted colorjump
This commit is contained in:
@@ -32,6 +32,7 @@ public class ColorJump extends StatelessGame {
|
|||||||
Block.PINK_CONCRETE
|
Block.PINK_CONCRETE
|
||||||
);
|
);
|
||||||
private Block currentBlock;
|
private Block currentBlock;
|
||||||
|
private Block blockLastRound;
|
||||||
private double roundTime = 5;
|
private double roundTime = 5;
|
||||||
private final double multiplierNextRoundTime = 0.9;
|
private final double multiplierNextRoundTime = 0.9;
|
||||||
|
|
||||||
@@ -56,6 +57,8 @@ public class ColorJump extends StatelessGame {
|
|||||||
this.generate();
|
this.generate();
|
||||||
|
|
||||||
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
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()));
|
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
@@ -80,15 +83,31 @@ public class ColorJump extends StatelessGame {
|
|||||||
if(this.roundTime > 0.5)
|
if(this.roundTime > 0.5)
|
||||||
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
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(() -> {
|
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;
|
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() {
|
private void generate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user