import java.awt.*; import java.awt.geom.*; import java.util.Vector; import physics2D.*; public class Space { private Plane2D space; private Vector ships; private SpaceShip userShip; private Image image; private Graphics2D graphics2D; private Color backgroundColor = new Color(0,0,0); private int width; private int height; public Space(int width, int height, Image image) { space = new Plane2D(); ships = new Vector(); userShip = new SpaceShip(new Vector2D(400,400, true), .10); userShip.setVelocity(new Vector2D(120,0,true)); ships.add(userShip); space.add(userShip); SpaceShip ship2 = new SpaceShip(new Vector2D(400,200, true), .10); ship2.setVelocity(new Vector2D(-120,0,true)); ships.add(ship2); space.add(ship2); SpaceShip ship3 = new SpaceShip(new Vector2D(300,300, true), .10); ship3.setVelocity(new Vector2D(0,120,true)); ships.add(ship3); space.add(ship3); SpaceShip ship4 = new SpaceShip(new Vector2D(500,300, true), .10); ship4.setVelocity(new Vector2D(0,-120,true)); ships.add(ship4); space.add(ship4); Star ship5 = new Star(new Vector2D(400,300, true), .10); ship5.setVelocity(new Vector2D(0,0,true)); ships.add(ship5); space.add(ship5); SpaceShip ship6 = new SpaceShip(new Vector2D(400,500, true), .10); ship6.setVelocity(new Vector2D(-80,0,true)); ships.add(ship6); space.add(ship6); SpaceShip ship7 = new SpaceShip(new Vector2D(400,100, true), .10); ship7.setVelocity(new Vector2D(80,0,true)); ships.add(ship7); space.add(ship7); SpaceShip ship8 = new SpaceShip(new Vector2D(200,300, true), .10); ship8.setVelocity(new Vector2D(0,-80,true)); ships.add(ship8); space.add(ship8); SpaceShip ship9 = new SpaceShip(new Vector2D(600,300, true), .10); ship9.setVelocity(new Vector2D(0,80,true)); ships.add(ship9); space.add(ship9); this.width = width; this.height = height; this.image = image; graphics2D = (Graphics2D) image.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); } public void advanceTime(int increment) { space.advanceTime(increment); } public Image getImage() { graphics2D.setPaint(backgroundColor); graphics2D.fill(new Rectangle(width, height)); Drawable d; for (int i = 0; i < ships.size(); i++) { d = (Drawable) ships.get(i); Shape[] shapes = d.getShapes(); Color[] colors = d.getColors(); for (int j = shapes.length - 1; j >= 0; j--) { graphics2D.setPaint(colors[j]); graphics2D.fill(shapes[j]); } } return image; } public SpaceShip getUserShip() { return userShip; } }