import java.awt.*; import java.util.ArrayList; import java.util.ListIterator; public class GunShot extends PlayerObject { public int dy = 0; //hastighet i x-led public int dx = 0; //hastighet i y-led public double speed = 4.0; //šnskad fšrflyttningshastighet public double normDirectionX; //normaliserade vektorn public double normDirectionY; //normaliserade vektorn public GunShot() { this.polygon.addPoint(x, y); this.polygon.addPoint(x, y + height); this.polygon.addPoint(x + width, y + height); this.polygon.addPoint(x + width, y); } public void setSpeed(double s) { this.speed = s; } public void friendlyCollission() { this.exists = false; } public void setDirection(double normDirectionX, double normDirectionY) { if (!(normDirectionY == 0) || !(normDirectionX == 0)) { this.normDirectionX = normDirectionX; this.normDirectionY = normDirectionY; } } public void draw(Graphics g) { g.setColor(Color.BLACK); g.fillOval(x, y, width, height); //Ritar ut objektet i vald fŠrg } public void clockTick() { this.x += (int) (speed * normDirectionX); this.y += (int) (speed * normDirectionY); Polygon polly = new Polygon(); polly.addPoint(x, y); polly.addPoint(x, y + height); polly.addPoint(x + width, y + height); polly.addPoint(x + width, y); this.polygon = polly; } /* public void checkCollission(ArrayList list) { ListIterator i1 = list.listIterator(); while (i1.hasNext()) { GameObject object = (GameObject) i1.next(); // Följande if-sats kontrollerar om baronens polygon krockar med objektets bound-rektangel // En bound-rektangel är den minsta möjliga rektangel som kan innersluta ett helt objekt. if (polyIntersects(this.polygon, object.getPolygon()) && !(object instanceof GunShot) && !(object instanceof MovingObject)) { //tar bort sig själv this.exists = false; // Skriver ut lite mumbo Jumbo System.out.print("Kolission: "); for (int i = 0; i < this.polygon.xpoints.length; i++) { System.out.print(this.polygon.xpoints[i] + " "); } System.out.print(" "); for (int i = 0; i < this.polygon.ypoints.length; i++) { System.out.print(this.polygon.ypoints[i] + " "); } System.out.print(" "); for (int i = 0; i < object.getPolygon().xpoints.length; i++) { System.out.print(object.getPolygon().xpoints[i] + " "); } System.out.print(" "); for (int i = 0; i < object.getPolygon().ypoints.length; i++) { System.out.print(object.getPolygon().ypoints[i] + " "); } System.out.println(" "); if (object.isEnemy()) { //Baronen skall dö och Game Over } else { //Nu ska baronen inte kunna åka i den riktningen som objektet finn i } } } } */ }