Missile

public class Missile extends SimulationObject implements Mover { private PVector speed; private Ellipse2D missile; public Missile(float x, float y, float speedx, float speedy) { super(x, y, 10, 5, 1f); speed = new PVector(speedx, speedy); } @Override public void drawObject(Graphics2D g) { AffineTransform at = g.getTransform(); g.translate(pos.x, pos.y); g.scale(size, size); g.rotate(speed.heading()); g.setColor(Color.BLACK); g.fill(missile); g.setTransform(at); } @Override public void drawInfo(Graphics2D g2) { // nothing to do here } @Override public void update(ArrayList<SimulationObject> objList, PacmanPanel panel) { Rectangle2D env = new Rectangle2D.Double(0,0,panel.PNL_SIZE.width, panel.PNL_SIZE.height); if (!env.contains(pos.x, pos.y)) { objList.remove(this); return; } move(); for (SimulationObject obj:objList) if (obj != this && !(obj instanceof PlayerPacman) && isColliding(obj)) { // someone got shot objList.remove(obj); break; } } @Override protected void setShapeAttributes() { missile = new Ellipse2D.Double(-dim.width/2, -dim.height/2, dim.width, dim.height); } @Override protected void setOutline() { outline = new Area(missile); } @Override protected Shape getOutline() { AffineTransform at = new AffineTransform(); at.translate(pos.x, pos.y); at.scale(size, size); at.rotate(speed.heading()); return at.createTransformedShape(outline); } @Override public void move() { pos.add(speed); } @Override public void approach(SimulationObject obj) { // nothing to do here } @Override public void checkCollision(PacmanPanel pnl) { // nothing to do here } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.