Skip to content

Instantly share code, notes, and snippets.

@RyanBreaker
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save RyanBreaker/f80356796b3b11df6f76 to your computer and use it in GitHub Desktop.

Select an option

Save RyanBreaker/f80356796b3b11df6f76 to your computer and use it in GitHub Desktop.
package GameState;
import TileMap.Background;
import Audio.AudioPlayer;
import java.awt.*;
import java.awt.event.KeyEvent;
public class MenuState extends GameState {
private Background bg;
private int currentChoice = 0;
private String[] options = { "Start", "Help", "Quit" };
private Color titleColor;
private Font titleFont;
private Font font;
private AudioPlayer bgMusic;
public MenuState(GameStateManager gsm) {
this.gsm = gsm;
try {
bg = new Background("/Backgrounds/PurpleClouds.gif", 1);
bg.setVector(-0.1, 0);
titleColor = new Color(128, 0, 0);
titleFont = new Font("Century Gothic", Font.PLAIN, 28);
font = new Font("Arial", Font.PLAIN, 12);
}
catch(Exception e){
e.printStackTrace();
}
}
public void init() {
bgMusic = new AudioPlayer("/Music/KingdomHeartsDearlyBeloved.wav");
bgMusic.play();
}
public void update(){
bg.update();
}
public void draw(Graphics2D g){
//draw bg
bg.draw(g);
//draw title
g.setColor(titleColor);
g.setFont(titleFont);
g.drawString("Anzori's Adventure", 40, 70);
//draw menu options
g.setFont(font);
for(int i = 0; i < options.length; i++) {
if(i == currentChoice) {
g.setColor(Color.BLACK);
} else {
g.setColor(Color.RED);
}
g.drawString(options[i], 145, 140 + i * 15);
}
}
private void select() {
if(currentChoice == 0) {
gsm.setState(GameStateManager.LEVEL1STATE);
}
if(currentChoice == 1) {
gsm.setState(GameStateManager.HELPSCREEN);
}
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