示例#1
0
 /**
  * Check if this entity collides with the other entity.
  *
  * @param other
  * @return
  */
 public final boolean collidesWith(Entity2D other) {
   if (dead) {
     return false;
   }
   if (other == null) {
     return false;
   }
   if (other.getHitbox() == null) {
     return false;
   }
   if (texture == null) {
     return false;
   }
   updateHitbox(
       (int) x, (int) y, texture.getImageWidth(), texture.getImageHeight()); // Update our hitbox.
   other.updateHitbox(
       other.getX(),
       other.getY(),
       other.texture.getImageWidth(),
       other.texture.getImageHeight()); // Update their hitbox
   if (getHitbox().intersects(other.getHitbox())) {
     Scarlet.eventReactor.post(new Collision2DEvent(this, other));
     return true;
   } else {
     return false;
   }
 }
示例#2
0
 /**
  * Create a new 2D entity.
  *
  * @param tex The texture to use.
  * @param x The starting X position.
  * @param y The starting Y position.
  */
 protected Entity2D(String tex, float x, float y) {
   this.x = x;
   this.y = y;
   if (!tex.isEmpty()) {
     texture = Scarlet.getTextureEngine().getTexture(tex, true);
   }
   if (texture != null) {
     updateHitbox((int) x, (int) y, texture.getImageWidth(), texture.getImageHeight());
   }
 }