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

2017/12/3

TankWars Questions

abot1776 abot1776

2017/12/3

#
Hey everyone! I am back with another few questions on a Tank Wars project I am working on. First, my tanks don't always stop when moving through walls. In order to fix this, I made them turn when they hit a wall, but I would much rather have it where they just stop moving when they hit the walls (my way doesn't work anyways). Second, I have a similar issue with the cannonballs I shoot, except sometimes the cannonballs zig zag through a single wall before exiting on the end of that wall. Finally, my right tank dies when I shoot a cannonball from it even though the left tank does not. The two codes for each tank are exactly identical (see Cannonball class). If anyone could suggest any improvements to the code to make these changes and/or answer my questions, I would be so grateful. I don't have much experience, so specific answers are better. I have been working for many, many hours to no avail... Link (May need to download):
abot1776 abot1776

2017/12/3

#
Just curious, but does anyone have an answer to any one of those questions?
Super_Hippo Super_Hippo

2017/12/3

#
Try to move the tank, then check it is is touching a wall and if they do, move back. This way you won't stop "inside" a wall. The right tank dies after shooting because the bullet moves to the right, bounces back and destroys the tank. The same happens with the left tank, the bullet just has a little longer way.
abot1776 abot1776

2017/12/3

#
What about the cannonball? Also, what do you mean by check if it is touching a wall? Like getObectIntersecting?
Super_Hippo Super_Hippo

2017/12/4

#
When I run the scenario, both tanks kill themselves when shooting, so I don't know why you said the tanks acted differently. With touching I mean something like:
int s = 0;
if (Greenfoot.isKeyDown("e") s++;
if (Greenfoot.isKeyDown("d") s--;
move(s);
if (isTouching(Wall.class)) move(-s);
You need to login to post a reply.