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

2015/6/1

Need help creating shooting command

emadrid3 emadrid3

2015/6/1

#
I am currently working on a simple game where you are a tank collecting crystals, you can be destroyed by a bomb the bomb and crystal falls randomly, I want to be able to fire a shell that will destroy the bomb. I am using the animal class to make the tank "eat" the crystal and the bombs "eat" the tank but i need help firing the shell then destroying the bomb.
danpost danpost

2015/6/1

#
I would consider the Animal class to be obsolete. Methods have been added directly into the Actor class to perform the 'canSee' (see 'isTouching') and the 'eat' (see 'removeTouching'), as well as the 'atWorldEdge' (see 'isAtEdge') method. This leaves the 'move' method which uses the 'WALKING_SPEED' field, where the field is a class constant. As such, all objects of all subclasses must use that same speed. That gives a heavy restriction on the 'move' method of the Animal class. So, you can see that there really is no usefulness in any Actor class to have the Animal class as a superclass. Having the shells destroy the bombs is simply having the shells 'eat' the bomb that it 'canSee' (or removing a bomb that is touched). In this case, however, you may also want the shell removed when it removes a bomb. Having the tank create a shell requires a trigger (what causes the creation of a shell -- or what triggers a shell to be fired). The tank will be doing this action, so the act method of the class of the tank would be the appropriate place for the code (or in a method that act method calls). Depending on what is used for the trigger, you may have to regulate the rate of shell firing.
emadrid3 emadrid3

2015/6/2

#
Hey I got it down. I used a firing method similar to that of Greenfoot Space Invaders. From there I used the animal class to make the shell eat the bomb then a destroy command.
You need to login to post a reply.