Coverage Summary for Class: WaterParticle (com.mozarellabytes.kroy.Entities)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
WaterParticle | 100% (1/ 1) | 62.5% (5/ 8) | 85.7% (18/ 21) |
1 package com.mozarellabytes.kroy.Entities;
2
3 import com.badlogic.gdx.graphics.Color;
4 import com.badlogic.gdx.math.Interpolation;
5 import com.badlogic.gdx.math.Vector2;
6
7 /**
8 * This class is what a FireTruck uses to attack a
9 * Fortress with. It generates a random colour from
10 * a list of colours and a random size before heading
11 * from the FireTruck towards the Fortress using the
12 * interpolation function specified
13 */
14 public class WaterParticle {
15
16 /** Fortress that WaterParticle is firing at */
17 private final Fortress target;
18
19 /** Random colour of Rectangle */
20 private final Color colour;
21
22 /** Random size of the Rectangle */
23 private final float size;
24
25 /** The position where the water particle starts from (the position
26 * of the truck)
27 */
28 private final Vector2 startPosition;
29
30 /** The current position of the water particle */
31 private Vector2 currentPosition;
32
33 /** The end position of the water particle (the fortress the truck
34 * is attacking)
35 */
36 private Vector2 targetPosition;
37
38 /**
39 * Constructs a WaterParticle with
40 * the following parameters
41 *
42 * @param truck The FireTruck that the
43 * WaterParticle came from
44 * @param target The Fortress that the
45 * WaterParticle is heading
46 * towards
47 */
48 public WaterParticle(FireTruck truck, Fortress target) {
49 this.target = target;
50 Color[] colors = new Color[] {Color.CYAN, Color.NAVY, Color.BLUE, Color.PURPLE, Color.SKY, Color.TEAL};
51 this.colour = colors[(int)(Math.random() * 4)];
52 this.size = (float)(Math.random()/5 + 0.1);
53 this.startPosition = new Vector2(truck.getPosition().x + 0.5f, truck.getPosition().y + 0.5f);
54 this.currentPosition = startPosition;
55 this.targetPosition = target.getPosition();
56 createTargetPosition(target);
57 }
58
59 /**
60 * Creates the random coordinate within the fortress
61 *
62 * @param fortress the fortress whose target position is being created
63 */
64 private void createTargetPosition(Fortress fortress) {
65 float xCoord = (float)(Math.random()-0.5+fortress.getPosition().x);
66 float yCoord = (float)(Math.random()-0.5+fortress.getPosition().y);
67 this.targetPosition = new Vector2(xCoord, yCoord);
68 }
69
70 /**
71 * Updates the position of the WaterParticle
72 * using the Interpolation function
73 */
74 public void updatePosition() {
75 this.currentPosition = this.startPosition.interpolate(this.targetPosition, 0.2f, Interpolation.circle);
76 }
77
78 /**
79 * Checks if the WaterParticle has
80 * reached the the Fortress
81 *
82 * @return <code>true</code> if WaterParticle hit Fortress
83 * <code>false</code> otherwise
84 */
85 public boolean isHit() {
86 return (((int) this.targetPosition.x == (int) this.currentPosition.x) &&
87 ((int) this.targetPosition.y == (int) this.currentPosition.y));
88 }
89
90 public Fortress getTarget() { return this.target; }
91
92 public float getSize() { return this.size; }
93
94 public Color getColour() { return this.colour; }
95
96 public Vector2 getPosition() { return this.currentPosition; }
97
98 }
99