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

2015/4/11

how can i stop of certain classes for game over screen. i want when counter got 200 point the game will over and show an over image.

chandan03 chandan03

2015/4/11

#
if (isTouching(Books.class)) { if (!getWorld().getObjects(Counter.class).isEmpty()) { ((Counter) getWorld().getObjects(Counter.class).get(0)).add(20); } removeTouching(Books.class); }
danpost danpost

2015/4/11

#
At least you know where the code would go:
if (isTouching(Books.class))
{
    removeTouching(Books.class);
    if (!getWorld().getObjects(Counter.class).isEmpty())
    {
        Counter counter = (Counter) getWorld().getObjects(Counter.class).get(0);
        counter.add(20);
        if (counter.getValue() == 200)
        {
            // add game over actor or change worlds here
            getWorld().removeObject(this); // if using game over actors (to avoid a multitude of them)
        }
    }
}
chandan03 chandan03

2015/4/11

#
thanks, but it is showing an error that cannot find counter variable, what should i do? and can u tell what is variable in greeenfoot and how we use this?
Super_Hippo Super_Hippo

2015/4/11

#
His code didn't produce this error. I guess you only added the if-block starting in line 8, but you have to understand the difference between line 6+7 and your line. You only add 20 to the counter. In danpost's code, he saves the counter object in the variable 'counter', adds 20 to it and checks if its value is 200.
chandan03 chandan03

2015/4/11

#
o sorry! that was my mistake. it is working now. thanks to both of u. can u tell me to how to make a game over screen
You need to login to post a reply.