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

2013/5/2

What's the best method ?

Solringolt Solringolt

2013/5/2

#
I want to make an enemy that each part could be shot down so that we can kill maybe first the arms then the legs then the head or in a different order. I first thought about making an actor for each part but like this it become very code heavy and as soon as I want to use a Greenfoot Random number they won't have the same value for each part. They should have some even functions like movement and interaction with the world but also personal stuff like: this part can shoot, this one has more life, and so on. What do you suggest me to do for such stuff?
bourne bourne

2013/5/2

#
I would have an Actor for the head (If the head was to be killed last) that would manage Actors for the different parts. So the head would mainly deal with overall movement of the entire "body" and could send messages via methods to its parts, while the different parts have their own healths, listen for being "shot"/damaged, and maybe have some certain behaviors that include animation/shooting projectiles etc.
Solringolt Solringolt

2013/5/2

#
that's the problem everything should be killable first... Is tere a way to stock a Greenfoot random number and then use it for many actors? that would probably solve my problem.
bourne bourne

2013/5/2

#
You can store a random number within an int which can be distributed/shared.
Solringolt Solringolt

2013/5/2

#
But won't it be the same number at each act after?
bourne bourne

2013/5/2

#
Yes. So you are wanting to generate a random number each act cycle, that then is the same for all parts? If you don't have some sort of central persisting part like the head, I would have a class (not an Actor) that has all the parts stored, which can generate the random number, and then give it to all the parts. Instances of this new class could be stored in like the World or some sort of central control place, which can call upon the class to "act" at every act cycle.
Solringolt Solringolt

2013/5/2

#
Ok thx I think that's the way I should take, now let's code! ^^
Solringolt Solringolt

2013/5/2

#
Yeah thx works great like this, I have many actors but it works ^^ I didn't needed the Instance I just put the variable declaration in the parent act class.
You need to login to post a reply.