So, I want 2 Objects to be moved by getKey(). After I saw that it is not possible to have 2 getKeys at the time, I tried to use to use the 2 getKeys.
Here's my code:
The code for the 2. Player is pretty much the same, the only thing different is that I want the CTRL key for the 2. Player and not the space bar.
And I don't want to use isKeyDown(), because then you can just hold the space bar/ctrl key to move forward. I want the players to repeatedly tab on the space bar / ctrl key to get along.
Hope that someone can help me with this issue.
String key = Greenfoot.getKey();
import lang.stride.*;
import java.util.*;
import greenfoot.*;
/**
*
*/
public class PlayerOne extends Actor
{
private String key = Greenfoot.getKey();
/**
* Act - do whatever the Am wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (key != null && "space".equals(key)) {
this.move(3);
}
if (this.isAtEdge()) {
getWorld().showText("Player1 wins!", this.getWorld().getWidth() / 2, this.getWorld().getHeight() / 2);
getWorld().showText("Press the reset button if you want to play again.", this.getWorld().getWidth() / 2, 220);
Greenfoot.stop();
}
}
}
