For my school project I need my main character that moves right,left, down and up with shooting keys K,M,O,L to shoot in four directions. my actor is a car, and i need to shoot from the front and back from the left right sides. this my existing code:
/**
* keyboard control
*/
public void keyMove()
{
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-12);
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY()+12);
}
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-30, getY());
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+12, getY());
}
if(Greenfoot.isKeyDown("k"))
{
getWorld().addObject(new Fla (), getX(), getY()); (Front left ammo)
}
if(Greenfoot.isKeyDown("l"))
{
getWorld().addObject(new Rba (), getX(), getY()); (Right back ammo)
}
if(Greenfoot.isKeyDown("m"))
{
getWorld().addObject(new La (), getX(), getY()); (Left ammo)
}
if(Greenfoot.isKeyDown("o"))
{
getWorld().addObject(new Fra (), getX(), getY()); (Front right ammo)
}
// kpoliceFire(Greenfoot.isKeyDown("K"));
// if(Greenfoot.isKeyDown("K"))
// {
// fire();
// }
}
This is my existing bullet codes:
Rba
public void act()
{
setLocation(getX()-2, getY());
if (isAtEdge())
getWorld().removeObject(this);
}
La
{
setLocation(getX()-40, getY());
// Touching();
if (isAtEdge())
getWorld().removeObject(this);
}
Fla
{
setLocation(getX()+20, getY());
if (isAtEdge())
getWorld().removeObject(this);
}
{
setLocation(getX()+16, getY());
if (isAtEdge())
getWorld().removeObject(this);
}
O dont know the right code and its really bothering me. Thanks!

