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

2013/10/29

End world

Baenefin Baenefin

2013/10/29

#
Hi, I am trying to get thie to work. If my actor hits the bottom of the level AND had 0 lives, end game If not, she is placed at the starting position. This is what I have
1
2
3
4
5
6
7
8
9
10
public void fall()
{
    setLocation ( getX(), getY() + vSpeed);
    vSpeed = vSpeed + acceleration;
    if ( atBottom() && ((ShroomScore) getWorld().getObjects(ShroomScore.class).get(0))==null )
        gameEnd();
        else{
            setLocation((Alice.class),20,340);
        }
}
SPower SPower

2013/10/29

#
Well, what would you like to happen when you want to end the game? Do you want to show a scoreboard or go to the main menu, or something else?
Baenefin Baenefin

2013/10/29

#
I will make a gameover world, with an option to restart the game
SPower SPower

2013/10/29

#
Then you can just replace the line gameEnd with:
1
Greenfoot.setWorld(new GameOverWorld());
Baenefin Baenefin

2013/10/29

#
Now every time I press the jump (up) button, it resets Alice to the given location in stead of jumping
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
public class Mover extends Actor
{
    private static final int acceleration = 1;      // down (gravity)
    public static final int Speed = 5;             // running speed (sideways)
    public int vSpeed = 0;                         // current vertical speed
 /**
     * Stop movement of this actor.
     */
    public void setVSpeed(int speed)
    {
        vSpeed = speed;
    }
 
    public void fall()
    {
        setLocation ( getX(), getY() + vSpeed);
        vSpeed = vSpeed + acceleration;
        if ( atBottom() && ((Score) getWorld().getObjects(Score.class).get(0))==null )
            gameEnd();
            else{
              setLocation (20,340);
            }
    }
 
    private boolean atBottom()
    {
        return getY() >= getWorld().getHeight() - 2;
    }
 
    private void gameEnd()
    {
        Greenfoot.setWorld(new gameOver());
    }
}
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
public class Alice extends Mover
{
 public void act()
    {
        checkKeys(); 
}
private void checkKeys()
    {
        if (Greenfoot.isKeyDown("left") )
        {
            setImage("AliceLeft.png");
            moveLeft();
 
        }
        if (Greenfoot.isKeyDown("right")  )
        {
            setImage("AliceRight.png");
            moveRight();
 
        }
        if (Greenfoot.isKeyDown("up") )
        {
            if (onGround() || onMover())
                jump();
        }
danpost danpost

2013/10/29

#
Check your logic on lines 18 through 23 in the 'fall' method of the 'Mover' class.
You need to login to post a reply.