package iat265.lab.w09.simulation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import iat265.lab.w09.main.PacmanPanel;
import processing.core.PVector;
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.