import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * That would be a spaceship that's flying around on its own, and doesn't need a player to steer it. * * @author Jannis Andrija Schnitzer, Martin Schend * @version 2011-01-21 */ public class AIControlledSpaceship extends Spaceship { /** * The initial speed the spaceship gets assigned on creation. */ protected static double initial_speed; /** * The random deviation that is added to or removed from the inital speed on creation. */ protected static double speed_deviation; public AIControlledSpaceship(int the_level) { super(the_level); hitpoints = max_hitpoints = level * 100; // TODO: add some kind of gun. initial_speed = .5; speed_deviation = 0.0; } public void act() { super.act(); // TODO: add some kind of shooting logic. } public static void setInitialSpeed(double speed) { initial_speed = speed; } public static double getInitialSpeed() { return initial_speed; } public static void setDeviation(double deviation) { speed_deviation = deviation; } public static double getDeviation() { return speed_deviation; } public void beforeDestruction() { int x, y; InvadersWorld world; x = getX(); y = getY(); world = (InvadersWorld) getWorld(); world.maybeCreateCollectible(x, y, side); } public boolean hit(ManuallyControlledSpaceship s) { if (s.getSide() == side) // one of our ships return true; else { ((InvadersWorld) getWorld()).maybeCreateCollectible(getX(), getY(), side); return false; } } }