package Hole;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;

import helpers.GameInfo;


public class Hole extends Sprite
{
    private World world;

    private Body body;

    private float xPosition, yPosition;

    public Hole(World world, float xPosition, float yPosition)
    {
        super(new Texture("Hole/Hole.png"));
        this.world = world;
        setSpritePosition(xPosition, yPosition);
    }

    void createHoleBody()
    {
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.StaticBody;

        bodyDef.position.set(getX(), getY());

        body = world.createBody(bodyDef);
        body.setUserData("Hole");

        CircleShape shape = new CircleShape();
        shape.setRadius((getWidth() / 2f) / GameInfo.PPM);
        shape.setPosition(new Vector2(getWidth() / 2f, getHeight() / 2f));

        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = shape;

        body.createFixture(fixtureDef);

        shape.dispose();
    }

    public void setSpritePosition(float x, float y)
    {
        setPosition(x, y);
        createHoleBody();
    }

    public float getxPosition()
    {
        return xPosition;
    }

    public void setxPosition(float xPosition)
    {
        this.xPosition = xPosition;
    }

    public float getyPosition()
    {
        return yPosition;
    }

    public void setyPosition(float yPosition)
    {
        this.yPosition = yPosition;
    }
}
