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

2012/5/7

Does anyone see anything wrong with this?

darkmist255 darkmist255

2012/5/7

#
I've got some code just to let the player know when to fall down but for some reason I can't get it to work, does anyone see anything wrong with this? It runs every act() cycle.
yGravityAddition = 0;
        xGravityMultiplier = 1;
        standingOnBlock = true;
        standingOnLadder = true;
        if(getOneObjectAtOffset(getImage().getWidth(), (getImage().getHeight() + 1), Block.class) == null && getOneObjectAtOffset(-getImage().getWidth(), (getImage().getHeight() + 1), Block.class) == null && getOneObjectAtOffset(0, (getImage().getHeight() + 1), Block.class) == null)
        {
            standingOnBlock = false;
        }
        if(getOneObjectAtOffset(getImage().getWidth(), (getImage().getHeight() + 1), Ladder.class) == null && getOneObjectAtOffset(-getImage().getWidth(), (getImage().getHeight() + 1), Ladder.class) == null && getOneObjectAtOffset(0, (getImage().getHeight() + 1), Ladder.class) == null)
        {
            standingOnLadder = false;
        }
        
        if(!standingOnBlock && !standingOnLadder)
        {
            yGravityAddition = gravityRate;  //This variable works
            xGravityMultiplier = 0.3;    //This variable works
        }
danpost danpost

2012/5/7

#
There are two things I see, but the one that might be the reason the player does not know when to fall it there are no commands to move or re-locate the player (or make the player fall). The other thing I noticed, is that the player will probably be floating above the objects (maybe half the height again of the image of the player), once told to fall. All your 'getImage().getWidth()' and 'getImage().getHeight()' value offsets need to be cut in half ( divided by 2 ).
darkmist255 darkmist255

2012/5/7

#
Ohohohoho I forgot about dividing the width and height! Thank you! And the re-location parts are all separate and working well on their own, this method just threw them off.
You need to login to post a reply.