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

2013/3/29

Jump code..

1
2
erdelf erdelf

2013/4/14

#
wouldnt it be easier to rewrite onGround?
danpost danpost

2013/4/14

#
Try starting the 'else' part with this statement:
1
ySpeed = 0;
un4giv3n94 un4giv3n94

2014/3/13

#
danpost ur the great
Pointifix Pointifix

2014/3/13

#
i always do jumps with square functions like -x² + c : c is the height of the jump and x must be set to the negative zero point of the graph
danpost danpost

2014/3/13

#
Pointifix wrote...
i always do jumps with square functions like -x² + c : c is the height of the jump and x must be set to the negative zero point of the graph
What do you mean by 'negative zero'? Zero is neither positive nor negative !!!
Pointifix Pointifix

2014/3/14

#
if you add c with like 100 the graph will be 100 at the x = 0 point, but the graph cuts the x-axis two times, once in the negative and once in the positive side, this are the point where the jump begin and ends.
danpost danpost

2014/3/14

#
oh, you mean 'negative x where y is zero'.
Pointifix Pointifix

2014/3/14

#
jeah right ;D
ZeroKnightZK ZeroKnightZK

2014/12/5

#
danpost wrote...
A simple jump/gravity code would be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import greenfoot.*
 
public class Jumper extends Actor
{
    private int ySpeed;
 
    public Jumper()
    {
    }
 
    public void act()
    {
        int groundLevel = getWorld().getWidth() - getImage().getHeight()/2;
        boolean onGround = (getY() == groundLevel);
        if (!onGround) // in middle of jump
        {
            ySpeed++; // adds gravity effect
            setLocation(getX(), getY()+ySpeed); // fall (rising slower or falling faster)
            if (getY()>=groundLevel) // has landed (reached ground level)
            {
                setLocation(getX(), groundLevel); // set on ground
                Greenfoot.getKey(); // clears any key pressed during jump
           }
        }
        else // on ground
        {
            if ("space".equals(Greenfoot.getKey())) // jump key detected
            {
                ySpeed = -15; // add jump speed
                setLocation(getX(), getY()+ySpeed; // leave ground
            }
        }
    }
}
How do you make it so if it lands on another Actor it stays there. Like in Mario where you jump on the bricks.
danpost danpost

2014/12/5

#
@ZeroKnightZK, you should start a new discussion thread and post code you have tried.
You need to login to post a reply.
1
2