This site requires JavaScript, please enable it in your browser!
Greenfoot back
davemib123
davemib123 wrote ...

2013/6/23

Jump active for far too long

davemib123 davemib123

2013/6/23

#
I've managed to get the character to jump using spacebar key but the jump is active for far too long and the character goes to the top of the screen. could someone take a look: http://www.greenfoot.org/scenarios/8881
Zamoht Zamoht

2013/6/23

#
Please add the source code :)
davemib123 davemib123

2013/6/23

#
done one better the source code is available.
Zamoht Zamoht

2013/6/23

#
Okay first of all you changed my checkGround() method.. The one i created would actually return true when mario was on the ground which makes your task a whole lot easier :) Okay so I changed a lot of methods, but only minor stuff, and to danpost before you start rewriting my 10 lines of code into 2, I know there is a smoother way.
public void act() 
    {
        checkKeys();
        if(!checkGround())  
        {  
            fall();  
        } 
        else
        {
            jumping = false;
        }
    }
public void jump()
    {
        vSpeed = vSpeed - jumpDistance;
        fall();
    }
public boolean checkGround()  
    {  
        Actor marioLeftFoot = getOneObjectAtOffset(-19, marioHeight, Tile.class);
        Actor marioRightFoot = getOneObjectAtOffset(19, marioHeight, Tile.class);
        if (marioLeftFoot == null && marioRightFoot == null) 
        {
            return false;
        }
        marioLeftFoot = getOneObjectAtOffset(-19, marioHeight - 1, Tile.class);    
        marioRightFoot = getOneObjectAtOffset(19, marioHeight - 1, Tile.class);
        while (marioLeftFoot != null || marioRightFoot != null)    
        {    
            setLocation(getX(), getY() - 1);
            marioLeftFoot = getOneObjectAtOffset(-19, marioHeight - 1, Tile.class);    
            marioRightFoot = getOneObjectAtOffset(19, marioHeight - 1, Tile.class);   
        } 
        vSpeed = 0;  
        return true;  
    } 
davemib123 davemib123

2013/6/25

#
Thanks Zamoht it works great.
You need to login to post a reply.