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