I can I make an enemy actor shoot randomly with least a two second wait and then the bullet follows another actor.
//in your bullet class:
public Bullet(int rotation) {
setRotation(rotation);
}//in your enemy class:
public void shoot() {
getWorld().addObject(new Bullet(Greenfoot.getRandomNumber(360), getX(), getY());
}//in your bullet class:
public Bullet(int rotation) {
setRotation(rotation);
I want the bullet to follow my "monster" class for only 5 seconds then the bullet disappears.
}//in your enemy class:
public void shoot() {
getWorld().addObject(new Bullet(Greenfoot.getRandomNumber(360), getX(), getY());
}turnTowards(followedActor.getX(), followedActor.getY());
turnTowards(followedActor.getX(), followedActor.getY());
public class EnemyTruck extends Truck implements LandUnit
{
private static final int ROTATION_SPEED = 3;
private static final double ACCELERATION = .1;
private static final double MAX_SPEED = 4;
private GreenfootImage background;
private boolean Startgame = false;
private boolean clicked = false;
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
public void act()
{
//moveAround();
shootPlayer();
}
//shoot player if player is nearby
public void shootPlayer()
{
if (canSee (Soldier.class))
{
getWorld().addObject(new Projectile(Greenfoot.getRandomNumber(250), getX(), getY());
}
}
}