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

2014/12/20

Add object within ? radius

gurlalsingh gurlalsingh

2014/12/20

#
I have to add my bee only within ? radius of a beehive. Can someone help me.
danpost danpost

2014/12/20

#
Please show the code for the class wherein you wish to add the bees with an attempt at doing so.
gurlalsingh gurlalsingh

2014/12/20

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class BeeHive extends Actor { private int numActs = 0; public void act() { numActs++; if ((300 % numActs)==0) { int Hive = (int)(Math.random()*20)+5; for (int i = 1; i<= Hive;i++) { Bee steve = new Bee(); getWorld().addObject( steve,getX(), getY() ); } } if (Math.random()<.001) { getWorld().removeObject(this); } } }
danpost danpost

2014/12/20

#
After adding the 'steve' to the world, give him a random rotation move him a random distance up to the radius required and then reset his rotation back to zero. Your remainder operation in the initial 'if' condition is odd in that it will only be true 18 times within the first 300 acts, then never be true again. If you want 'steve's to be spawned every 300 acts, you need to reverse the values -- (numActs % 300).
You need to login to post a reply.