I want to code a game where two players try to hit the same thing. The code for the shooting of Player 1 looks like this:
I'm using the getKey()-method instead of the isKeyDown()-method because latter one doesn't seem to work properly: the first one just shoots once, and the second one shoots as long as the key is pressed.
For Player 2 the code is almost the same, but using the "space"-key instead of the "down"-key. But Greenfoot doesn't react on this. It only reacts when Player 1 is dead and does not exist anymore.
Any idea what is the problem and how to solve it? Or any different idea how to do two players shooting?
if ("down".equals(Greenfoot.getKey())) {
Bullet bullet = new Bullet();
int x = getX();
int y = getY();
int r = getRotation();
bullet.setRotation(r);
getWorld().addObject(bullet, x, y);
}

