Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hp78
- */
- import java.io.IOException;
- import java.io.*;
- import java.util.*;
- import java.util.Timer;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.*;
- import javax.microedition.lcdui.game.GameCanvas;
- import javax.microedition.lcdui.game.LayerManager;
- import javax.microedition.lcdui.game.Sprite;
- import javax.microedition.lcdui.game.TiledLayer;
- import javax.microedition.lcdui.game.Layer;
- import javax.microedition.lcdui.Font;
- import javax.microedition.media.*;
- import javax.microedition.media.Control.*;
- import javax.microedition.media.control.ToneControl;
- import javax.microedition.media.protocol.*;
- import javax.microedition.io.*;
- import javax.microedition.rms.RecordStoreException;
- public class MenuCanvas extends GameCanvas implements Runnable {
- //menu system
- private Graphics g = getGraphics();
- private int w = getWidth();
- private int h = getHeight();
- private int currentSelectedIndex = 0;
- boolean x = true;
- private Thread t;
- private Display d;
- private BeatBoyCanvas gameCanvas;
- private GameMidlet boss;
- public MenuCanvas() {
- super(true);
- try {
- this.setFullScreenMode(true);
- this.init();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- private void init() throws IOException{
- }
- public void run() {
- //menu render
- drawBg();
- drawMenu(currentSelectedIndex);
- //check keystate
- while(x = true ){
- int keyState = getKeyStates();
- if((keyState & DOWN_PRESSED)!=0)
- {
- if(currentSelectedIndex == 0)
- currentSelectedIndex = 1;
- else
- currentSelectedIndex = 0;
- drawBg();
- drawMenu(currentSelectedIndex);
- System.out.println(currentSelectedIndex);
- }
- else if ((keyState & UP_PRESSED) != 0)
- {
- if(currentSelectedIndex == 0)
- currentSelectedIndex = 1;
- else
- currentSelectedIndex = 0;
- drawBg();
- drawMenu(currentSelectedIndex);
- System.out.println(currentSelectedIndex);
- }
- else if((keyState & FIRE_PRESSED) != 0)
- {
- if(currentSelectedIndex == 0){
- boss.startGame();
- x = false;
- }
- else
- System.out.println("exit chosen");
- x=false;
- }
- flushGraphics();
- }
- try {
- Thread.sleep(20);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
- // work with menu according to its current state
- /**
- * Stops the main game loop.
- */
- public void stop() {
- }
- //paint bg black
- public void drawBg ()
- {
- g.setColor(0, 0, 0);
- g.fillRect(0, 0, getWidth(), getHeight());
- //flushGraphics();
- }
- //drawmenu
- public void drawMenu (int currentSelectedIndex)
- {
- g.setColor(255,0,0);
- String menuTitle = "SUPER BEAT BOY";
- g.drawString(menuTitle,w/2, h/2,g.BASELINE|g.HCENTER);
- //start menu options
- String menuOptions[] = {"PLAY", "EXIT"};
- int paddedHeight = h/2 + 40;
- for (int i = 0; i<2; i++)
- {
- if(currentSelectedIndex == i)
- {
- g.setColor(255,255,255);
- }
- else
- {
- g.setColor(255,0,0);
- }
- g.drawString(menuOptions[i],w/2, paddedHeight,g.BASELINE|g.HCENTER);
- paddedHeight = paddedHeight + 40;
- }
- //flushGraphics();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement