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

levels implemented

parent 1091c1c9
No related branches found
No related tags found
No related merge requests found
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2; import bagel.util.Vector2;
...@@ -18,10 +16,12 @@ public class Airplane extends Sprite{ ...@@ -18,10 +16,12 @@ public class Airplane extends Sprite{
private double speed; private double speed;
private int damage;
private boolean finished, isVertical; private boolean finished, isVertical;
private double frameCount; private double frameCount;
private Random r = new Random(); private Random r = new Random();
private double nothingTime; private double nothingTime;
private Point explode;
...@@ -30,16 +30,25 @@ public class Airplane extends Sprite{ ...@@ -30,16 +30,25 @@ public class Airplane extends Sprite{
public Airplane(Point point, boolean isVertical, String imageSrc){ public Airplane(Point point, boolean isVertical, String imageSrc){
super(point,imageSrc); super(point,imageSrc);
this.speed = 1.5; this.speed = 1.5;
this.damage = 500;
this.finished = false; this.finished = false;
this.isVertical = isVertical; this.isVertical = isVertical;
this.frameCount = Integer.MAX_VALUE; this.frameCount = Integer.MAX_VALUE;
this.nothingTime = Math.round((TIME_MIN + (TIME_MAX - TIME_MIN) * r.nextDouble())*1000); this.nothingTime = Math.round((TIME_MIN + (TIME_MAX - TIME_MIN) * r.nextDouble())*1000);
this.explosives = new ArrayList<>(); this.explosives = new ArrayList<>();
this.explode = null;
} }
public Point getExplode(){
return this.explode;
}
public int getDamage(){
return this.damage;
}
@Override @Override
public void update(Input input) { public void update(Input input) {
explode = null;
frameCount += ShadowDefend.getTimescale(); frameCount += ShadowDefend.getTimescale();
if (finished) { if (finished) {
return; return;
...@@ -68,21 +77,26 @@ public class Airplane extends Sprite{ ...@@ -68,21 +77,26 @@ public class Airplane extends Sprite{
// Check if we have reached the end // Check if we have reached the end
if ((currentPoint.x >= WIDTH || currentPoint.y >= HEIGHT) && explosives.isEmpty()) { 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--) { for (int i = explosives.size() - 1; i >= 0; i--) {
if(!explosives.isEmpty()){ if(!explosives.isEmpty()){
System.out.println(explosives); //System.out.println(explosives);
Explosive v = explosives.get(i); Explosive v = explosives.get(i);
v.update(input); v.update(input);
if (v.isFinished()) { if (v.isFinished()) {
explode = v.getPoint();
explosives.remove(i); 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.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List; import java.util.List;
/** /**
...@@ -17,14 +15,14 @@ public class ApexSlicer extends Slicer { ...@@ -17,14 +15,14 @@ public class ApexSlicer extends Slicer {
* *
* @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,int targetPointIndex, Point point,String imageSrc) {
super(polyline, imageSrc); super(polyline, targetPointIndex, point, imageSrc);
this.speed = 0.375; this.speed = 0.375;
this.health = 25; this.health = 25;
this.reward = 150; this.reward = 150;
this.penalty = 16; this.penalty = 16;
this.spawnOnDeath = 4;
} }
/** /**
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import java.util.Random;
public class Explosive extends Sprite{ public class Explosive extends Sprite{
private static final double COOLDOWN = 2000; private static final double COOLDOWN = 2000;
private double radius,damage,frameCount; private double radius,frameCount;
private boolean finished; private boolean finished;
private Point point;
...@@ -18,13 +15,16 @@ public class Explosive extends Sprite{ ...@@ -18,13 +15,16 @@ public class Explosive extends Sprite{
public Explosive(Point point, String imageSrc){ public Explosive(Point point, String imageSrc){
super(point,imageSrc); super(point,imageSrc);
this.radius = 200; this.radius = 200;
this.damage = 500;
this.point = point;
this.finished = false; this.finished = false;
this.frameCount = 0; this.frameCount = 0;
} }
public Point getPoint(){
return this.point;
}
@Override @Override
public void update(Input input) { public void update(Input input) {
frameCount += ShadowDefend.getTimescale(); frameCount += ShadowDefend.getTimescale();
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List; import java.util.List;
/** /**
...@@ -17,14 +15,14 @@ public class MegaSlicer extends Slicer { ...@@ -17,14 +15,14 @@ public class MegaSlicer extends Slicer {
* *
* @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, int targetPointIndex, Point point,String imageSrc) {
super(polyline, imageSrc); super(polyline, targetPointIndex, point,imageSrc);
this.speed = 0.75; this.speed = 0.75;
this.health = 2; this.health = 2;
this.reward = 10; this.reward = 10;
this.penalty = 4; this.penalty = 4;
this.spawnOnDeath = 2;
} }
/** /**
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2; import bagel.util.Vector2;
...@@ -18,9 +16,15 @@ public class Projectile extends Sprite { ...@@ -18,9 +16,15 @@ public class Projectile extends Sprite {
this.speed = 5; this.speed = 5;
this.damage = damage; this.damage = damage;
this.slicerIndex = slicerIndex; this.slicerIndex = slicerIndex;
}
public int getSlicerIndex(){
return this.slicerIndex;
}
public int getDamage() {
return this.damage;
} }
@Override @Override
public void update(Input input) { public void update(Input input) {
if (finished) { if (finished) {
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List; import java.util.List;
/** /**
...@@ -15,13 +13,14 @@ public class RegularSlicer extends Slicer { ...@@ -15,13 +13,14 @@ public class RegularSlicer extends Slicer {
* *
* @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 RegularSlicer(List<Point> polyline,String imageSrc) { public RegularSlicer(List<Point> polyline, int targetPointIndex, Point point, String imageSrc) {
super(polyline, imageSrc); super(polyline, targetPointIndex, point, imageSrc);
this.speed = 1; this.speed = 1;
this.health = 1; this.health = 1;
this.reward = 2; this.reward = 2;
this.penalty = 1; this.penalty = 1;
this.spawnOnDeath = 0;
} }
......
This diff is collapsed.
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2; import bagel.util.Vector2;
...@@ -12,7 +10,7 @@ public class Slicer extends Sprite { ...@@ -12,7 +10,7 @@ public class Slicer extends Sprite {
protected double speed,reward,penalty; protected double speed,reward,penalty;
protected int health; protected int health, spawnOnDeath;
protected final List<Point> polyline; protected final List<Point> polyline;
protected int targetPointIndex; protected int targetPointIndex;
protected boolean finished; protected boolean finished;
...@@ -22,17 +20,41 @@ public class Slicer extends Sprite { ...@@ -22,17 +20,41 @@ public class Slicer 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 Slicer(List<Point> polyline,String imageSrc) { public Slicer(List<Point> polyline,int targetPointIndex, Point point,String imageSrc) {
super(polyline.get(0), imageSrc); super(point, imageSrc);
this.polyline = polyline; this.polyline = polyline;
this.targetPointIndex = 1; this.targetPointIndex = targetPointIndex;
this.finished = false; this.finished = false;
} }
public int getTargetPointIndex() {
return this.targetPointIndex;
}
public double getReward() {
return this.reward;
}
public int getSpawnOnDeath() {
return this.spawnOnDeath;
}
public int getHealth(){
return this.health;
}
public double getPenalty() {
return this.penalty;
}
public void setHealth(int health){ public void setHealth(int health){
this.health = health; this.health = health;
} }
public Point getCurrentPoint(){
return getCenter();
}
/** /**
* 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 +86,7 @@ public class Slicer extends Sprite { ...@@ -64,6 +86,7 @@ public class Slicer extends Sprite {
} }
if(health<=0){ if(health<=0){
finished = true; finished = true;
return; return;
} }
......
package lists;
import bagel.DrawOptions; import bagel.DrawOptions;
import bagel.Image; import bagel.Image;
import bagel.Input; import bagel.Input;
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import bagel.util.Vector2;
import java.util.List; import java.util.List;
/** /**
...@@ -17,13 +15,14 @@ public class SuperSlicer extends Slicer { ...@@ -17,13 +15,14 @@ public class SuperSlicer extends Slicer {
* *
* @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, int targetPointIndex, Point point,String imageSrc) {
super(polyline, imageSrc); super(polyline,targetPointIndex,point, imageSrc);
this.speed = 0.75; this.speed = 0.75;
this.health = 1; this.health = 1;
this.reward = 15; this.reward = 15;
this.penalty = 2; this.penalty = 2;
this.spawnOnDeath = 2;
} }
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
...@@ -10,7 +8,7 @@ public class SuperTank extends Tank{ ...@@ -10,7 +8,7 @@ public class SuperTank extends Tank{
public SuperTank(Point point, String imageSrc){ public SuperTank(Point point, String imageSrc){
super(point,imageSrc); super(point,imageSrc);
this.radius = 150; this.radius = 150;
this.damage = 1; this.damage = 3;
this.cooldown = 500; this.cooldown = 500;
} }
......
package lists;
import bagel.Input; import bagel.Input;
import bagel.util.Point; import bagel.util.Point;
import java.util.ArrayList;
import java.util.List;
public class Tank extends Sprite{ public class Tank extends Sprite{
protected double radius,cooldown; protected double radius,cooldown;
protected int damage; protected int damage;
...@@ -22,13 +16,23 @@ public class Tank extends Sprite{ ...@@ -22,13 +16,23 @@ public class Tank extends Sprite{
this.target = null; this.target = null;
} }
public void setTarget(Slicer givenTarget){
public void attack(Slicer slicer){ this.target = givenTarget;
if (slicer.health > 0){ }
slicer.health-=damage; public Point getTankPoint(){
return this.tankPoint;
}
public Slicer getTarget(){
return this.target;
}
public int getDamage(){
return this.damage;
}
public double getRadius(){
return this.radius;
} }
public double getCooldown(){
return this.cooldown;
} }
@Override @Override
public void update(Input input) { public void update(Input input) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment