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

2013/2/23

Need help with my projekt.

SKy. SKy.

2013/2/23

#
Hey guys, Sky from Germany here :) I have a little big problem with my projekt i'm doing for school at the moment. It's a little jump 'n' run with the character "Pinguin" and he wants to jump but the animation looks awefull :/ Can u help me to get a jump like this http://www.greenfoot.org/scenarios/7091 ? Thats my code:
if (pressSpace()) //jump
        {
            
            if(!objectAbove()&&(objectBelow())) 
//just jump if Pinguin stands on something and nothing is above him. 
            {
                for (int i = 1; i<=300; i++) //thats my Problem 
                {                                   
                            {  
                                if(!objectAbove())
                                {
                                        setLocation( getX(), getY() -1);                                    
                                }
                            }

                }
            }
EXTRA QUESTION: is there an alternativ for Greenfoot.delay() that just delays one class and not the whole Program ?
danpost danpost

2013/2/24

#
The jumping code, as shown above, says to teleport to the highest possible point up to 300 pixels from its current location without obstruction. What you want is to add an acceleration to its vertical speed so that its movement goes upward. The objects vertical speed will have to be kept track of. Each act cycle, add 1 to the vertical speed for the effect of gravity. If there is an object below this object (standing on something), set its vertical speed to the vertical speed of that on which it stands (of course, if the object does not rise or fall, then set the actors vertical speed to zero). When it is time to jump, add a moderate negative value to the vertical speed ('-24' should be comparable to what you were trying in your code above). You could use something similar to your 'for' loop above to break each pixel move of one part of the jump to detect obstacles; however, you should check for both above and below within the loop (the vertical speed could in the upward or downward direction). If you are lost, there is jumping code included in the Wombat class of my Scrolling SuperWorld scenario. It is more specific to what I wanted there, but may come in handy as an example.
You need to login to post a reply.