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

2012/5/13

Score per second help please!

horyna horyna

2012/5/13

#
My game is a game where you are a tank and you have to survive the longest before the two computer controlled tanks kill you. The idea of the game is that the people playing will compete to get the longest time in seconds, obviously the player that survives the longest will win. for this to work i need something that will count up in seconds preferably at the top left of the screen. Anyone got any idea how to do this? Thanks
SPower SPower

2012/5/13

#
Take a look at my Library project, and specifically in the counter and in the SimpleTimer class. If you need help, ask me.
horyna horyna

2012/5/13

#
thanks ill have a look now!
horyna horyna

2012/5/13

#
Dont really know where to start haha im a proper noob at this, cheers anyway!
SPower SPower

2012/5/13

#
Create a new Counter in YourWorld:
public class YourWorld extends SuperWorld
{
    private Counter counter;
    private SimpleTimer timer;
    
    /**
     * Create a new YourWorld.
     * It puts a mouse follower and some text in the world
     */
    public YourWorld()
    {
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels:
        super(600, 400, 1);
        prepare();
    }
Then, change prepare() to this:
private void prepare()
    {
        counter = new Counter();
        addObject(counter, 100, 200);
        SimpleTimer timer = new SimpleTimer();
        timer.mark();
    }
Change act() to this:
public void act()
    {
        counter.setValue(timer.millisElapsed());
    }
All this would set the Counter to the number of milliseconds ellapsed since the creation of the counter. If you have questions, ask me.
SPower SPower

2012/5/13

#
Sorry: wrong thing: Change prepare() to this:
    private void prepare()
    {
        counter = new Counter();
        addObject(counter, 100, 200);
        timer = new SimpleTimer();
        timer.mark();
    }
The rest was OK.
horyna horyna

2012/5/13

#
Whats the superworld part?
SPower SPower

2012/5/13

#
That is just a class I wrote to give you extra capabilities. You don't need it here. But don't change it if you ever want to use it.
horyna horyna

2012/5/13

#
okay thanks!
SPower SPower

2012/5/13

#
You're welcome :)
You need to login to post a reply.