source: last-defense/main/Projectile.java@ fb4fc67

Last change on this file since fb4fc67 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: 2.2 KB
Line 
1package main;
2
3import java.awt.Color;
4import java.awt.Graphics;
5import java.util.LinkedList;
6import gamegui.Animation;
7
8public class Projectile extends Entity {
9 public static long explodedDuration = 300L;
10
11 public boolean exploded;
12 public long timeExploded;
13
14 private int damage;
15 private Location targetLoc;
16 private Unit target;
17 private int speed;
18
19 public Projectile(final String name, final Animation img, final int speed, final Location targetLoc, final Unit target, final int damage) {
20 super(name, img);
21 this.speed = speed;
22 this.targetLoc = targetLoc;
23 this.target = target;
24 this.damage = damage;
25 this.exploded = false;
26 this.actions.add(new Action.Move(20L));
27 }
28
29 public int getDamage() {
30 return this.damage;
31 }
32
33 public Unit getTarget() {
34 return this.target;
35 }
36
37 @Override
38 public void perform(final Action action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
39 if (action instanceof Action.Move) {
40 this.perform((Action.Move)action, lstObjects, lstTargets);
41 }
42 }
43
44 public void perform(final Action.Move action, final LinkedList<Entity> lstObjects, final LinkedList<Unit> lstTargets) {
45 if (this.exploded) {
46 return;
47 }
48 if (this.loc.moveToTarget(this.targetLoc.getX(), this.targetLoc.getY(), (System.currentTimeMillis() - action.timeLastPerformed) * this.speed / 1000L)) {
49 this.remove = true;
50 this.target.takeDamage(this.damage);
51 if (this.target.getHitpoints() == 0) {
52 this.target.remove = true;
53 }
54 }
55 }
56
57 @Override
58 public void draw(final Graphics g) {
59 if (this.exploded) {
60 if (System.currentTimeMillis() - this.timeExploded >= Projectile.explodedDuration) {
61 this.remove = true;
62 }
63 else {
64 g.setColor(new Color(255, 0, 0, 100));
65 g.fillOval(this.loc.getX() - 15, this.loc.getY() - 15, 30, 30);
66 }
67 }
68 else {
69 this.img.draw(g, this.loc.getX(), this.loc.getY() + this.img.getHeight() / 2);
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.