Hey guys.. in my code i have two getKey commands... But it's only the first one that is being used. So the second getKey command does not work. However, if i delete the first getKey command, the other one works..
Here's my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Skydemand here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Skydemand extends SmoothMover
{
int change = 0;
/**
* Act - do whatever the Skydemand wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moving();
shooting();
}
/**
* moving the object
*/
private void moving()
{
if (Greenfoot.isKeyDown("d")) change++;
if (Greenfoot.isKeyDown("a")) change--;
if("w".equals(Greenfoot.getKey()))
{
change=change+180;
}
setRotation(change);
setLocation(getWorld().getWidth()/2, getWorld().getHeight()/2);
move(65);
}
private void shooting()
{
if("space".equals(Greenfoot.getKey()))
{
fire();
}
}
/**
* Fire the cannon
*/
private void fire()
{
Bullet bullet = new Bullet();
getWorld().addObject(bullet,getX(),getY());
bullet.setRotation(getRotation());
bullet.move(40.0);
}
}
