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

2017/5/16

How to make new Predator spawn.

SprayNPray SprayNPray

2017/5/16

#
I have a question. I am making this Fish scenario in Greenfoot. I have fish randomly spawning and moving tot he edge of the world only to then come back on 0 for the x axis and at the same y axis. I then have a predator that eats the fish. I need to somehow have another predator fish spawn whenever the original predator eats 5 fish. Anyone know how to do that?
Super_Hippo Super_Hippo

2017/5/16

#
Have a int variable in the predator class, increase it by one whenever it eats a fish. Then, when it hits 5, add a new predator.
SprayNPray SprayNPray

2017/5/17

#
What would this code look like? Sorry, I"m somewhat new to Greenfoot.
danpost danpost

2017/5/17

#
SprayNPray wrote...
What would this code look like? Sorry, I"m somewhat new to Greenfoot.
What have you tried? Hippo suggested how.
SprayNPray SprayNPray

2017/5/17

#
I tried: if (showCounter = 5) { Predator myPredator = new Predator(); int LocationX = Greenfoot.getRandomNumber(550); int LocationY = Greenfoot.getRandomNumber(550); addObject(myPredator, LocationX, LocationY); } showCounter shows the number of fish eaten by the Predator. All of the Predator spawning code is the code underneath if (showCounter = 5) It states that I have incompatible types: int cannot be converted to boolean. When I try to use a different variable or put int in front, it says I need a .class in front or it says that it is a illegal start of the expression. None of the variables I use seem to work tho. Maybe i'm putting the code in the wrong class? I tried moving it but it didn't work. I am trying to place the code in myWorld.
danpost danpost

2017/5/18

#
A single equal sign is an assignment operation, which in this case assigns 5 to the variable showCounter. To compare 5 to the current value of showCounter, use a double equals sign, the equality comparison operator.
You need to login to post a reply.