Coverage Summary for Class: Weather (com.mygdx.game.Entitys)

Class Class, % Method, % Line, %
Weather 100% (1/1) 77.8% (7/9) 70.4% (19/27)


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.badlogic.gdx.utils.ObjectMap; 6 import com.mygdx.game.Components.Pirate; 7 import com.mygdx.game.Components.Renderable; 8 import com.mygdx.game.Components.RigidBody; 9 import com.mygdx.game.Components.Transform; 10 import com.mygdx.game.Managers.GameManager; 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 import com.mygdx.utils.Utilities; 17  18 import java.util.Objects; 19 import java.util.Vector; 20  21 /**NEW 22  * 23  */ 24 public class Weather extends Entity implements CollisionCallBack { 25  private static int weatherCount = 0; 26  RigidBody rb; 27  int count = 0; 28  /** 29  * Creates a Weather entity, 30  */ 31  public Weather() { 32  super(4); 33  setName("Storm (" + weatherCount++ + ")"); // each ship has a unique name 34  35  Transform t = new Transform(); 36  t.setPosition(900, 800); 37  Renderable r = new Renderable("whirlpool.png", RenderLayer.Transparent) ; 38  rb = new RigidBody(PhysicsBodyType.Dynamic, r, t); 39  rb.setCallback(this); 40  41  addComponents(t, r, rb); 42  } 43  44  45  public void moveWeather() { 46  47  Vector2 dir = getRandomDirection(); 48  rb.setVelocity(dir); 49  } 50  51  private Vector2 getRandomDirection() { 52  float x = (float) Math.floor(Math.random()*3) - 1; 53  float y = (float) Math.floor(Math.random()*3) - 1; 54  Vector2 dir = new Vector2(x * 1000, y * 1000); 55  return dir; 56  }; 57  58  @Override 59  public void update() { 60  super.update(); 61  if (count == 50) { 62  moveWeather(); 63  count = 0; 64  } 65  count++; 66  } 67  68  69  @Override 70  public void BeginContact(CollisionInfo info) { 71  EnterTrigger(info); 72  } 73  74  @Override 75  public void EndContact(CollisionInfo info) { 76  } 77  78  79  /** 80  * if called on a Player against anything else call it on the other thing 81  */ 82  @Override 83  public void EnterTrigger(CollisionInfo info) { 84  if (this instanceof Weather && !(info.a instanceof Weather) && !(info.a == null)) { 85  ((CollisionCallBack) info.a).EnterTrigger(info); 86  } 87  } 88  89  /** 90  * if called on a Player against anything else call it on the other thing 91  */ 92  @Override 93  public void ExitTrigger(CollisionInfo info) { 94  if (this instanceof Weather && !(info.a instanceof Weather) && !(info.a == null)) { 95  ((CollisionCallBack) info.a).ExitTrigger(info); 96  } 97  } 98 }