import res.display.FrameBuffer;

using res.display.Sprite;
using res.graphics.Painter;
using Std;

class Satellite {
	final hX:Float;
	final hY:Float;
	final sprite:Sprite;

	final cX:Float;
	final cY:Float;

	var angle:Float;

	public function new(cX:Float, cY:Float, hX:Float, hY:Float, angle:Float, sprite:Sprite) {
		this.cX = cX;
		this.cY = cY;
		this.hX = hX;
		this.hY = hY;
		this.angle = angle;
		this.sprite = sprite;
	}

	public function update(dt:Float) {
		angle += Math.PI / 10 * dt;
	}

	public function drawOrbit(frameBuffer:FrameBuffer) {
		frameBuffer.ellipse(cX.int(), cY.int(), hX.int(), hY.int(), 9);
	}

	public function render(frameBuffer:FrameBuffer) {
		final x = Std.int(cX + Math.cos(angle) * hX - sprite.width / 2);
		final y = Std.int(cY - Math.sin(angle) * hY - sprite.height / 2);

		frameBuffer.drawSprite(sprite, x, y);
	}
}
