Need help on mobile gaming development basic  {working the game main menu}

package Assignment1;
import java.io.IOException;
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
public class a1Canvas extends GameCanvas implements Runnable{
    private Display display;
    private Sprite ufoSprite;
    private Image backgroundImage;
    private long frameDelay;
    private int ufoX;
    private int ufoY;
    private int ufoXDir;
    private int ufoXSpeed;
    private int ufoYSpeed;
    private Random rand;
    private Sprite[] roidSprite = new Sprite[3];
    private boolean gameOverState;
    //constructor
    public a1Canvas(Display display){
        super(true);
        this.display = display;
        frameDelay = 33;
        gameOverState = false;
    public void start(){
        display.setCurrent(this);
        //start the animation thread
         rand = new Random();     // Initialize the random number generator
         ufoXSpeed = ufoYSpeed = 0; // Initialize the UFO and roids sprites
        try {
            backgroundImage = Image.createImage("/background.jpg");
            ufoSprite = new Sprite(Image.createImage("/ufo.png"));
            //initialise sprite at middle of screen
            ufoSprite.setRefPixelPosition(25,25);
            ufoX = (int)(0.5 * (getWidth()- ufoSprite.getWidth()));
            ufoY = (int)(0.5 * (getHeight()- ufoSprite.getHeight()));
            ufoSprite.setPosition(ufoX, ufoY);
            Image img = Image.createImage("/Roid.png");
            roidSprite[0] = new Sprite(img, 42, 35);   //create 1st frame-animated asteroid sprite
            roidSprite[1] = new Sprite(img, 42, 35);
            roidSprite[2] = new Sprite(img, 42, 35);
        } catch (IOException ex) {
            System.err.println("Failed to load images");
        Thread t = new Thread(this);
        t.start();
    public void run() {
        while (!gameOverState){
            update();
            draw(getGraphics());
            try{
                Thread.sleep(frameDelay);
            }catch(InterruptedException ie){}
        gotoMainMenu(getGraphics());
    private void draw(Graphics graphics) {
        //clear background to black
        graphics.setColor(0, 0, 0);
        graphics.fillRect(0, 0, getWidth(), getHeight());
        //draw the background
        graphics.drawImage(backgroundImage, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
        ufoSprite.paint(graphics);
        for(int i=0;i<3;i++){
            roidSprite.paint(graphics);
flushGraphics(); //flush graphics from offscreen to on screen
private void update() {
// Process user input to control the UFO speed
int keyState = getKeyStates();
if ( (keyState & LEFT_PRESSED) != 0 )
ufoXSpeed--;
else if ( (keyState & RIGHT_PRESSED) != 0 )
ufoXSpeed++;
if ( (keyState & UP_PRESSED) != 0 )
ufoYSpeed--;
else if ( (keyState & DOWN_PRESSED) != 0 )
ufoYSpeed++;
ufoXSpeed = Math.min(Math.max(ufoXSpeed, -8), 8);
ufoYSpeed = Math.min(Math.max(ufoYSpeed, -8), 8);
ufoSprite.move(ufoXSpeed, ufoYSpeed); // Move the UFO sprite
checkBounds(ufoSprite); // Wrap UFO sprite around the screen
// Update the roid sprites
for (int i = 0; i < 3; i++) {
roidSprite[i].move(i + 1, 1 - i); // Move the roid sprites
checkBounds(roidSprite[i]); // Wrap asteroid sprite around the screen
// Increment the frames of the roid sprites; 1st and 3rd asteroids spin in opposite direction as 2nd
if (i == 1)
          roidSprite[i].prevFrame();
else
          roidSprite[i].nextFrame();
// Check for a collision between the UFO and roids
if ( ufoSprite.collidesWith(roidSprite[i], true) ) {
System.out.println("Game Over !");
gameOverState = true;
}//if
}//for
public void stop(){
gameOverState = true;
private void checkBounds(Sprite sprite) {
// Wrap the sprite around the screen if necessary
if (sprite.getX() < -sprite.getWidth())
     sprite.setPosition(getWidth(), sprite.getY());
else if (sprite.getX() > getWidth())
     sprite.setPosition(-sprite.getWidth(), sprite.getY());
if (sprite.getY() < -sprite.getHeight())
     sprite.setPosition(sprite.getX(), getHeight());
else if (sprite.getY() > getHeight())
     sprite.setPosition(sprite.getX(), -sprite.getHeight());
private void gotoMainMenu(Graphics graphics) {
graphics.setColor(0, 0, 0);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(255, 0, 0);
graphics.drawRect(0, 0, getWidth()-1, getHeight()-1);
graphics.setColor(255, 255, 255);
graphics.drawString("GAME NAME", getWidth()/2 -50, 30, Graphics.LEFT | Graphics.TOP);
graphics.setColor(255, 0, 0);
graphics.drawString("Main Menu", getWidth()/2 -50, 50, Graphics.LEFT | Graphics.TOP);
graphics.setColor(0, 255, 0);
graphics.drawString("Start Game", getWidth()/2 , 80, Graphics.LEFT | Graphics.TOP);
graphics.drawString("Instructions", getWidth()/2 , 110, Graphics.LEFT | Graphics.TOP);
flushGraphics();
int keyState = getKeyStates();
if ( (keyState & FIRE_PRESSED) != 0 ){
System.out.println("game start");
gameOverState = false;
The problem i am facing is :
the FIRE button is not functioning, i put a system.out.println and it didnt print.
i am unsure whether i put the key input listener at the correct function
this button is supposed to start the game again.
What i want to do :
i want to display the main menu when i launched the game
when game is over, it will display back to the main menu again
when i press the fire button it will play the game again.
i hope someone can help me on this :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

kdoom wrote:
The problem i am facing is :
the FIRE button is not functioning, i put a system.out.println and it didnt print.
i am unsure whether i put the key input listener at the correct function
this button is supposed to start the game again.
What i want to do :
i want to display the main menu when i launched the game
when game is over, it will display back to the main menu again
when i press the fire button it will play the game again.
i hope someone can help me on this :)You didn't have to create a whole new post just for the formatted code, silly. You could have just replied in the old thread. Anyway:
Step through the program and think about what each line is doing. Most importantly:
    public void run() {
        while (!gameOverState){
            update();
            draw(getGraphics());
            try{
                Thread.sleep(frameDelay);
            }catch(InterruptedException ie){}
        gotoMainMenu(getGraphics());
    }This says that while the game is being played, update( ), then draw( ). When the game is over, call gotoMainMenu( ).
   private void gotoMainMenu(Graphics graphics) {
        //do a bunch of graphics stuff
        int keyState = getKeyStates();
        if ( (keyState & FIRE_PRESSED) != 0 ){
            System.out.println("game start");
            gameOverState = false;
    }This says to do a bunch of graphics stuff, and then to check the key states. If fire is being pressed, print something out and set gameOverState to false. This check only happens once. When the state is being checked, most likely the user will not be pressing any keys, so the code is done.
Also, simply setting the gameOverState variable to false outside of the loop you use it in won't do anything. For example:
boolean doLoop = true;
int count = 0;
while(doLoop){
   count++;
   if(count > 10){
      doLoop = false;
doLoop = true;Would you expect that second doLoop = true to start the while loop over?

Similar Messages

  • Need help on mobile gaming development basic

    my game canvas is like this
    public a1Canvas(Display display){
    super(true);
    this.display = display;
    frameDelay = 33;
    gameOverState = false;
    public void start(){
    display.setCurrent(this);
    try {
    //get the images up
    } catch (IOException ex) {
    System.err.println("Failed to load images");
    Thread t = new Thread(this);
    t.start();
    public void run() {
    while (!gameOverState){
    update();
    draw(getGraphics());
    try{
    Thread.sleep(frameDelay);
    }catch(InterruptedException ie){}
    gotoMainMenu(getGraphics());
    private void draw(Graphics graphics) {
    //clear background to black
    //draw the background
    private void update() {
    // Process user input
    // Check for game over condition
    if ( collision detection )
    gameOverState = true;
    }//if
    }//for
    private void gotoMainMenu(Graphics graphics) {
    //clear screen to black colour
    //draw the main menu
    flushGraphics();
    //if i press the fire button the game will start again
    int keyState = getKeyStates();
    if ( (keyState & FIRE_PRESSED) != 0 ){
    System.out.println("game start");
    gameOverState = false;
    The problem i am facing is :
    the FIRE button is not functioning, i put a system.out.println and it didnt print.
    i am unsure whether i put the key input listener at the correct function
    this button is supposed to start the game again.
    What i want to do :
    i want to display the main menu when i launched the game
    when game is over, it will display back to the main menu again
    when i press the fire button it will play the game again.
    i hope someone can help me on this :)

    kdoom wrote:
    my game canvas is like thisWhen posting code, use the CODE tag. Just highlight all your code (pasted in from your editor to preserve formatting) and press the CODE button. Otherwise nobody will read it.
    i hope someone can help me on this :)I can, if you use the CODE tag.

  • Need help on mobile crm development

    Dear all,
    I am new to Mobile CRM.Where can I get some tutorials or cookbook  for  developing Mobile applications for CRM .Please dont give the sap help link as I already  have it.
    It would be great if somebody explains me the arichetecture of mobile app development for CRM.
    Your support is highly appreciated.
    Thanks and regards,
    Rajesh

    Hi,
    Pls chk this links;might be useful.
    "Getting Started with Mobile Client Applications":
    http://help.sap.com/saphelp_crm50/helpdata/en/50/45c33a1dfe105ae10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_crm50/helpdata/en/0e/c90d3888a6b510e10000009b38f8cf/frameset.htm
    Regards,
    CSM Reddy

  • Need Help on Mobile Portal Development

    Hello everyone!
    I am trying to develop a portal (client) for web services on mobile devices that supports CLDC and MIDP, like the Yahoo! Go.
    I was just wondering what technologies I need to learn and tools I have to use to develop the portal application. I have been developing game applications using J2ME for quite sometime now, and this portal application is new to me that is why I am asking for 'guidance' in what steps I have to take.
    Any help is greatly appreciated. :)

    Hi,
    Pls chk this links;might be useful.
    "Getting Started with Mobile Client Applications":
    http://help.sap.com/saphelp_crm50/helpdata/en/50/45c33a1dfe105ae10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_crm50/helpdata/en/0e/c90d3888a6b510e10000009b38f8cf/frameset.htm
    Regards,
    CSM Reddy

  • Need help getting Adobe OnLocation CS3 to work with windows 7 64 bit. Any ideas?

    Need help getting Adobe OnLocation CS3 to work with windows 7 64 bit.  The program installed ok and the S/N took.
    The program does record video and audio HDV M2T.
    The problem is video doesn't display or play back on the monitor component @ 16:9 or 720 p.  4:3....
    The scopes respond as do the audio components when recording. (with a blank monitor component).
    The video does play back on my system no problem.
    Any ideas?
    Dan

    Moving the discussion to OnLocation
    Thanks,
    Atul Saini

  • Hello, my iphone for several times shows me this message "this iphone can't be used because the Apple Mobile Device service not started". I need help because i'm enable do download the new update. Thanks

    Hello, my iphone for several times shows me this message "this iphone can't be used because the Apple Mobile Device service not started".
    I need help, because i'm enable do download the new update.
    Thanks

    Type "Apple Mobile Device service" into the search bar at the top of this age by "Support" and read the resulting help articles.

  • I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results

    I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results, and very difficult to get help.

    Lightroom Trial uninstall wrote:
    Very frustrating you already took my money and no results, and very difficult to get help.
    Just for clarity, "we" haven't taken your money - this is a user-to-user forum, and you're not talking to Adobe.
    Like Rob I'm a Windows user, and - like him - I thought "uninstalling" on Macs was simply a case of trashing the application. Google would seem to concur.
    Not really a Lightroom/Adobe issue, then?

  • All of my photos are displayed as BW because somehow I've saved a quick develop preset and it saves as BW.  This is for all of my photos.  I can individually undo them but need help in how to get rid of the preset so it goes to Default. thanks

    All of my photos are displayed as BW because somehow I've saved a quick develop preset and it saves as BW.  This is for all of my photos.  I can individually undo them but need help in how to get rid of the preset so all photos goes to Default or as shot. thanks

    Go to the develop module and highlight all of the images in the filmstrip at the bottom of the screen. Then activate Auto-sync and click on the Reset button. That should reset all of the images to your camera default settings.

  • I need help - My illustrator CS2 just quit working.  Can anyone help?

    I went to open a file yesterday and illustrator just freezes on me.  won't open.  I have uninstalled and reinstalled but no luck.  My photo shop is working fine but Indesign now asks for serial number and then tells me it is not valid. Panic here as Adobe states they will not support/help me even if I pay.  They say illustrator CS2 is to old.  It does what I need for my business and must have it up and running again.  Short of buying the update - does anyone out there know of something I can try to resolve this?  HELP ME PLEASE????  Karen

    You are a life saver!!!!  It worked!  Thank You  so much - Why couldn't
    Adobe just sent this to me in the first place.  It would have made my life
    soooooo much easier.  Back in business again - just in time to get a rush
    order handled for one of our customers.   THANK YOU THANK YOU THANK YOU
    Karen
    From: cruisedesigner <[email protected]>
    Reply-To: <[email protected]>
    Date: Fri, 22 Jan 2010 08:38:58 -0700
    To: Karen Caisse <[email protected]>
    Subject: I need help - My illustrator CS2 just quit
    working.  Can anyone help?
    Hi Karen
    I just found this link whilst looking on the forum
    http://go.adobe.com/kb/ts_cpsid_53468_en-us
    go to this link it worked for me
    hope it helps
    >

  • I need help adding a mouse motion listner to my game. PLEASE i need it for

    I need help adding a mouse motion listner to my game. PLEASE i need it for a grade.
    i have a basic game that shoots target how can use the motion listner so that paint objects (the aim) move with the mouse.
    i am able to shoot targets but it jus clicks to them ive been using this:
    public void mouse() {
    dotX = mouseX;
    dotY = mouseY;
    int d = Math.abs(dotX - (targetX + 60/2)) + Math.abs(dotY - (targetY + 60/2));
    if(d < 15) {
    score++;
    s1 = "" + score;
    else {
    score--;
    s1 = "" + score;
    and here's my cross hairs used for aiming
    //lines
    page.setStroke(new BasicStroke(1));
    page.setColor(Color.green);
    page.drawLine(dotX-10,dotY,dotX+10,dotY);
    page.drawLine(dotX,dotY-10,dotX,dotY+10);
    //cricle
    page.setColor(new Color(0,168,0,100));
    page.fillOval(dotX-10,dotY-10,20,20);
    please can some1 help me

    please can some1 help meNot when you triple post a question:
    http://forum.java.sun.com/thread.jspa?threadID=5244281
    http://forum.java.sun.com/thread.jspa?threadID=5244277

  • I need help installing my adobe premiere element 13. the soft ware is 3.5 GB and I have a 654.4GB space is this enought space to dowload the software. It appears the software is downloading , but when it gets to the end it gives me the error summary messa

    I need help installing my adobe premiere element 13. the soft ware is 3.5 GB and I have a 654.4GB space is this enought space to dowload the software. It appears the software is downloading , but when it gets to the end it gives me the error summary message. I have been on the phone for hours being transfered from from person to the next with no results.

    reesep
    This is not Adobe. Rather user to user. The Adobe Staff and PRE_help presence in this forum is undefined.
    The replies from here are not instantaneous. But, your fellow users all try to respond as timely as possible.
    What is your computer operating system?
    From where are you downloading Premiere Elements 13....direct from Adobe as the tryout or the purchased product? If the purchased product, do you now have a purchased serial number to go with the installation files?
    Where are you stopped in the installation....at the Sign In or before? Is the faulting module cited in any messages? What are the error messages?
    The usual questions:
    1. Are you working with the antivirus and firewall(s) disabled?
    2. Are you running the computer programs as administrator?
    3. Are you working with a pen and tablet device instead of mouse?
    4. Is your video card/graphics card up to date according to the web site of the manufacturer of the card?
    5. Are you installing the program to the default location on the Local Disc C (if Windows).
    Let us start here and then decide what next based on the details that you post. Subsequent troubleshooting may include:
    deletion of the Adobe Premiere Elements Prefs file and/or uninstall, free ccleaner run through, reinstall with antivirus and firewall(s) disabled.
    Any questions or need clarification, please do not hesitate to ask.
    Thank you.
    ATR

  • Need help in modifying mapping parameters of out the box mapping

    Hi There,
    I am a new bee to dac.
    Need help in modifying mapping parameters of out the box mapping, which is invoked by DAC task.
    We got a requirement to edit mapping parameter. When I go and see parameter under mappings tab in a mapping, I could not see any values in it.
    But when I set any value, and validate it. It is successful.
    Is it right way to do it?
    What my concern is, When I initially go and see parameter values under maapings tab in a mapping, they are blank.
    Where is it storing these values?
    Thanks,
    Rag

    If you modify mapping then u have to create new task in dac and dac itself craete parameter file at run time. if you want to add more parameters then do it in dac system parameters tab.
    Thanks
    Jay.

  • I need help in activating apple id to for the find my iphone app

    i need help in activating apple id to for the find my iphone app

    What sort of help are you requesting from us, your fellow users? What exactly is the problem/issue?

  • HT6114 I need help hacking into my ipod i forgot the password and i cant factory reset it because the power button is broken?!

    I need help hacking into my ipod i forgot the password and i cant factory reset it because the power button is broken?!

    If your iPod Touch, iPhone, or iPad is Broken
    Apple does not fix iDevices. Instead, they exchange yours for a refurbished or new replacement depending upon the age of your device and refurbished inventories. On rare occasions when there are no longer refurbished units for your older model, they may replace it with the next newer model.
    ATTN: Beginning July 2013 Apple Stores are now equipped to do screen repairs/replacements in-house on iPhone 5 and 5C. In some cases while you wait. According to Apple this is the beginning of equipping Apple Stores with the resources needed to do most repairs for iPhones, iPads, and iPod Touches that would not require major replacements. Later in the year the services may be extended as Apple Stores become equipped and staffed with the proper repair expertise. So, if you need a screen repaired or a broken screen replaced or have your stuck Home button fixed, call your local Apple Store to see if they are now doing these in-house.
    You may take your device to an Apple retailer for help or you may call Customer Service and arrange to send your device to Apple:
    Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
    To contact product and tech support: Contacting Apple for support and service - this includes international calling numbers.
    You will find respective repair costs in the appropriate link:
    iPod Service Support and Costs
    iPhone Service Support and Costs
    iPad Service Support and Costs
    There are third-party firms that do repairs on iDevices, and there are places where you can order parts to DIY if you feel up to the task:
    1. iResq or Google for others.
    2. Buy and replace screen yourself: iFixit
    Locked Out, Forgot Lock or Restrictions Passcode, or Need to Restore Your Device: Several Alternative Solutions
    A
    1. iOS- Forgotten passcode or device disabled after entering wrong passcode
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. Restoring iPod touch after forgotten passcode
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. iOS- Understanding passcodes
    6. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    7. iOS - Unable to update or restore
    Forgotten Restrictions Passcode Help
                iPad,iPod,iPod Touch Recovery Mode
    You will need to restore your device as New to remove a Restrictions passcode. Go through the normal process to restore your device, but when you see the options to restore as New or from a backup, be sure to choose New.
    You can restore from a backup if you have one from BEFORE you set the restrictions passcode.
    Also, see iTunes- Restoring iOS software.

  • NEED HELP!! i restore backup at the wrong iphone

    NEED HELP!! i restore backup at the wrong iphone
    i have 2 iphone 4s.. i already have backuped the 1st iphone, then the 2nd iphone not yet backuped.
    when i plug the 2nd iphone it restore the backup of 1st iphone.. now the 1st and 2nd iphone has the same files... the original files of 2nd iphone has gone, how to restored the original files of 2nd iphone since i restored the backup of 1st iphone.and i do not have backup for the 2nd iphone. >.< PLEASE HELP!!!!

    With no backup for the 2nd iPhone, you can't.

Maybe you are looking for

  • MSI - KT3 Ultra-ARU Raid + XP

    Hi, I have just built a new system using the MSI - KT3 Ultra-ARU motherboard and am having issues instaling Windows XP professional. The system has been set with 2 Maxtor HD on Raid 0 Stipping. On installing Windows XP and Raid Driver 2.0 that comes

  • How to filter Billing Document Date

    Hello SAP Consultant I'm using vbrk and vbrp to fetch the data according to selection screen. Also i'm using Billing Document no as vbrp-vbeln and Billing date vbrp-fkdate. But i'm not able to filter the data according to billing document date. I'm u

  • Suggest a filename extension in a save file dialog

    Hello guys, does any of you know, how to suggest the user a certain filename extension in a save file dialog? I'm using both the normal save file dialog:      javax.swing.JFileChooser.showSaveDialog, and the Java Web Start save file dialog:      java

  • How to set a different listener on port 465 for SMTPS?

    The idea is being able to manage both plain and secure SMTP while reconfiguring all clients for SMTPS. How would you go about this? I have - created new Ip interface + listener - created SMTP authentication profile - created a new policy that require

  • How to include new inserted row in cursor

    Hi ... Is there anyway to include new inserted row into opened cursor ? consider the following code: declare cursor tbl_cur is select * from table1; -- table1 has two fields: no and name -- begin for tbl_rec in tbl_cur loop -- if I insert some record