Package blocksthatfall

Source Code of blocksthatfall.GameOverState

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);
    }
   
}
TOP

Related Classes of blocksthatfall.GameOverState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.