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

2015/12/28

Enemies randomly spawning?

Jnrichards Jnrichards

2015/12/28

#
How do i get enemies to randomly spawn at a set location. Limiting factor of five maximum?
danpost danpost

2015/12/28

#
Use 'if' (to limit), 'Greenfoot.getRandomNumber' (to randomize) and 'addObect' (to add the enemies) in your World subclass act method. If you have issues with coding, post what you have tried and we can help correct it.
Jnrichards Jnrichards

2016/1/2

#
i've only been able to get it to start at a set location, idk how to do the rest private void prepare() { Enemy enemy = new Enemy(); addObject(enemy, 178, 788); }
Jnrichards Jnrichards

2016/1/2

#
actually i have it how i wanted it { getWorld().removeObject(Evil); Enemy enemy = new Enemy(); getWorld().addObject(enemy, Greenfoot.getRandomNumber(950), Greenfoot.getRandomNumber(900)); } Now is it possible to make this coincide with an onscreen counter. So that everytime the enemy is removed it goes up by 10
danpost danpost

2016/1/2

#
Jnrichards wrote...
i've only been able to get it to start at a set location, idk how to do the rest private void prepare() { Enemy enemy = new Enemy(); addObject(enemy, 178, 788); }
You can replace the hard-coded int values, '178' and '788' with method calls that return or variables that hold random int values. EDIT: just saw your second post -- looks okay. And yes, it is possible to have the counter add 10 to its value. Show your Counter class code, the code that creates and add one into the world and your attempt at accessing/changing its value.
You need to login to post a reply.