diff --git a/src/lists/Airplane.java b/src/lists/Airplane.java index c866b5a3e4091bb138524db7814b159d6651f3e5..3bee4ac675a266e79bc9e712cd61fd3633c68dea 100644 --- a/src/lists/Airplane.java +++ b/src/lists/Airplane.java @@ -3,12 +3,27 @@ package lists; import bagel.Input; import bagel.util.Point; import bagel.util.Vector2; + +import java.util.ArrayList; import java.util.List; +import java.util.Random; + public class Airplane extends Sprite{ + private static final String EXPLOSIVE_FILE = "res/images/explosive.png"; private static final int HEIGHT = 768; private static final int WIDTH = 1024; + private static final double TIME_MIN = 1; + private static final double TIME_MAX = 2; + private final List<Explosive> explosives; + + private double speed; private boolean finished, isVertical; + private double frameCount; + private Random r = new Random(); + private double nothingTime; + + @@ -17,12 +32,15 @@ public class Airplane extends Sprite{ this.speed = 1.5; this.finished = false; this.isVertical = isVertical; + this.frameCount = Integer.MAX_VALUE; + this.nothingTime = Math.round((TIME_MIN + (TIME_MAX - TIME_MIN) * r.nextDouble())*1000); + this.explosives = new ArrayList<>(); } @Override public void update(Input input) { - + frameCount += ShadowDefend.getTimescale(); if (finished) { return; } @@ -33,7 +51,7 @@ public class Airplane extends Sprite{ if(isVertical){ targetPoint = new Point(currentPoint.x,currentPoint.y + 3); - setAngle(Math.PI*(3/2)); + setAngle(Math.PI); } @@ -41,28 +59,30 @@ public class Airplane extends Sprite{ Vector2 current = currentPoint.asVector(); Vector2 distance = target.sub(current); - // Update current rotation angle to face target point - - - // Obtain where we currently are, and where we want to be - //Point currentPoint = getCenter(); - //Point targetPoint = polyline.get(targetPointIndex); - // Convert them to vectors to perform some very basic vector math - //Vector2 target = targetPoint.asVector(); - //Vector2 current = currentPoint.asVector(); - //Vector2 distance = target.sub(current); - // Distance we are (in pixels) away from our target point double magnitude = distance.length(); - // Check if we are close to the target point - + if (frameCount*1000 / ShadowDefend.FPS >= nothingTime &&(currentPoint.x < WIDTH && currentPoint.y < HEIGHT)) { + explosives.add(new Explosive(currentPoint,EXPLOSIVE_FILE)); + nothingTime = Math.round((TIME_MIN + (TIME_MAX - TIME_MIN) * r.nextDouble())*1000); + frameCount = 0; + } // Check if we have reached the end - if (currentPoint.x >= WIDTH || currentPoint.y >= HEIGHT) { + if ((currentPoint.x >= WIDTH || currentPoint.y >= HEIGHT) && explosives.isEmpty()) { System.out.println("out"); finished = true; return; } + for (int i = explosives.size() - 1; i >= 0; i--) { + if(!explosives.isEmpty()){ + System.out.println(explosives); + Explosive v = explosives.get(i); + v.update(input); + if (v.isFinished()) { + explosives.remove(i); + } + } + } // Move towards the target point // We do this by getting a unit vector in the direction of our target, and multiplying it // by the speed of the slicer (accounting for the timescale) diff --git a/src/lists/Explosive.java b/src/lists/Explosive.java new file mode 100644 index 0000000000000000000000000000000000000000..837b1734c6551ff0d778a791134e62813695f677 --- /dev/null +++ b/src/lists/Explosive.java @@ -0,0 +1,46 @@ +package lists; + +import bagel.Input; +import bagel.util.Point; + +import java.util.Random; + +public class Explosive extends Sprite{ + private static final double COOLDOWN = 2000; + private double radius,damage,frameCount; + private boolean finished; + + + + + + + public Explosive(Point point, String imageSrc){ + super(point,imageSrc); + this.radius = 200; + this.damage = 500; + + this.finished = false; + this.frameCount = 0; + + } + + @Override + public void update(Input input) { + frameCount += ShadowDefend.getTimescale(); + if (finished) { + return; + } + if (frameCount*1000 / ShadowDefend.FPS >= COOLDOWN) { + + finished = true; + + } + super.update(input); + } + public boolean isFinished() { + return finished; + } + + +} diff --git a/src/lists/ShadowDefend.java b/src/lists/ShadowDefend.java index a60ca9fa251d684f2405ce0bd1ec66c0b8be8ec8..202caf2446a9a048147ac3f929286b4c0a573c59 100644 --- a/src/lists/ShadowDefend.java +++ b/src/lists/ShadowDefend.java @@ -3,7 +3,7 @@ package lists; import bagel.*; import bagel.Font; import bagel.Image; -import bagel.Window; + import bagel.map.TiledMap; import bagel.util.Colour; import bagel.util.Point; diff --git a/src/lists/Sprite.java b/src/lists/Sprite.java index 88a7029bc8fdb83f98c1dd058d0f3d5c8dda18f4..81609b54b2d7167441c34c9bc5717bdd36307ada 100644 --- a/src/lists/Sprite.java +++ b/src/lists/Sprite.java @@ -26,6 +26,7 @@ public abstract class Sprite { this.image = new Image(imageSrc); this.rect = image.getBoundingBoxAt(point); this.angle = 0; + } diff --git a/src/lists/SuperTank.java b/src/lists/SuperTank.java index 96a1398123b39f8d1e87dc026232698106cdb9d5..2b5778e675d86a1295473a9fb98062293deee181 100644 --- a/src/lists/SuperTank.java +++ b/src/lists/SuperTank.java @@ -2,10 +2,9 @@ package lists; import bagel.Input; import bagel.util.Point; -import bagel.util.Vector2; -import java.util.List; -public class SuperTank extends Sprite{ - private double radius,damage,cooldown; + +public class SuperTank extends Tank{ + public SuperTank(Point point, String imageSrc){ diff --git a/src/lists/Tank.java b/src/lists/Tank.java index 102f8a849d72cd3f99ee79fcedd5dd4f598608a7..f44c83560c4cfd5234d6d9f43dc99fe0376eaca5 100644 --- a/src/lists/Tank.java +++ b/src/lists/Tank.java @@ -2,10 +2,9 @@ package lists; import bagel.Input; import bagel.util.Point; -import bagel.util.Vector2; -import java.util.List; + public class Tank extends Sprite{ - private double radius,damage,cooldown; + protected double radius,damage,cooldown; public Tank(Point point, String imageSrc){ @@ -19,7 +18,7 @@ public class Tank extends Sprite{ @Override public void update(Input input) { - //setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x)); + super.update(input); }