Results 1 to 4 of 4

Thread: Creating a Loop

  1. #1
    SenorJalapeno is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Question Creating a Loop

    I am new to java and I am recreating Super Mario Bros for the NES in Greenfoot. I am early on in my project but I need some help making Mario's legs move :(

    Here is the code I have currently:

    Java Code:
     public void checkKeys()
        {
         if (Greenfoot.isKeyDown("left") )
            {
                if(onGround() )
                setImage(marioRL);
                moveLeft();
            }
            if (Greenfoot.isKeyDown("right") )
            {
                if(onGround() )
                setImage(marioRR);
                moveRight();
            }
            
             if (Greenfoot.isKeyDown("x"))
            {
                if(onGround() )
                {
                    if(getImage() == marioRR)
                    {
                    jump();
                    setImage(marioJR);
                    }
                    else
                    {
                    jump();
                    setImage(marioJL);
                    }
                }
            }
        }
    I need my mario images to loop with the normal mario stance, and right or left running stance. So when the keys are pressed this loops until the key is released, or he is not onGround().

    Thanks in advance.
    Last edited by SenorJalapeno; 04-01-2010 at 07:02 AM.

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    When I did a simple little game, I used a thread that ran the animation process, first it would update the gamestate, for example if the up key is pressed change the state of the object/s accordingly, and then paint the new state on screen. I'd reccomend you take a look at Killer Game Programming in Java, I don't remember which specific chapter it was, but it does explain the concept behind a side scroller, including animating the character and paralax scrolling, also, my threaded animation idea came from there.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    Cross Posted
    Java Programming - Creating a Loop

    Any more?

    db

  4. #4
    wangwei is offline Member
    Join Date
    Apr 2010
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-26-2009, 12:45 AM
  2. Replies: 3
    Last Post: 07-23-2009, 08:45 AM
  3. Replies: 1
    Last Post: 07-22-2009, 11:10 PM
  4. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 PM
  5. Creating a New Method for Square Root Loop
    By SapphireSpark in forum New To Java
    Replies: 14
    Last Post: 02-25-2009, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •