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

2014/2/19

Doodle jump code help

CassWin CassWin

2014/2/19

#
hi, im doing a doodle jump game. and i want the sledge to flow down from top in a uniform manner. can anyone help me with this code??
danpost danpost

2014/2/19

#
Can you make it go down at all? are you using 'setLocation' or 'move' (well, what code have you tried)?
CassWin CassWin

2014/2/20

#
public void act() { if(Greenfoot.getRandomNumber(50) < 3) { addObject(new brick(), Greenfoot.getRandomNumber(400), 0); // world width is 400. so they come randomly } } this is how I am creating bricks to come from top. but they dont come uniformly. sometimes there are no bricks only for the doodle to jump on. in brick class im using "move(2);"
danpost danpost

2014/2/20

#
Sounds like you need a timer that is given a random value within a range of values. Then subtract one from the counter each act method and when it is zero, add a brick and give the counter a new random value within the range. This would mean you need an instance int field, call it 'spawnTimer' in the world class and code in the world act method to check its value for zero to add a brick and give the time a new random value in the chosen range using something like:
spawnTimer = minValue+Greenfoot.getRandomNumber(maxValue-minValue);
This should effectively limit the time between random spawns.
CassWin CassWin

2014/2/20

#
thankx alott!!
You need to login to post a reply.