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

2019/11/17

Collection System

HEISENBERG HEISENBERG

2019/11/17

#
So I want to create a coin collection system. I've tried using "getOneIntersectingObject" but with no luck...
private int coinsCollected = 0;
private boolean fiveCoinsCollected = false;
private void collect () {
        Actor coin = getOneIntersectingObject(Coin.class);
        
        
        if (coin != null) {
            getWorld().removeObject(coin);
            coinsCollected++;
        }
        if (coinsCollected == 5 && fiveCoinsCollected == false) {
            getWorld().addObject(new door_temp(), 157, 162);
            fiveCoinsCollected = true;
        }
    }
HEISENBERG HEISENBERG

2019/11/17

#
I also forgot to say that the "door_temp" is the door for the next level. It will appear once the player has reached 5 coins.
danpost danpost

2019/11/17

#
HEISENBERG wrote...
So I want to create a coin collection system. I've tried using "getOneIntersectingObject" but with no luck... << Code Omitted >>
The cause of your principle failure is uncertain. Are you calling the collect method from the act method?
HEISENBERG HEISENBERG

2019/11/17

#
No, I don't think so... I'm calling the collect method, and in there is the Actor
danpost danpost

2019/11/17

#
HEISENBERG wrote...
No, I don't think so... I'm calling the collect method, and in there is the Actor
Please show entire class codes.
You need to login to post a reply.