Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User want2win's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    8
    hi all,

    I am new to J2ME mobile gaming,
    I am doing fighting game, can any one help me how to make my user character to interact with the system character.
    please send me any sample code......



    thanking u in advance.........

    -------------
    WANT2WIN

  2. #2
    Nokia Developer Moderator petrib's Avatar
    Join Date
    Mar 2003
    Posts
    9,412
    What "system character"? Aren't you writing the whole game yourself? In other words, you control all the characters in your own game yourself with your own code.

  3. #3
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    Quote Originally Posted by want2win View Post
    hi all,

    I am new to J2ME mobile gaming,
    I am doing fighting game, can any one help me how to make my user character to interact with the system character.
    please send me any sample code......



    thanking u in advance.........

    -------------
    WANT2WIN
    Hi,
    Have you design the system character?Hope you develop the logic?
    search the same on Google, and you will find the few projects concept and might be code too.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User want2win's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    8
    hi petrib,

    thanks for ur reply......
    i am writing the whole game myself...

    "system character" in the sense opponent character...

    as i am doing fight game i hav 2 characters
    1) hero
    2) villain(opponent).

    i wrote code for hero movements(able to animate).
    when i am pressing the keys only the hero is acting according to the keys events.
    now parallel to hero movements the villan should also animate.

    but i dont know how to make both characters animate at a time in on the single layer.

    so please help me regarding this issue....

    thanking you in advance........
    ---------------
    WANT2WIN

  5. #5
    Super Contributor grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    OK... Java games 101.

    You need to animate BOTH of your characters, in the run() method of a thread. Don't update anything in your paint() method, just paint. Don't update your character position in the keyPressed() method.

    Here's some sample code... this isn't complete!! It is for example only, to see how a typical Java game is structured.

    PHP Code:
    public class MyGame extends Canvas implements Runnable {
        private static final 
    int MILLIS_PER_FRAME 100;  // 10 frames per second
        
    private static final int MINIMUM_SLEEP 10;  // always sleep() for at least this

        
    private static final int LEFT_KEY = -3;  // this is right for Nokias, different on others

        
    private boolean exitGame;
        private 
    boolean leftKeyPressed;
        private 
    boolean leftKeyReleased;
        private 
    int playerX;

        public 
    MyGame() {
            
    exitGame false;
            (new 
    Thread(this)).start();
        }

        public 
    void run() {
            
    // set exitGame to true to exit the game-thread
            
    while (!exitGame) {
                
    long startTime System.currentTimeMillis();

                
    // update the game state

                // first, process input
                
    if (leftKeyPressed) {
                    
    playerX--;
                    if (
    leftKeyReleased) {
                        
    leftKeyPressed false;
                        
    leftKeyReleased false;
                    }
                }

                
    // and other updates for the player, like:
                // playerAnimationFrame++;

                // next, update the "computer" character
                
    updateComputerCharacter();

                
    // paint the screen
                
    repaint();
                
    serviceRepaints();

                
    // this keeps the frame rate regular
                
    int timeTaken = (int)(System.currentTimeMillis() - startTime);
                
    int sleepTime MILLIS_PER_FRAME timeTaken;
                if (
    sleepTime MINIMUM_SLEEP) {
                    
    // if the game doesn't sleep on every frame, it is possible that
                    // no time will be given to the event thread, and keyPressed() events
                    // won't be delivered promptly
                    
    sleepTime MINIMUM_SLEEP;
                }
                if (
    sleepTime 0) {
                    try {
                        
    Thread.sleep(sleepTime);
                    } catch (
    Exception e) {
                        
    // ignore
                    
    }
                }
            }
        }

        public 
    void paint(Graphics g) {
            
    // don't do anything here, except paint
            
    drawBackground(g);
            
    drawPlayer(g);
            
    drawEnemy(g);
        }

        public 
    void keyPressed(int key) {
            
    // do nothing here, except record the event
            
    switch (key) {
            case 
    LEFT_KEY:
                
    leftKeyPressed true;
                break;
            }
        }

        public 
    void keyReleased(int key) {
            
    // do nothing here, except record the event
            
    switch (key) {
            case 
    LEFT_KEY:
                
    leftKeyReleased true;
                break;
            }
        }

    Why are there two booleans for one key? Why not?

    Code:
    // don't do this!!
    boolean leftKeyPressed;
    
    public void keyPressed(int key) {
        if (key == LEFT_KEY) {
            leftKeyPressed = true;
        }
    }
    
    public void keyReleased(int key) {
        if (key == LEFT_KEY) {
            leftKeyPressed = false;
        }
    }
    Don't do this, because it is possible to receive a pressed and released event during the same frame. With this code, the update code will never see that key pressed, because data will be lost.

    Setting MINIMUM_SLEEP to zero will make the game faster. But on some devices, it will make it less responsive to user input. Slowing the game down like this actually makes it feel faster.

    Hope this helps.

    Cheers,
    Graham.

  6. #6
    Nokia Developer Champion balagopalks's Avatar
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,427
    Also to add : have a look at Java Games Articles

    Regards
    Gopal
    Twitter : @balagopalks
    Linkedin : @balagopalks

  7. #7
    Registered User junfeng14's Avatar
    Join Date
    Jul 2009
    Posts
    15
    Hi Graham.,

    Meaning I will be using game builder on netbeans ?

    Thank you,

    Jun Feng

  8. #8
    Super Contributor grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    I've never used netbeans, I have no idea.

    Graham.

Similar Threads

  1. Replies: 3
    Last Post: 2008-09-09, 04:53
  2. Tip: Developing Connected Mobile Java Games with SNAP Mobile
    By heihauki in forum Mobile Java Games
    Replies: 7
    Last Post: 2008-03-08, 17:42
  3. Replies: 11
    Last Post: 2007-10-03, 19:46
  4. Regd. Games for mobile phones
    By in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2002-04-26, 12:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved