ncannasse %!s(int64=11) %!d(string=hai) anos
pai
achega
43d39c3774
Modificáronse 1 ficheiros con 38 adicións e 0 borrados
  1. 38 0
      hxd/Direction.hx

+ 38 - 0
hxd/Direction.hx

@@ -0,0 +1,38 @@
+package hxd;
+
+@:enum abstract Direction(Int) {
+
+	public var Up = 1;
+	public var Left = 4;
+	public var Right = 6;
+	public var Down = 9;
+
+	public var x(get, never) : Int;
+	public var y(get, never) : Int;
+	public var name(get, never) : String;
+
+	inline function get_x() {
+		return (this & 3) - 1;
+	}
+
+	inline function get_y() {
+		return (this >> 2) - 1;
+	}
+
+	inline function get_name() {
+		return VALUES[this];
+	}
+
+	static var VALUES = ["none", "up", null, null, "left", null, "right", null, null, "down"];
+	inline function toString() {
+		return name;
+	}
+
+	public static function from(x, y) {
+		if( x < 0 ) x = -1;
+		if( x > 0 ) x = 1;
+		if( y < 0 ) y = -1;
+		if( y > 0 ) y = 1;
+		return (x + 1) | ((y + 1) << 2);
+	}
+}