Coverage Summary for Class: Building (com.mygdx.game.Entitys)
Class |
Class, %
|
Method, %
|
Line, %
|
Building |
100%
(1/1)
|
100%
(9/9)
|
100%
(34/34)
|
1 package com.mygdx.game.Entitys;
2
3 import com.badlogic.gdx.graphics.g2d.Sprite;
4 import com.badlogic.gdx.math.Vector2;
5 import com.mygdx.game.Components.Pirate;
6 import com.mygdx.game.Components.Renderable;
7 import com.mygdx.game.Components.RigidBody;
8 import com.mygdx.game.Components.Transform;
9 import com.mygdx.game.Faction;
10 import com.mygdx.game.Managers.RenderLayer;
11 import com.mygdx.game.Managers.ResourceManager;
12 import com.mygdx.game.Physics.CollisionCallBack;
13 import com.mygdx.game.Physics.CollisionInfo;
14 import com.mygdx.game.Physics.PhysicsBodyType;
15
16 import static com.mygdx.utils.Constants.BUILDING_SCALE;
17
18 /**
19 * Buildings that you see in game.
20 * Changed for Assessment 2 (made class public)
21 */
22 public class Building extends Entity implements CollisionCallBack {
23 private String buildingName;
24 private static int atlas_id;
25 private boolean isFlag;
26 private final College college; //Added for Assessment 2
27
28 /**
29 * Flags are indestructible and mark college locations.
30 * Amended for Assessment 2: Added College parameter to keep track of parent
31 * @param college added to signify ownership of building
32 */
33 public Building(College college) {
34 super();
35 isFlag = false;
36 Transform t = new Transform();
37 t.setScale(BUILDING_SCALE, BUILDING_SCALE);
38 Pirate p = new Pirate();
39 atlas_id = ResourceManager.getId("Buildings.txt");
40 Renderable r = new Renderable(atlas_id, "big", RenderLayer.Transparent);
41 addComponents(t, p, r);
42 this.college = college;
43 }
44
45 /**
46 * Flags are indestructible and mark college locations.
47 * Amended for Assessment 2: Added College parameter to keep track of parent
48 * @param isFlag set to true to create a flag
49 */
50 Building(College college, boolean isFlag) {
51 this(college);
52 this.isFlag = isFlag;
53 }
54
55 /**
56 * Creates a building with the given name at the specified location.
57 *
58 * @param pos 2D position vector
59 * @param name name of building
60 */
61 public void create(Vector2 pos, String name) {
62 Sprite s = ResourceManager.getSprite(atlas_id, name);
63 Renderable r = getComponent(Renderable.class);
64 r.setTexture(s);
65 getComponent(Transform.class).setPosition(pos);
66 buildingName = name;
67
68 RigidBody rb = new RigidBody(PhysicsBodyType.Static, r, getComponent(Transform.class));
69 rb.setCallback(this);
70 addComponent(rb);
71 }
72
73 /**
74 * Replace the building with ruins and mark as broken.
75 * Changed for Assessment 2
76 * - Made public for testing purposes
77 * - Sets destroyer as parent college's most recent attacker.
78 */
79 public void destroy(Faction conqueror) {
80 if (isFlag) {
81 return;
82 }
83 Sprite s = ResourceManager.getSprite(atlas_id, buildingName + "-broken");
84 Renderable r = getComponent(Renderable.class);
85 r.setTexture(s);
86 getComponent(Pirate.class).kill();
87 college.setMostRecentAttacker(conqueror);
88 }
89
90 /**
91 * @return the boolean value of the alive status of the Pirate Component
92 */
93 public boolean isAlive() {
94 return getComponent(Pirate.class).isAlive();
95 }
96
97 /**
98 * Destroys the building and marks cannonball for removal.
99 * Amended for Assessment 2, added Faction checks and now ignores flags
100 * @param info CollisionInfo container
101 */
102 @Override
103 public void EnterTrigger(CollisionInfo info) {
104 if (info.a instanceof CannonBall && isAlive() && !isFlag) {
105 CannonBall a = (CannonBall) info.a;
106 if(a.getFaction() != college.getFaction()){
107 destroy(a.getFaction());
108 }
109 a.kill();
110 }
111 }
112
113 /**
114 * Unused
115 */
116 @Override
117 public void BeginContact(CollisionInfo info) {}
118
119 /**
120 * Unused
121 */
122 @Override
123 public void EndContact(CollisionInfo info) {}
124
125 /**
126 * Unused
127 */
128 @Override
129 public void ExitTrigger(CollisionInfo info) {
130
131 }
132 }