[fb4fc67] | 1 | package main;
|
---|
| 2 |
|
---|
| 3 | import java.util.LinkedList;
|
---|
| 4 | import gamegui.Animation;
|
---|
| 5 |
|
---|
| 6 | public class Turret extends Unit {
|
---|
| 7 | int damage;
|
---|
| 8 | Unit target;
|
---|
| 9 | Animation projectileImg;
|
---|
| 10 |
|
---|
| 11 | public Turret(final String name, final Animation img, final int damage, final int hitpoints, final int fireRate, final Animation projectileImg) {
|
---|
| 12 | super(name, img, hitpoints);
|
---|
| 13 | this.damage = damage;
|
---|
| 14 | this.projectileImg = projectileImg;
|
---|
| 15 | this.actions.add(new Action.Fire(fireRate));
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public int getDamage() {
|
---|
| 19 | return this.damage;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | @Override
|
---|
| 23 | public void perform(final Action action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
|
---|
| 24 | if (action instanceof Action.Fire) {
|
---|
| 25 | this.perform((Action.Fire)action, lstObjects, lstTargets);
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public void perform(final Action.Fire action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
|
---|
| 30 | if (lstTargets.size() == 0) {
|
---|
| 31 | this.target = null;
|
---|
| 32 | return;
|
---|
| 33 | }
|
---|
| 34 | if (this.target == null || this.target.remove) {
|
---|
| 35 | this.target = lstTargets.get((int)(Math.random() * lstTargets.size()));
|
---|
| 36 | }
|
---|
| 37 | lstObjects.add(this.fire(this.target));
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public Projectile fire(final Unit target) {
|
---|
| 41 | final Projectile proj = new Projectile("Projectile", this.projectileImg, 400, target.loc, target, this.damage);
|
---|
| 42 | proj.setLocation(this.loc);
|
---|
| 43 | return proj;
|
---|
| 44 | }
|
---|
| 45 | } |
---|