I have a space ship and I want to make it fire at enemy ships. How do I do this?
public void act()
{
setLocation(getX(), getY() - 1); //this will move the bullet up.
//(getX(), getY() + 1) is down
//(getX() + 1, getY()) is right
//(getX() - 1, getY()) is left
}public void shoot()
{
getWorld().addObject(new Bullet(), getX, getY); //this will add a new Bullet object (change the name to whatever you want to call the bullet/projectile class) to the world at the spaceships location.
}public void act()
{
if (Greenfoot.isKeyDown("space"))
{
shoot();
}
}