Skip to content
Snippets Groups Projects
Commit 1f144193 authored by David Lin's avatar David Lin
Browse files

implemented explosives spawns

parent 1fa401c4
Branches
No related tags found
No related merge requests found
...@@ -3,12 +3,27 @@ package lists; ...@@ -3,12 +3,27 @@ package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2; import bagel.util.Vector2;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
public class Airplane extends Sprite{ 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 HEIGHT = 768;
private static final int WIDTH = 1024; 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 double speed;
private boolean finished, isVertical; private boolean finished, isVertical;
private double frameCount;
private Random r = new Random();
private double nothingTime;
...@@ -17,12 +32,15 @@ public class Airplane extends Sprite{ ...@@ -17,12 +32,15 @@ public class Airplane extends Sprite{
this.speed = 1.5; this.speed = 1.5;
this.finished = false; this.finished = false;
this.isVertical = isVertical; 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 @Override
public void update(Input input) { public void update(Input input) {
frameCount += ShadowDefend.getTimescale();
if (finished) { if (finished) {
return; return;
} }
...@@ -33,7 +51,7 @@ public class Airplane extends Sprite{ ...@@ -33,7 +51,7 @@ public class Airplane extends Sprite{
if(isVertical){ if(isVertical){
targetPoint = new Point(currentPoint.x,currentPoint.y + 3); 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{ ...@@ -41,28 +59,30 @@ public class Airplane extends Sprite{
Vector2 current = currentPoint.asVector(); Vector2 current = currentPoint.asVector();
Vector2 distance = target.sub(current); 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(); 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 // 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"); System.out.println("out");
finished = true; finished = true;
return; 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 // Move towards the target point
// We do this by getting a unit vector in the direction of our target, and multiplying it // 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) // by the speed of the slicer (accounting for the timescale)
......
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;
}
}
...@@ -3,7 +3,7 @@ package lists; ...@@ -3,7 +3,7 @@ package lists;
import bagel.*; import bagel.*;
import bagel.Font; import bagel.Font;
import bagel.Image; import bagel.Image;
import bagel.Window;
import bagel.map.TiledMap; import bagel.map.TiledMap;
import bagel.util.Colour; import bagel.util.Colour;
import bagel.util.Point; import bagel.util.Point;
......
...@@ -26,6 +26,7 @@ public abstract class Sprite { ...@@ -26,6 +26,7 @@ public abstract class Sprite {
this.image = new Image(imageSrc); this.image = new Image(imageSrc);
this.rect = image.getBoundingBoxAt(point); this.rect = image.getBoundingBoxAt(point);
this.angle = 0; this.angle = 0;
} }
......
...@@ -2,10 +2,9 @@ package lists; ...@@ -2,10 +2,9 @@ package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List; public class SuperTank extends Tank{
public class SuperTank extends Sprite{
private double radius,damage,cooldown;
public SuperTank(Point point, String imageSrc){ public SuperTank(Point point, String imageSrc){
......
...@@ -2,10 +2,9 @@ package lists; ...@@ -2,10 +2,9 @@ package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List;
public class Tank extends Sprite{ public class Tank extends Sprite{
private double radius,damage,cooldown; protected double radius,damage,cooldown;
public Tank(Point point, String imageSrc){ public Tank(Point point, String imageSrc){
...@@ -19,7 +18,7 @@ public class Tank extends Sprite{ ...@@ -19,7 +18,7 @@ public class Tank extends Sprite{
@Override @Override
public void update(Input input) { public void update(Input input) {
//setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x));
super.update(input); super.update(input);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment