/*
 * Box.java
 *
 * Box-shaped model to support collisions.
 *
 * Given the name box2d, this is your primary collision shape. In this example
 * we draw it with primitives, but you could easily adapt this class to use it
 * with Sprites.
 *
 * @author Walker M. White
 * @version 3/9/2025
 */
package edu.cornell.cis3152.box2d.shape;

import com.badlogic.gdx.math.*;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.physics.box2d.*;

import edu.cornell.cis3152.box2d.*;  // For Entity
import edu.cornell.gdiac.math.Poly2;

/**
 * A rectangular physics object.
 */
public class Box extends Entity {
	/** Shape information for this box */
	protected PolygonShape shape;

	/**
	 * Creates a new box, but do not initialize it yet.
	 */
	public Box() { }

	/**
     * Creates the collision shape information
     *
     * @param size The object bounding box
     */
	protected void makeFixture(Vector2 size) {
		shape = new PolygonShape();
		// The polygon tool uses half-height
		shape.setAsBox(size.x / 2, size.y / 2);

		// Create the fixture
		FixtureDef def = new FixtureDef();
		def.density = density;
		def.friction = friction;
		def.restitution = restitution;
		def.shape = shape;

		fixture = body.createFixture(def);
		shape.dispose(); // Do not need it anymore
	}

	/**
     * Creates the drawing shape information
     *
     * @param size  The object bounding box
     */
	protected void makeGraphics(Vector2 size) {
		// Make the polygon centered at origin
        poly = new Poly2(-units*size.x/2.0f, -units*size.y/2.0f, units*size.x, units*size.y);
	}
}
