You set the key for each player with the setShootKey method.
player.pipe.setShootKey("o");
player2.pipe.setShootKey("e");public void setShootKey(String key)
{
shootKey = key;
}player.setShootKey("o");public class Player extends Actor
{
int playerNum;
Pipe pipe = new Pipe();
...
public Player(int num)
{
playerNum = num;
if (num == 0)
{
...
}
else
{
...
}
...
}
protected void addedToWorld(World world)
{
world.addObject(pipe, getX(), getY());
}
...
public class Pipe extends Actor
{
String shootKey;
public Pipe()
{
shootKey = this.Player.playerNum == 0 ? "o", "e";
GreenfootImage img = new GreenfootImage("Rohr"+(this.Player.playerNum+1)+".PNG");
img.scale(25, 25);
setImage(img);
}
public void act()
{
if (this.Player.getWorld() == null) { getWorld().removeObject(this); return; }
...
}
}
}shootKey = this.Player.playerNum == 0 ? "o", "e";
if (A)
{
B;
}
else
{
C;
}A ? B : C;