package depart.commun.monde2d;

import ca.ntro.app.fx.controls.World2dMouseEventFx;
import ca.ntro.app.world2d.Object2dFx;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.ArcType;

public class Balle2d extends Object2dFx {
	
	private static final double CONST_A = 900;
	private static final double CONST_B = 0.8;
	
	public Balle2d() {
		super();

		setWidth(20);           
		setHeight(20);
		
		setAccelerationY(CONST_A);
	}

	@Override
	public void onAddedToWorld() {
		setTopLeftX(getWorldWidth() / 2 - getWidth() / 2);
		setTopLeftY(10);
	}

	@Override
	protected boolean onMouseEvent(World2dMouseEventFx mouseEvent) {
		return false;
	}
	
	@Override
	public void onTimePasses(double secondsElapsed) {
		super.onTimePasses(secondsElapsed);

		if(getTopLeftY() + getHeight() > getWorldHeight()) {

			setTopLeftY(getWorldHeight()-getHeight());
			setSpeedY(-1 * Math.abs(getSpeedY()) * CONST_B); 

		}
	}

	@Override
	public void drawOnWorld(GraphicsContext gc) {
		gc.setFill(Color.BROWN);

		gc.fillArc(getTopLeftX(),
				   getTopLeftY(),
				   getWidth(),
				   getHeight(),
				   0,
				   360,
				   ArcType.CHORD);
	}

}
