When I use the getKey() method I can only seem to get it to work on one key. As in I can put if("space".equals(Greenfoot.getKey())) and if("q".equals(Greenfoot.getKey())) but it will only work for space not q. any help appreciated
public class MainCharacter extends Actor { public int vSpeed = 0; public int walk = 0; private GreenfootImage imag; public int acceleration = 2; private GreenfootImage image1 = new GreenfootImage("IceMan-Facing-Right.png"); private GreenfootImage image2 = new GreenfootImage("IceMan-Running-Right.png"); private GreenfootImage image7 = new GreenfootImage("IceMan-Facing-Left.png"); private GreenfootImage image8 = new GreenfootImage("IceMan-Running-Left.png"); public int direc = 0; public int dir = 0; public int shot = 0; /** * Act - do whatever the MainCharacter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public MainCharacter() { setImage (image1); } public void act() { checkShoot(); checkJump(); fallCheck(); walk(); checkDir(); } public void checkDir() { if (shot == 1) { dir = 1; direc = 36; } if (shot == 2) { dir = 1; direc = 36; } if (shot == 7) { dir = 0; direc = -36; } if (shot == 8) { dir = 0; direc = -36; } } public void walk() { walk++; if(Greenfoot.isKeyDown("right")) { walkRight(); } if(Greenfoot.isKeyDown("left")) { walkLeft(); } } public void walkRight() { if(walk<10) { setImage(image1); shot = 1; } if(walk>10) { setImage(image2); shot = 2; } if (walk > 20) { walk = 0; } } public void walkLeft() { if(walk<10) { setImage(image7); shot = 7; } if(walk>10) { setImage(image8); shot = 8; } if (walk > 20) { walk = 0; } } public void fallCheck() { if (onPlatform()) { vSpeed = 0; } else { fall(); } } public boolean onPlatform() { Actor uPlat = getOneObjectAtOffset(0,getImage().getHeight()/2,Platform.class); return uPlat != null; } public boolean touchPlatform() { Actor uPlat = getOneObjectAtOffset(getImage().getWidth()/2,0,Platform.class); return uPlat != null; } public void fall() { setLocation (getX(),getY() + vSpeed); vSpeed = vSpeed + acceleration; } public void jump() { vSpeed = -16; fall(); } public void checkJump() { if("space".equals(Greenfoot.getKey())) { jump(); } } public void checkShoot() { if("z".equals(Greenfoot.getKey())) { shootIce(); } } public void shootIce() { getWorld().addObject(new Iceshot(dir),getX()+direc,getY()); } }
String key = Greenfoot.getKey();