Esempio n. 1
0
 /**
  * Get all the entities who are touching this entity
  *
  * @param dest A list to store the entities in, or null, to construct a new one
  * @return dest, or a new List if dest was null
  */
 public final List<Entity> checkCollisions(List<Entity> dest) {
   if (node != null) {
     return node.checkCollisions(this, dest);
   } else {
     // Haven't got a node in the quadtree. Use the root
     assert false : this + " is not in the quadtree!";
     return COLLISIONMANAGER.checkCollisions(this, dest);
   }
 }
Esempio n. 2
0
 /** Add this entity to the collision manager */
 protected final void addToCollisionManager() {
   if (node != null) {
     if (!node.remove(this)) {
       assert false : "Entity " + this + " was not found!";
     }
   }
   node = COLLISIONMANAGER.add(this);
   if (node == null) {
     node = COLLISIONMANAGER;
     COLLISIONMANAGER.store(this);
   }
 }
Esempio n. 3
0
  /** Tick. Called every frame if this entity is alive. */
  @Override
  public final void tick() {
    try {
      doTick();
      float newR = getRadius();

      if (node != null) {
        if (canCollide() && isActive()) {
          // If we've changed radius, remove and re-add to the quadtree
          if (oldR != newR) {
            oldR = newR;
            addToCollisionManager();
          }
        } else {
          // Can't collide any more - remove from quadtree
          node.remove(this);
          node = null;
        }
      } else {
        if (canCollide() && isActive()) {
          // Add us in to the quadtree
          addToCollisionManager();
        }
      }
    } catch (Exception e) {
      System.err.println("Error ticking " + this);
      e.printStackTrace(System.err);
      remove();
    }
  }
Esempio n. 4
0
 /** Remove the entity */
 @Override
 public final void remove() {
   removeSprites();
   if (!active) {
     // Already removed
     return;
   }
   active = false;
   Worm.getGameState().removeEntity(this);
   if (node != null) {
     node.remove(this);
     node = null;
   }
   doRemove();
 }
Esempio n. 5
0
 /**
  * Find out which entities are touching the specified rectangle
  *
  * @param rect
  * @param dest
  * @return
  */
 public static List<Entity> getCollisions(ReadableRectangle rect, List<Entity> dest) {
   return COLLISIONMANAGER.checkCollisions(rect, dest);
 }
Esempio n. 6
0
 public static void reset() {
   COLLISIONMANAGER.clear();
 }
Esempio n. 7
0
 /** Process collisions */
 public static void checkCollisions() {
   COLLISIONMANAGER.checkCollisions();
 }