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

2014/3/16

Help me with game, please!

Tarasovych Tarasovych

2014/3/16

#
I've done primitive game, where crab eats crystals. How I can add there: a timer (only 60 sec to game), a scoreboard (1 eaten crystall = 1 point) and acceleration after eating one crystall (a-1.1a-1.2a-...). Thanks for help and sorry for my English! Game
hugtvy hugtvy

2014/3/16

#
for the scoreboard if you go into edit>import class> counter> Import, it will add a counter into your game. Now what you need to do is tell your score board to add 1 to the counter everytime you eat a crystal! this can be done by making a reference to the counter in the Class that eats the crystal e.g the crab:
private void bumpCounter(int amount)
    {
        YourWolrdHere world;
        world = (YourWolrdHere)getWorld();
        Counter counter;
        counter = (Counter)world.getObjects(Counter.class).get(0);
        counter.add(amount);
    }
replace "YourWolrdHere" with the name of your world. now where you have the code to "eat" the crystal, add this underneath:
hugtvy hugtvy

2014/3/16

#
bumpCounter(1);
Tarasovych Tarasovych

2014/3/16

#
hugtvy wrote...
bumpCounter(1);
Thanks!
Tarasovych Tarasovych

2014/3/16

#
It works!
Tarasovych Tarasovych

2014/3/16

#
What about acceleration and timer?
hugtvy hugtvy

2014/3/16

#
um..for timer you could make a private int that equals 50x60 (50 = 1 second so 60 seconds would be 50x60) then make it something like this:
private int counter = 50*60;

private void act()
{
    counter--;
}
and then somehow make another counter to actually project it so bumpcounter(-50) instead of 1 but im not entirely sure
danpost danpost

2014/3/16

#
hugtvy wrote...
and then somehow make another counter to actually project it so bumpcounter(-50) instead of 1 but im not entirely sure
You do not need another counter. To project the score, use can use
int projectedScore = bumpCounter/50;
// or
int projectedScore = (bumpCounter+49)/50;
The first way will project zero when the bumpCounter reaches 49. The second way will project zero when the bumpCounter reaches 0.
You need to login to post a reply.