source: last-defense/main/Shield.java

Last change on this file was fb4fc67, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Initial commit, code decompiled from a jar

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[fb4fc67]1package main;
2
3import java.util.Iterator;
4import java.util.LinkedList;
5import gamegui.Animation;
6
7public class Shield extends Unit {
8 int radius;
9
10 public Shield(final String name, final Animation img, final int hitpoints, final int radius) {
11 super(name, img, hitpoints);
12 this.radius = radius;
13 this.actions.add(new Action.Defend(5L));
14 }
15
16 @Override
17 public void perform(final Action action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
18 if (action instanceof Action.Defend) {
19 this.perform((Action.Defend)action, lstObjects, lstTargets);
20 }
21 }
22
23 public void perform(final Action.Defend action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
24 for (final Entity cur : lstObjects) {
25 if (cur instanceof Projectile && !(((Projectile)cur).getTarget() instanceof Ship) && this.loc.distance(cur.loc) <= this.radius && !((Projectile)cur).exploded) {
26 ((Projectile)cur).exploded = true;
27 ((Projectile)cur).timeExploded = System.currentTimeMillis();
28 this.takeDamage(((Projectile)cur).getDamage());
29 if (this.getHitpoints() != 0) {
30 continue;
31 }
32 this.remove = true;
33 }
34 }
35 }
36}
Note: See TracBrowser for help on using the repository browser.