package com.rehab.world;

public class Hitbox {
	
	// Top left corner and bottom right corner of rectangular model
	private double mTopLeftX, mTopLeftY,
					mBottomRightX, mBottomRightY;
		
	private double mWidth, mHeight;


	/**
	 * Empty Hitboxes must not be created.
	 */
	private Hitbox() {  }

	/**
	 * Constructor for a Rectangular Hitbox whose dimensions are based off of a given
	 * Entity's image dimensions.
	 * @param e
	 * 		the Entity whose image width and height should model the collidable area.
	 */
	public Hitbox(Entity e) {

		// TODO - Record coordinates based on Entity image
		
	}


	/**
	 * Constructor for a rectangular Hitbox where the host object's image dimensions is
	 * not the true collidable dimensions.
	 * @param leftX
	 * 		the x-coordinate of the top left corner.
	 * @param leftY
	 * 		the y-coordinate of the top left corner.
	 * @param rightX
	 * 		the x-coordinate of the bottom right corner.
	 * @param rightY
	 * 		the y-coordinate of the bottom right corner.
	 */
	public Hitbox(double leftX, double leftY, double rightX, double rightY) {
		mTopLeftX = leftX;
		mTopLeftY = leftY;
		mBottomRightX = rightX;
		mBottomRightY = rightY;
		// Cache dimensions
		mWidth = mBottomRightX - mTopLeftX;
		mHeight = mBottomRightY - mTopLeftY;
	}

	/**
	 * Checks whether or not two rectangular Hitboxes overlap.
	 * @param h
	 * 		the Hitbox to check against.
	 * @return
	 * 		true if the two Hitboxes overlap at some point, false othewise.
	 */
	public boolean intersects(Hitbox h) {
		if (this.mBottomRightX > h.mTopLeftX && this.mBottomRightY > h.mTopLeftY
				&& this.mTopLeftX < h.mBottomRightX && this.mTopLeftY < h.mBottomRightY)
				return true;
		return false;
	}

	/**
	 * Sets the new origin of the Hitbox.
	 * @param x
	 * 		the new x origin.
	 * @param y
	 * 		the new y origin.
	 */
	public void moveTo(double x, double y) {
		mTopLeftX = x;
		mTopLeftY = y;
		mBottomRightX = x + mWidth;
		mBottomRightY = y + mHeight;	
	
		mBottomRightY = y + mHeight;
	}

	/**
	 * Shrinks the actual size of an object's collision model on four optional sides.
	 * @param right
	 * 		how many px to pull back on the right.
	 * @param top
	 * 		how many px to pull back on the top.
	 * @param left
	 * 		how many px to pull back on the left.
	 * @param bottom
	 * 		how many px to pull back on the bottom.
	 */
	public void setPadding(double right, double top, double left, double bottom) {
		mTopLeftX += left;
		mTopLeftY += top;
		mBottomRightX -= right;
		mBottomRightY -= bottom;
	}
}

@@ -19,16 +19,52 @@
 world;%0A%0A
+import com.rehab.animation.Sprite;%0A%0A
 public c
@@ -218,17 +218,29 @@
 ightY;%0A%09
-%09
+// Dimensions
 %0A%09privat
@@ -317,16 +317,45 @@
 d.%0A%09 */%0A
+%09@SuppressWarnings(%22unused%22)%0A
 %09private
@@ -618,64 +618,93 @@
 ) %7B%0A
-%0A
 %09%09
-// TODO - Record coordinates based on Entity image%0A%09%09
+Sprite img = e.getSprite();%0A%09%09mWidth = img.getWidth();%0A%09%09mHeight = img.getHeight();
 %0A%09%7D%0A
@@ -2039,42 +2039,8 @@
 th;%0A
-%09%09mBottomRightY = y + mHeight;%09%0A%09%0A
 %09%09mB
@@ -2158,16 +2158,97 @@
  sides.%0A
+%09 * Any negative values given will cause no padding to be set (non-retroactive).%0A
 %09 * @par
@@ -2574,101 +2574,600 @@
 %7B%0A%09%09
-mTopLeftX += left;%0A%09%09mTopLeftY += top;%0A%09%09mBottomRightX -= right;%0A%09%09mBottomRightY -= bottom;%0A%09
+// Ensure negatives don't mess with collision%0A%09%09if (right %3C 0 %7C%7C top %3C 0 %7C%7C left %3C 0 %7C%7C bottom %3C 0) return;%0A%09%09mTopLeftX += left;%0A%09%09mTopLeftY += top;%0A%09%09mBottomRightX -= right;%0A%09%09mBottomRightY -= bottom;%0A%09%09%0A%09%09// Update the dimensions%0A%09%09mWidth = mBottomRightX - mTopLeftX;%0A%09%09mHeight = mBottomRightY - mTopLeftY;%0A%09%7D%0A%09%0A%09/**%0A%09 * Gets the width of the collision model.%0A%09 * @return%0A%09 * %09%09the width in pixels.%0A%09 */%0A%09public double getWidth() %7B return mWidth; %7D%0A%09%0A%09/**%0A%09 * Gets the height of the collision model.%0A%09 * @return%0A%09 * %09%09the height in pixels.%0A%09 */%0A%09public double getHeight() %7B return mHeight; 
 %7D%0A%7D%0A

Update for physics