1
0
mirror of https://github.com/inf112-v20/Fiasko.git synced 2025-03-04 17:19:45 +01:00

Legger til en visuell timer på PowerDownScreen

This commit is contained in:
Kristian Knarvik 2020-04-01 21:51:27 +02:00
parent a158ef4b20
commit 56949b9326

@ -1,7 +1,6 @@
package inf112.fiasko.roborally.game_wrapper;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
@ -20,7 +19,7 @@ public class PowerDownScreen extends AbstractScreen {
private long startTime;
private final int applicationWidth = 600;
private final int applicationHeight = 800;
private Boolean press = false;
private Boolean buttonPressed = false;
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
@ -36,7 +35,7 @@ public class PowerDownScreen extends AbstractScreen {
powerDownButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
press = true;
buttonPressed = true;
return true;//her we do stuff
}
});
@ -50,18 +49,20 @@ public class PowerDownScreen extends AbstractScreen {
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
int elapsedTime = (int)Math.floor((System.currentTimeMillis() - startTime) / 1000f);
roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "click to go in PowerDown you have 10 seconds",
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter Power Down next round",
applicationWidth/2f-380/2f,applicationHeight/2f + 100,380, 1, true);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(10 - elapsedTime),
applicationWidth / 2f - 40 / 2f,applicationHeight/2f - 100,40, 1, true);
roboRallyWrapper.batch.end();
stage.draw();
long time = System.currentTimeMillis();
if (time-startTime>10000){
if (elapsedTime > 10) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
dispose();
}
else if (press){
} else if (buttonPressed) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
dispose();
}