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

implemented tower shooting

parent 1f144193
No related branches found
No related tags found
No related merge requests found
...@@ -8,14 +8,9 @@ import java.util.List; ...@@ -8,14 +8,9 @@ import java.util.List;
/** /**
* A super slicer. * A super slicer.
*/ */
public class ApexSlicer extends Sprite { public class ApexSlicer extends Slicer {
private static final String IMAGE_FILE = "res/images/slicer.png";
protected double speed,health,reward,penalty;
private final List<Point> polyline;
private int targetPointIndex;
private boolean finished;
/** /**
* Creates a new Slicer * Creates a new Slicer
...@@ -23,10 +18,7 @@ public class ApexSlicer extends Sprite { ...@@ -23,10 +18,7 @@ public class ApexSlicer extends Sprite {
* @param polyline The polyline that the slicer must traverse (must have at least 1 point) * @param polyline The polyline that the slicer must traverse (must have at least 1 point)
*/ */
public ApexSlicer(List<Point> polyline,String imageSrc) { public ApexSlicer(List<Point> polyline,String imageSrc) {
super(polyline.get(0), imageSrc); super(polyline, imageSrc);
this.polyline = polyline;
this.targetPointIndex = 1;
this.finished = false;
this.speed = 0.375; this.speed = 0.375;
this.health = 25; this.health = 25;
...@@ -41,39 +33,9 @@ public class ApexSlicer extends Sprite { ...@@ -41,39 +33,9 @@ public class ApexSlicer extends Sprite {
*/ */
@Override @Override
public void update(Input input) { public void update(Input input) {
if (finished) {
return;
}
// 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 (magnitude < speed * ShadowDefend.getTimescale()) {
// Check if we have reached the end
if (targetPointIndex == polyline.size() - 1) {
finished = true;
return;
} else {
// Make our focus the next point in the polyline
targetPointIndex += 1;
}
}
// 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)
super.move(distance.normalised().mul(speed * ShadowDefend.getTimescale()));
// Update current rotation angle to face target point
setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x));
super.update(input); super.update(input);
} }
public boolean isFinished() {
return finished;
}
} }
...@@ -8,14 +8,9 @@ import java.util.List; ...@@ -8,14 +8,9 @@ import java.util.List;
/** /**
* A super slicer. * A super slicer.
*/ */
public class MegaSlicer extends Sprite { public class MegaSlicer extends Slicer {
private static final String IMAGE_FILE = "res/images/slicer.png";
protected double speed,health,reward,penalty;
private final List<Point> polyline;
private int targetPointIndex;
private boolean finished;
/** /**
* Creates a new Slicer * Creates a new Slicer
...@@ -23,10 +18,7 @@ public class MegaSlicer extends Sprite { ...@@ -23,10 +18,7 @@ public class MegaSlicer extends Sprite {
* @param polyline The polyline that the slicer must traverse (must have at least 1 point) * @param polyline The polyline that the slicer must traverse (must have at least 1 point)
*/ */
public MegaSlicer(List<Point> polyline,String imageSrc) { public MegaSlicer(List<Point> polyline,String imageSrc) {
super(polyline.get(0), imageSrc); super(polyline, imageSrc);
this.polyline = polyline;
this.targetPointIndex = 1;
this.finished = false;
this.speed = 0.75; this.speed = 0.75;
this.health = 2; this.health = 2;
...@@ -41,39 +33,9 @@ public class MegaSlicer extends Sprite { ...@@ -41,39 +33,9 @@ public class MegaSlicer extends Sprite {
*/ */
@Override @Override
public void update(Input input) { public void update(Input input) {
if (finished) {
return;
}
// 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 (magnitude < speed * ShadowDefend.getTimescale()) {
// Check if we have reached the end
if (targetPointIndex == polyline.size() - 1) {
finished = true;
return;
} else {
// Make our focus the next point in the polyline
targetPointIndex += 1;
}
}
// 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)
super.move(distance.normalised().mul(speed * ShadowDefend.getTimescale()));
// Update current rotation angle to face target point
setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x));
super.update(input); super.update(input);
} }
public boolean isFinished() {
return finished;
}
} }
package lists;
import bagel.Input;
import bagel.util.Point;
import bagel.util.Vector2;
public class Projectile extends Sprite {
protected boolean finished;
protected double speed;
protected int damage,slicerIndex;
protected Slicer target;
public Projectile(Point point, Slicer target,int damage,int slicerIndex, String imageSrc){
super(point, imageSrc);
this.target = target;
this.speed = 5;
this.damage = damage;
this.slicerIndex = slicerIndex;
}
@Override
public void update(Input input) {
if (finished) {
return;
}
// Obtain where we currently are, and where we want to be
Point currentPoint = getCenter();
Point targetPoint = target.getCenter();
// Convert them to vectors to perform some very basic vector math
Vector2 targetVector = targetPoint.asVector();
Vector2 currentVector = currentPoint.asVector();
Vector2 distance = targetVector.sub(currentVector);
// Distance we are (in pixels) away from our target point
double magnitude = distance.length();
// Check if we have reached the end
if (getRect().intersects(target.getRect())) {
finished = true;
return;
}
// 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)
super.move(distance.normalised().mul(speed * ShadowDefend.getTimescale()));
// Update current rotation angle to face target point
setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x));
super.update(input);
}
public boolean isFinished() {
return finished;
}
}
package lists;
import bagel.Input;
import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List;
/**
* A regular slicer.
*/
public class RegularSlicer extends Slicer {
/**
* Creates a new Slicer
*
* @param polyline The polyline that the slicer must traverse (must have at least 1 point)
*/
public RegularSlicer(List<Point> polyline,String imageSrc) {
super(polyline, imageSrc);
this.speed = 1;
this.health = 1;
this.reward = 2;
this.penalty = 1;
}
/**
* Updates the current state of the slicer. The slicer moves towards its next target point in
* the polyline at its specified movement rate.
*/
@Override
public void update(Input input) {
super.update(input);
}
}
...@@ -32,6 +32,7 @@ public class ShadowDefend extends AbstractGame { ...@@ -32,6 +32,7 @@ public class ShadowDefend extends AbstractGame {
private static final String SHOP_FILE = "res/images/buypanel.png"; private static final String SHOP_FILE = "res/images/buypanel.png";
private static final String STATUS_FILE = "res/images/statuspanel.png"; private static final String STATUS_FILE = "res/images/statuspanel.png";
private static final String TANK_FILE = "res/images/tank.png"; private static final String TANK_FILE = "res/images/tank.png";
private static final String TANK_PROJ_FILE = "res/images/tank_projectile.png";
private static final String STANK_FILE = "res/images/supertank.png"; private static final String STANK_FILE = "res/images/supertank.png";
private static final String PLANE_FILE = "res/images/airsupport.png"; private static final String PLANE_FILE = "res/images/airsupport.png";
private static final String FONT_FILE = "res/fonts/DejaVuSans-Bold.ttf"; private static final String FONT_FILE = "res/fonts/DejaVuSans-Bold.ttf";
...@@ -54,12 +55,10 @@ public class ShadowDefend extends AbstractGame { ...@@ -54,12 +55,10 @@ public class ShadowDefend extends AbstractGame {
private final Image shop, statusPanel, tankIcon, stankIcon, planeIcon; private final Image shop, statusPanel, tankIcon, stankIcon, planeIcon;
private final List<Point> polyline; private final List<Point> polyline;
private final List<Slicer> slicers; private final List<Slicer> slicers;
private final List<SuperSlicer> superSlicers; private final List<Projectile> projectiles;
private final List<MegaSlicer> megaSlicers;
private final List<ApexSlicer> apexSlicers;
private final List<Tank> tanks; private final List<Tank> tanks;
private final List<SuperTank> stanks;
private final List<Airplane> planes; private final List<Airplane> planes;
private final Rectangle window; private final Rectangle window;
...@@ -70,6 +69,7 @@ public class ShadowDefend extends AbstractGame { ...@@ -70,6 +69,7 @@ public class ShadowDefend extends AbstractGame {
private Font goldDisplay, keyInstruction, costText, statusText; private Font goldDisplay, keyInstruction, costText, statusText;
private Image placingIcon; private Image placingIcon;
private double frameCount; private double frameCount;
private double projCount;
private int spawnedSlicers; private int spawnedSlicers;
private int nothingTime; private int nothingTime;
private int spawnDelay; private int spawnDelay;
...@@ -78,13 +78,14 @@ public class ShadowDefend extends AbstractGame { ...@@ -78,13 +78,14 @@ public class ShadowDefend extends AbstractGame {
private int waveCounter; private int waveCounter;
private int eventCounter; private int eventCounter;
private int prevWaveState; private int prevWaveState;
private int slicerIndex;
private boolean eventWait; private boolean eventWait;
private String enemyType; private String enemyType;
private String placedImage; private String placedImage;
private boolean waveStarted; private boolean waveStarted;
private boolean eventStarted = true; private boolean eventStarted = true;
private boolean isVertical = false; private boolean isVertical = false;
private boolean hasTarget = false;
private static int gold, lives, waveNumber, waveState; private static int gold, lives, waveNumber, waveState;
...@@ -112,12 +113,10 @@ public class ShadowDefend extends AbstractGame { ...@@ -112,12 +113,10 @@ public class ShadowDefend extends AbstractGame {
this.statusText = new Font(FONT_FILE,16); this.statusText = new Font(FONT_FILE,16);
this.polyline = map.getAllPolylines().get(0); this.polyline = map.getAllPolylines().get(0);
this.slicers = new ArrayList<>(); this.slicers = new ArrayList<>();
this.superSlicers = new ArrayList<>(); this.projectiles = new ArrayList<>();
this.megaSlicers = new ArrayList<>();
this.apexSlicers = new ArrayList<>();
this.tanks = new ArrayList<>(); this.tanks = new ArrayList<>();
this.stanks = new ArrayList<>();
this.planes = new ArrayList<>(); this.planes = new ArrayList<>();
this.events = new ArrayList<>(); this.events = new ArrayList<>();
...@@ -126,6 +125,7 @@ public class ShadowDefend extends AbstractGame { ...@@ -126,6 +125,7 @@ public class ShadowDefend extends AbstractGame {
this.spawnedSlicers = 0; this.spawnedSlicers = 0;
this.waveStarted = false; this.waveStarted = false;
this.frameCount = Integer.MAX_VALUE; this.frameCount = Integer.MAX_VALUE;
this.projCount = Integer.MAX_VALUE;
this.waveCounter = 1; this.waveCounter = 1;
this.eventCounter = 0; this.eventCounter = 0;
this.eventWait = false; this.eventWait = false;
...@@ -205,6 +205,8 @@ public class ShadowDefend extends AbstractGame { ...@@ -205,6 +205,8 @@ public class ShadowDefend extends AbstractGame {
protected void update(Input input) { protected void update(Input input) {
// Increase the frame counter by the current timescale // Increase the frame counter by the current timescale
frameCount += getTimescale(); frameCount += getTimescale();
projCount += getTimescale();
// Draw map from the top left of the window // Draw map from the top left of the window
map.draw(0, 0, 0, 0, WIDTH, HEIGHT); map.draw(0, 0, 0, 0, WIDTH, HEIGHT);
...@@ -344,9 +346,9 @@ public class ShadowDefend extends AbstractGame { ...@@ -344,9 +346,9 @@ public class ShadowDefend extends AbstractGame {
System.out.println(tanks); System.out.println(tanks);
} }
if(placedImage.equals("stank")) { if(placedImage.equals("stank")) {
stanks.add(new SuperTank(input.getMousePosition(), STANK_FILE)); tanks.add(new SuperTank(input.getMousePosition(), STANK_FILE));
gold-=600; gold-=600;
System.out.println(stanks); System.out.println(tanks);
} }
if(placedImage.equals("plane")) { if(placedImage.equals("plane")) {
if(isVertical){ if(isVertical){
...@@ -399,8 +401,7 @@ public class ShadowDefend extends AbstractGame { ...@@ -399,8 +401,7 @@ public class ShadowDefend extends AbstractGame {
} }
} else { } else {
if(lives>0 && slicers.isEmpty() && superSlicers.isEmpty() if(lives>0 && slicers.isEmpty()){
&& megaSlicers.isEmpty() && apexSlicers.isEmpty()){
if(waveState != 3){ if(waveState != 3){
gold += waveNumber*100+150; gold += waveNumber*100+150;
} }
...@@ -414,8 +415,7 @@ public class ShadowDefend extends AbstractGame { ...@@ -414,8 +415,7 @@ public class ShadowDefend extends AbstractGame {
} }
} }
if(waveState == 1 && !waveStarted && slicers.isEmpty() && superSlicers.isEmpty() if(waveState == 1 && !waveStarted && slicers.isEmpty()){
&& megaSlicers.isEmpty() && apexSlicers.isEmpty()){
if(waveState != 0){ if(waveState != 0){
gold += waveNumber*100+150; gold += waveNumber*100+150;
} }
...@@ -429,17 +429,17 @@ public class ShadowDefend extends AbstractGame { ...@@ -429,17 +429,17 @@ public class ShadowDefend extends AbstractGame {
if (frameCount*1000 / FPS >= spawnDelay && spawnedSlicers != spawnCount) { if (frameCount*1000 / FPS >= spawnDelay && spawnedSlicers != spawnCount) {
switch(enemyType) { switch(enemyType) {
case "slicer": case "slicer":
slicers.add(new Slicer(polyline,RSLICER)); slicers.add(new RegularSlicer(polyline,RSLICER));
break; break;
case "superslicer": case "superslicer":
//System.out.println("in"); //System.out.println("in");
superSlicers.add(new SuperSlicer(polyline,SSLICER)); slicers.add(new SuperSlicer(polyline,SSLICER));
break; break;
case "megaslicer": case "megaslicer":
megaSlicers.add(new MegaSlicer(polyline,MSLICER)); slicers.add(new MegaSlicer(polyline,MSLICER));
break; break;
case "apexslicer": case "apexslicer":
apexSlicers.add(new ApexSlicer(polyline,ASLICER)); slicers.add(new ApexSlicer(polyline,ASLICER));
break; break;
} }
...@@ -476,63 +476,73 @@ public class ShadowDefend extends AbstractGame { ...@@ -476,63 +476,73 @@ public class ShadowDefend extends AbstractGame {
}*/ }*/
// Update all sprites, and remove them if they've finished // Update all sprites, and remove them if they've finished
for (int i = slicers.size() - 1; i >= 0; i--) { for (int j = tanks.size() - 1; j >= 0; j--) {
if (!tanks.isEmpty()) {
Tank v = tanks.get(j);
v.target = null;
for (int i = 0; i <= slicers.size() - 1; i++) {
if(!slicers.isEmpty()){ if(!slicers.isEmpty()){
Slicer s = slicers.get(i); Slicer s = slicers.get(i);
s.update(input); if (v.getCenter().distanceTo(s.getCenter()) < v.radius && s.health > 0 && !hasTarget) {
if (s.isFinished()) { v.target = s;
slicers.remove(i); slicerIndex = i;
hasTarget = true;
} }
} }
}
for (int i = superSlicers.size() - 1; i >= 0; i--) {
if(!superSlicers.isEmpty()){
SuperSlicer t = superSlicers.get(i);
t.update(input);
if (t.isFinished()) {
superSlicers.remove(i);
}
} }
if(hasTarget){
if (projCount*1000 / FPS >= v.cooldown) {
} projectiles.add(new Projectile(v.tankPoint,v.target,v.damage,slicerIndex,TANK_PROJ_FILE));
for (int i = megaSlicers.size() - 1; i >= 0; i--) { projCount = 0;
if(!megaSlicers.isEmpty()){
MegaSlicer u = megaSlicers.get(i);
u.update(input);
if (u.isFinished()) {
megaSlicers.remove(i);
}
} }
} }
for (int i = apexSlicers.size() - 1; i >= 0; i--) {
if(!apexSlicers.isEmpty()){
ApexSlicer v = apexSlicers.get(i);
v.update(input); v.update(input);
if (v.isFinished()) { hasTarget = false;
apexSlicers.remove(i);
} }
} }
for (int i = projectiles.size() - 1; i >= 0; i--) {
if(!projectiles.isEmpty()){
Projectile t = projectiles.get(i);
t.update(input);
if (t.isFinished()) {
slicers.get(t.slicerIndex).setHealth(slicers.get(t.slicerIndex).health-t.damage);
System.out.println(slicers.get(t.slicerIndex).health);
projectiles.remove(i);
} }
for (int i = tanks.size() - 1; i >= 0; i--) { }
if(!tanks.isEmpty()){
Tank v = tanks.get(i);
v.update(input);
} }
for (int i = slicers.size() - 1; i >= 0; i--) {
if(!slicers.isEmpty()){
Slicer s = slicers.get(i);
s.update(input);
if (s.isFinished()) {
if(s.health<=0){
gold += s.reward;
} else {
lives -= s.penalty;
}
slicers.remove(i);
} }
for (int i = stanks.size() - 1; i >= 0; i--) {
if(!stanks.isEmpty()){
SuperTank v = stanks.get(i);
v.update(input);
} }
} }
for (int i = planes.size() - 1; i >= 0; i--) { for (int i = planes.size() - 1; i >= 0; i--) {
if(!planes.isEmpty()){ if(!planes.isEmpty()){
Airplane v = planes.get(i); Airplane v = planes.get(i);
......
...@@ -11,11 +11,11 @@ import java.util.List; ...@@ -11,11 +11,11 @@ import java.util.List;
public class Slicer extends Sprite { public class Slicer extends Sprite {
private double speed,health,reward,penalty; protected double speed,reward,penalty;
protected int health;
private final List<Point> polyline; protected final List<Point> polyline;
private int targetPointIndex; protected int targetPointIndex;
private boolean finished; protected boolean finished;
/** /**
* Creates a new Slicer * Creates a new Slicer
...@@ -28,13 +28,11 @@ public class Slicer extends Sprite { ...@@ -28,13 +28,11 @@ public class Slicer extends Sprite {
this.targetPointIndex = 1; this.targetPointIndex = 1;
this.finished = false; this.finished = false;
this.speed = 1;
this.health = 1;
this.reward = 2;
this.penalty = 1;
} }
public void setHealth(int health){
this.health = health;
}
/** /**
* Updates the current state of the slicer. The slicer moves towards its next target point in * Updates the current state of the slicer. The slicer moves towards its next target point in
* the polyline at its specified movement rate. * the polyline at its specified movement rate.
...@@ -64,6 +62,12 @@ public class Slicer extends Sprite { ...@@ -64,6 +62,12 @@ public class Slicer extends Sprite {
targetPointIndex += 1; targetPointIndex += 1;
} }
} }
if(health<=0){
finished = true;
return;
}
// 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)
......
...@@ -31,6 +31,7 @@ public abstract class Sprite { ...@@ -31,6 +31,7 @@ public abstract class Sprite {
public Rectangle getRect() { public Rectangle getRect() {
return new Rectangle(rect); return new Rectangle(rect);
} }
...@@ -40,14 +41,17 @@ public abstract class Sprite { ...@@ -40,14 +41,17 @@ public abstract class Sprite {
* @param dx The move delta vector * @param dx The move delta vector
*/ */
public void move(Vector2 dx) { public void move(Vector2 dx) {
rect.moveTo(rect.topLeft().asVector().add(dx).asPoint()); rect.moveTo(rect.topLeft().asVector().add(dx).asPoint());
} }
public Point getCenter() { public Point getCenter() {
return getRect().centre(); return getRect().centre();
} }
public void setAngle(double angle) { public void setAngle(double angle) {
this.angle = angle; this.angle = angle;
} }
......
...@@ -8,14 +8,9 @@ import java.util.List; ...@@ -8,14 +8,9 @@ import java.util.List;
/** /**
* A super slicer. * A super slicer.
*/ */
public class SuperSlicer extends Sprite { public class SuperSlicer extends Slicer {
private static final String IMAGE_FILE = "res/images/slicer.png";
protected double speed,health,reward,penalty;
private final List<Point> polyline;
private int targetPointIndex;
private boolean finished;
/** /**
* Creates a new Slicer * Creates a new Slicer
...@@ -23,10 +18,7 @@ public class SuperSlicer extends Sprite { ...@@ -23,10 +18,7 @@ public class SuperSlicer extends Sprite {
* @param polyline The polyline that the slicer must traverse (must have at least 1 point) * @param polyline The polyline that the slicer must traverse (must have at least 1 point)
*/ */
public SuperSlicer(List<Point> polyline,String imageSrc) { public SuperSlicer(List<Point> polyline,String imageSrc) {
super(polyline.get(0), imageSrc); super(polyline, imageSrc);
this.polyline = polyline;
this.targetPointIndex = 1;
this.finished = false;
this.speed = 0.75; this.speed = 0.75;
this.health = 1; this.health = 1;
...@@ -41,39 +33,9 @@ public class SuperSlicer extends Sprite { ...@@ -41,39 +33,9 @@ public class SuperSlicer extends Sprite {
*/ */
@Override @Override
public void update(Input input) { public void update(Input input) {
if (finished) {
return;
}
// 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 (magnitude < speed * ShadowDefend.getTimescale()) {
// Check if we have reached the end
if (targetPointIndex == polyline.size() - 1) {
finished = true;
return;
} else {
// Make our focus the next point in the polyline
targetPointIndex += 1;
}
}
// 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)
super.move(distance.normalised().mul(speed * ShadowDefend.getTimescale()));
// Update current rotation angle to face target point
setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x));
super.update(input); super.update(input);
} }
public boolean isFinished() {
return finished;
}
} }
...@@ -18,7 +18,6 @@ public class SuperTank extends Tank{ ...@@ -18,7 +18,6 @@ public class SuperTank extends Tank{
@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);
} }
......
...@@ -3,21 +3,41 @@ package lists; ...@@ -3,21 +3,41 @@ package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
public class Tank extends Sprite{ import java.util.ArrayList;
protected double radius,damage,cooldown;
import java.util.List;
public class Tank extends Sprite{
protected double radius,cooldown;
protected int damage;
protected Point tankPoint;
protected Slicer target;
public Tank(Point point, String imageSrc) { public Tank(Point point, String imageSrc) {
super(point, imageSrc); super(point, imageSrc);
this.radius = 100; this.radius = 100;
this.damage = 1; this.damage = 1;
this.cooldown = 1000; this.cooldown = 1000;
this.tankPoint = point;
this.target = null;
} }
public void attack(Slicer slicer){
if (slicer.health > 0){
slicer.health-=damage;
}
}
@Override @Override
public void update(Input input) { public void update(Input input) {
if(target != null){
// Obtain where we currently are, and where we want to be
Point currentPoint = getCenter();
Point targetPoint = target.getCenter();
setAngle(Math.atan2(targetPoint.y - currentPoint.y, targetPoint.x - currentPoint.x)+Math.PI/2);
}
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