import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Spaceship here. * * @author Jannis Andrija Schnitzer * @version 2011-01-16 */ public class Spaceship extends QuantumObject { /** * Act - do whatever the Spaceship wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { super.act(); for (int i = 0; i < N_GUNS; i++) { if (guns[i] != null) guns[i].tick(); } } protected static int N_GUNS = 3; protected Gun[] guns; public Spaceship() { guns = new Gun[N_GUNS]; guns[0] = null; guns[1] = null; guns[2] = null; // set height to some value, used for calculation of starting point } public void addGun(int position, Gun new_gun) { guns[position] = new_gun; } public void removeGun(int position) { guns[position] = null; } protected void fire() { int x = getX(); int y = getY(); World world = getWorld(); for (int i = 0; i < N_GUNS; i++) { if (guns[i] != null) { Missile m = guns[i].missile(); if (m != null) world.addObject(m, x + guns[i].get_dx(), y - guns[i].get_dy()); // subtracting dy here because greenfoot has 0,0 at the top left corner } } } }