package ecs.components;

import ecs.core.Component;
import res.geom.Vector2;

class Velocity extends Component {
	public var x:Float;
	public var y:Float;

	public var speed(get, set):Float;

	function get_speed() {
		return Vector2.xy(x, y).length();
	}

	function set_speed(newSpeed:Float) {
		if (newSpeed != 0) {
			final v = Vector2.xy(x, y).normalize(newSpeed);
			x = v.x;
			y = v.y;
		} else {
			x = y = 0;
		}

		return newSpeed;
	}

	public function new(x, y) {
		super();

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