import res.geom.Vector2;
import res.display.FrameBuffer;

using res.display.Sprite;
using Std;

class Meteor {
	final sprite:Sprite;

	final cx:Float;
	final cy:Float;

	public var x:Float;
	public var y:Float;

	var vel:Vector2;

	public var hitEarth:Bool = false;

	public function new(cx:Float, cy:Float, x:Float, y:Float, sprite:Sprite) {
		this.cx = cx;
		this.cy = cy;

		this.x = x;
		this.y = y;

		vel = new Vector2(cx - x, cy - y).normalize(10);

		this.sprite = sprite;
	}

	public function update(dt:Float) {
		x += vel.x * dt;
		y += vel.y * dt;

		if (Vector2.xy(cx - x, cy - y).length2() < 16.5 * 16.5) {
			hitEarth = true;
		}
	}

	public function render(frameBuffer:FrameBuffer) {
		frameBuffer.drawSprite(sprite, (x - sprite.width / 2).int(), (y - sprite.height / 2).int(), false, false, false);
	}
}
