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

2011/5/25

Help with "shooting game"

KHSquestions KHSquestions

2011/5/25

#
I am currently coding a game which includes two "players" shooting at each other. The first player works, and shoots when the spacebar is pressed. I am having a problem with the second player and the shooting. Their fires methods are identical and the "bullet" methods are too. the only difference is the button that each player uses to fire. It seems greenfoot will only allow one player to fire at a time, and I cannot figure out why.
mjrb4 mjrb4

2011/5/25

#
It could be all sorts of things, without seeing the code it'll just be a case of wild guesses! Can you upload the scenario with the source so we can see what's going on?
KHSquestions KHSquestions

2011/5/26

#
here are the two player and bullet classes(each seperated by braces)(this one works and shoots)
nccb nccb

2011/5/26

#
I think your problem is:
public class Domo extends BulletBill
Because Domo is a BulletBill, when Player fires a Domo, the Domo still intersects the Player next round -- when the Player looks for an intersecting BulletBill. It finds the Domo and removes it from the world, so each Domo will only be in the world for one frame before it hits the Player who fired it! You want:
public class Domo extends Mover
In fact, I'd question whether you need four classes at all -- I think two will do, one player class and one bullet class. Rather than copy and paste your code and tweak it (which means every time you want to change the bullets, you need to do it in two places!), have one player class that takes its keys as parameters to the constructor (or have set methods), and one bullet class, but follow up on the getOneIntersectingObject call by casting the bullet class and asking who fired it (to then check and make sure each player is only hit by bullets from *other* players).
You need to login to post a reply.