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

2014/8/3

Start Menu and Changing Level

1
2
3
VideoGame VideoGame

2014/8/6

#
It works ! Thank you, and for the door and the key: how to bind the door, the key and the player so that the player grab the key, touch the door and the screen and the map change to the next level ?
danpost danpost

2014/8/6

#
The door and the key are already bound by the code I gave for the Door class. You can have the key remove itself when the player touches it (coded in the act method of the Key class). The removal of the key from the world will automatically unlock the door. The code I gave previously for the Door act method will properly pass to the next level if allowed. In short, here is what happens: * when you create a door, it creates its own key * when you add that key to the world, the door locks * when the player touches the key, the key is removed from the world * when the key is not in the world, the door is unlocked * when the player touches the door while it is unlocked, the next level starts
danpost danpost

2014/8/6

#
Oh,, you will need to add a line at the beginning of your 'populateWorld' method to remove all objects currently in the world:
1
removeObjects(getObjects(null));
VideoGame VideoGame

2014/8/7

#
Thank you for your help ! When I add a key in the World, the player can't 'grab' it. So the door is locked. Even I don't add the key, the door should be unlocked but when the player touch the door, nothing happens. In fact, the player pass through the key and the door. And for the map, some platforms is cut in two or something like that. Is it a problem with super(30*map.length(), 30*map.length, 1); ?
danpost danpost

2014/8/7

#
Please show your Key class code.
danpost danpost

2014/8/7

#
Ah, I did notice that I was using '30', and not '32', for the actor size. Change all occurrences of '30' to '32' in the 'super' call.
VideoGame VideoGame

2014/8/7

#
I would have thought ... There is nothing in the Key class..
danpost danpost

2014/8/7

#
The key should remove itself when the player touches it (or, rather, when the key 'is touching' the player). This would be coded in the 'act' method of the Key class.
danpost danpost

2014/8/7

#
danpost wrote...
Oh,, you will need to add a line at the beginning of your 'populateWorld' method to remove all objects currently in the world:
1
removeObjects(getObjects(null));
This is totally unnecessary (since you will be creating new Level worlds and not re-using the same world).
VideoGame VideoGame

2014/8/7

#
Awesome, it works perfectly after I add this in the key class
1
2
3
4
5
6
7
8
9
Actor player = getOneIntersectingObject(Player.class);
            if(getX() <= 1 || getX() >= getWorld().getWidth() -1)
        {
            getWorld().removeObject(this); // l'image du kunai est removed
        }
        else if(player !=null)
        {
            getWorld().removeObject(this); // pareil
        }
Thank you again
danpost danpost

2014/8/7

#
Still, need to see the Key and Door class codes.
danpost danpost

2014/8/7

#
NVM.
VideoGame VideoGame

2014/8/7

#
Door Class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private Key key = new Key();
    /**
     * Act - do whatever the Door wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        if (key.getWorld() == null && isTouching(Player.class))
        { // key was picked up and player is at door
            Level.level++;
            Greenfoot.setWorld(new Level());
        }
    }  
    public Key getKey()
    {
        return key;
    }
danpost danpost

2014/8/7

#
Question: why are you having the keys remove themselves if they reach the left or right edges of the world? Do the keys even move? All you should need in the key class is this:
1
2
3
4
public void act()
{
    if (isTouching(Player.class)) getWorld().removeObject(this);
}
VideoGame VideoGame

2014/8/7

#
It was just a test. I copy/paste the code for the arrow
There are more replies on the next page.
1
2
3