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

2013/6/27

Using counter.class for life and score

davemib123 davemib123

2013/6/27

#
I have the counter.class to work for adding score. But how do I get the counter to show the number of lives at 3? I have this in the world class to generate the counter in the world:
scoreCounter = new Counter ("Score");
        addObject(scoreCounter, 1035, 21);
        lifeCounter = new Counter ("Life");
        addObject(lifeCounter, 1027, 51);
Scenario with source added: http://www.greenfoot.org/scenarios/8881
davemib123 davemib123

2013/6/27

#
Nevermind, got this sorted.
davemib123 davemib123

2013/6/27

#
I have the life subtracted when Goomba collides with Mario but how do I get Mario to reset himself to the first location?
davemib123 davemib123

2013/6/27

#
I've tried by restting the world, but this does not give the desired effect.
djsat djsat

2013/6/28

#
inicializa scoreCounter asi: public Counter scoreCounter; luego para acceder a los métodos del contador, si quieres incrementar ; scoreCounter.add(); hasta ahí tienes el decremento tienes editar los métodos contenidos en la clase Counter y añadir uno nuevo; si quieres mas pistas te digo
Zamoht Zamoht

2013/6/28

#
Save Mario's start location somewhere and then set Mario's location to that when you want to reset.
davemib123 davemib123

2013/7/1

#
Zamoht wrote...
Save Mario's start location somewhere and then set Mario's location to that when you want to reset.
Would I save the start location in World or in Mario?
Zamoht Zamoht

2013/7/1

#
Create two ints in the world. int marioStartX; int marioStartY; And then in the setupLevel you should remember to set these to the location that you add Mario to. Then you can create a reset method which set Mario's location to the start location. Though you can also add these ints to the Mario class, I doesn't really matter. So just put them where you have the easiest access to them when you need them.
davemib123 davemib123

2013/7/1

#
Thanks Zamoht. I've created the ints, and placed them in the setupLevel. Could you elaborate on the reset method?
Zamoht Zamoht

2013/7/1

#
It really depends on how much you want to reset, is it only Mario? is it Mario and enemies? is it Mario, enemies and coins? If it's only Mario, you can easily create a reset method which would look something like this: public void reset() { setLocation(marioStartX, marioStartY); } If you saved the integers in Mario. If you have them in the world the code would look like this: public void reset() { WorldClassNameHere world = (WorldClassNameHere) getWorld(); setLocation(world.marioStartX, world.marioStartY); }
davemib123 davemib123

2013/7/1

#
ace that works great.
davemib123 davemib123

2013/7/1

#
Zamoht, I suppose if i wanted to reset Mario, enemies and coins that would be a method directly in the world class?
Zamoht Zamoht

2013/7/1

#
It would make good sense to put that in the world class, yes.
davemib123 davemib123

2013/7/1

#
Thanks for the suggestion. I got it done within Mario class. I was about to ask for some support but managed to get it working fine.
Zamoht Zamoht

2013/7/1

#
Good :) Just ask if you need any help.
You need to login to post a reply.