Skip to content

Instantly share code, notes, and snippets.

@89515522549
Created January 11, 2015 11:36
Show Gist options
  • Save 89515522549/7acd3b825db1640f1ce5 to your computer and use it in GitHub Desktop.
Save 89515522549/7acd3b825db1640f1ce5 to your computer and use it in GitHub Desktop.
package GameState;
import Audio.AudioManager;
import TileMap.Background;
import java.awt.*;
import java.awt.event.KeyEvent;
public class MenuState extends GameState {
private Background bg;
private int currentChoice = 0;
private String[] options = {
"Старт",
"Выход"
};
private Color titleColor;
private Font titleFont;
private Font font;
public MenuState (GameStateManager gsm){
this.gsm = gsm;
try {
bg = new Background("/Backgrounds/menubg2.png",1);
// bg.setVector(-0.1,0);
titleColor = new Color(128,0,0);
titleFont = new Font("Segoe Print", Font.PLAIN, 25);
font = new Font("Segoe Print", Font.PLAIN, 16);
}
catch (Exception e){
e.printStackTrace();
}
init();
}
public void init() {
AudioManager.getInstanse().getLevel1Music().stop();
AudioManager.getInstanse().getwastedMusic().stop();
AudioManager.getInstanse().getStartMusic().play();
}
public void update(){
bg.update();
}
public void draw ( java.awt.Graphics2D g){
bg.draw(g);
//draw title
g.setColor(titleColor);
g.setFont(titleFont);
g.drawString("", 85, 70);
g.setFont(font);
for (int i =0 ; i< options.length; i++ ){
if (i == currentChoice){
g.setColor(Color.WHITE);
}
else{
g.setColor(Color.RED);
}
g.drawString (options[i], 200, 140 + i*30);
}
}
private void select(){
if (currentChoice == 0){
gsm.setState(GameStateManager.LEVEL1STATE);
}
if (currentChoice == 1){
//chois
System.exit(0);
}
// if (currentChoice == 2){
// System.exit(0);
// }
}
public void keyPressed(int k){
if (k== KeyEvent.VK_ENTER){
select();
}
if (k== KeyEvent.VK_UP){
currentChoice--;
if (currentChoice == -1){
currentChoice = options.length - 1;
}
}
if (k== KeyEvent.VK_DOWN){
currentChoice++;
if (currentChoice == options.length){
currentChoice = 0;
}
}
}
public void keyReleased(int k){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment