added timermanager

This commit is contained in:
Cedric Beck
2024-12-10 13:26:56 +01:00
parent 0c7030659a
commit 50f0cdfce6
2 changed files with 11 additions and 7 deletions

View File

@@ -21,6 +21,8 @@ public class MatrixAnimation extends ActionControl {
private List<ParticleEmitter> activeEmitter = new ArrayList<>(); private List<ParticleEmitter> activeEmitter = new ArrayList<>();
private ParticleEmitter radarEmitter = null; private ParticleEmitter radarEmitter = null;
private float timeElapsed = 0f; private float timeElapsed = 0f;
private final TimerManager timerManager = new TimerManager();
private enum MatrixState{ private enum MatrixState{
RADAR_ON, RADAR_ON,
@@ -30,6 +32,7 @@ private enum MatrixState{
} }
private MatrixState state; private MatrixState state;
public MatrixAnimation(MdgaApp app, Vector3f radarPos, Runnable runnable){ public MatrixAnimation(MdgaApp app, Vector3f radarPos, Runnable runnable){
super(runnable); super(runnable);
this.app = app; this.app = app;
@@ -50,18 +53,18 @@ protected void controlUpdate(float tpf) {
timeElapsed += tpf; timeElapsed += tpf;
switch(state){ switch(state){
case RADAR_ON -> { case RADAR_ON -> {
if(timeElapsed >= 2f){ if(timeElapsed >= 2f){
state = MatrixState.RADAR_OFF; state = MatrixState.RADAR_OFF;
timeElapsed = 0; timeElapsed = 0;
radarEmitter.setParticlesPerSec(0); radarEmitter.setParticlesPerSec(0);
new Timer().schedule(new TimerTask() { timerManager.addTask(3f, () -> app.enqueue(() -> {
@Override
public void run() {
app.getRootNode().detachChild(radarEmitter); app.getRootNode().detachChild(radarEmitter);
} return null;
}, 3000); }));
} }
} }
case RADAR_OFF -> { case RADAR_OFF -> {
@@ -95,6 +98,7 @@ public void run() {
} }
} }
} }
timerManager.update(tpf);
} }
private void turnOff(){ private void turnOff(){

View File

@@ -87,7 +87,7 @@ public Game() {
gameStatistics = new Statistic(); gameStatistics = new Statistic();
initializeDrawPile(); initializeDrawPile();
board = new Board(); board = new Board();
die = new Die(1,2,3,4, die = new Die(1,2,
5, 1,1,1 5, 1,1,1
); );
} }