I'm doing this for my school project and its going good. My Hero shoots and the bullets disappear when it hits the edge but I can't seem to shoot the enemy and I need help. I got this code from another thread for basis, here's the code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Actor
{
private int direction, speed;
public Bullet(int dir)
{
direction = dir;
speed = 15;
}
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
isWorldEdge();
setRotation(direction);
move(speed);
}
public void isWorldEdge()
{
if(atWorldEdge() == true )
{
World world;
world = getWorld();
world.removeObject(this);
}
}
public boolean atWorldEdge()
{
if(getX() < 20 || getX() > getWorld().getWidth() - 20)
return true;
if(getY() < 20 || getY() > getWorld().getHeight() - 20)
return true;
else
return false;
}
}


