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

View File

@ -1,7 +1,6 @@
package inf112.fiasko.roborally.game_wrapper; package inf112.fiasko.roborally.game_wrapper;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
@ -20,7 +19,7 @@ public class PowerDownScreen extends AbstractScreen {
private long startTime; private long startTime;
private final int applicationWidth = 600; private final int applicationWidth = 600;
private final int applicationHeight = 800; private final int applicationHeight = 800;
private Boolean press = false; private Boolean buttonPressed = false;
public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) { public PowerDownScreen(final RoboRallyWrapper roboRallyWrapper) {
camera = new OrthographicCamera(); camera = new OrthographicCamera();
viewport = new FitViewport(applicationWidth, applicationHeight, camera); viewport = new FitViewport(applicationWidth, applicationHeight, camera);
@ -36,7 +35,7 @@ public class PowerDownScreen extends AbstractScreen {
powerDownButton.addListener(new InputListener() { powerDownButton.addListener(new InputListener() {
@Override @Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
press = true; buttonPressed = true;
return true;//her we do stuff return true;//her we do stuff
} }
}); });
@ -50,18 +49,20 @@ public class PowerDownScreen extends AbstractScreen {
camera.update(); camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
int elapsedTime = (int)Math.floor((System.currentTimeMillis() - startTime) / 1000f);
roboRallyWrapper.batch.begin(); 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); 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(); roboRallyWrapper.batch.end();
stage.draw(); stage.draw();
long time = System.currentTimeMillis(); if (elapsedTime > 10) {
if (time-startTime>10000){
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getMainMenuScreen(this.roboRallyWrapper));
dispose(); dispose();
} } else if (buttonPressed) {
else if (press){
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
dispose(); dispose();
} }