package blocksthatfall;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class GameOverState extends BasicGameState {
int stateID = -1;
GameOverState(int stateID) {
this.stateID = stateID;
}
@Override
public int getID() {
return stateID;
}
@Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
}
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics grphcs) throws SlickException {
grphcs.setBackground(Color.white);
grphcs.setColor(Color.black);
Font font = grphcs.getFont();
int posX = (800/2 - font.getWidth("SCORE: "+BlocksThatFall.score) / 2);
int posY = (600/2 - font.getHeight("SCORE: "+BlocksThatFall.score) / 2)-60;
grphcs.drawString("SCORE: "+BlocksThatFall.score, posX, posY);
posX = (800/2 - font.getWidth("GAME OVER") / 2);
posY = (600/2 - font.getHeight("GAME OVER") / 2);
grphcs.drawString("GAME OVER", posX, posY);
posX = (800/2 - font.getWidth("press SPACE to play again or ESC to exit") / 2);
posY = 30 + (600/2 - font.getHeight("press SPACE to play again or ESC to exit") / 2);
grphcs.drawString("press SPACE to play again or ESC to exit", posX, posY);
}
@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input in = gc.getInput();
if(in.isKeyPressed(Input.KEY_ESCAPE)) gc.exit();
if(in.isKeyPressed(Input.KEY_SPACE)) sbg.enterState(BlocksThatFall.GAMEPLAYSTATE);
}
}