diff --git a/src/flixel/FlxObject.hx b/src/flixel/FlxObject.hx index 3ae94f4..3c8cd78 100644 --- a/src/flixel/FlxObject.hx +++ b/src/flixel/FlxObject.hx @@ -46,16 +46,16 @@ class FlxObject extends FlxBasic { @:noCompletion inline function initVars() { - scrollFactor = FlxPoint.create(1, 1); + scrollFactor = new FlxPoint(1, 1); initMotionVars(); } @:noCompletion inline function initMotionVars() { - velocity = FlxPoint.create(); - acceleration = FlxPoint.create(); - drag = FlxPoint.create(); - maxVelocity = FlxPoint.create(10000, 10000); + velocity = new FlxPoint(); + acceleration = new FlxPoint(); + drag = new FlxPoint(); + maxVelocity = new FlxPoint(10000, 10000); } public function screenCenter(axes:FlxAxes = XY):FlxObject { diff --git a/src/flixel/math/FlxPoint.hx b/src/flixel/math/FlxPoint.hx index a926bfe..2990c42 100644 --- a/src/flixel/math/FlxPoint.hx +++ b/src/flixel/math/FlxPoint.hx @@ -1,5 +1,58 @@ package flixel.math; +import haxe.ds.Vector; import raylib.Vector2; -typedef FlxPoint = Vector2; \ No newline at end of file +using raylib.RayMath; + +@:forward +@:publicFields +abstract FlxPoint(Vector2) to Vector2 from Vector2 { + public var x(get, set):Float; + + public var y(get, set):Float; + + inline function new(x:Float = 0, y:Float = 0) { + this = Vector2.create(x, y); + } + + @:op(a + b) + static inline function add(a:FlxPoint, b:FlxPoint):FlxPoint { + return a.vector2Add(b); + } + + @:op(a - b) + static inline function subtract(a:FlxPoint, b:FlxPoint):FlxPoint { + return a.vector2Subtract(b); + } + + @:op(a * b) + static inline function multiply(a:FlxPoint, b:FlxPoint):FlxPoint { + return Vector2.create(a.x * b.x, a.y * b.y); + } + + @:op(a / b) + static inline function divide(a:FlxPoint, b:FlxPoint):FlxPoint { + return Vector2.create(a.x / b.x, a.y / b.y); + } + + @:noCompletion + private inline function set_x(x:Float):Float { + return this.x = x; + } + + @:noCompletion + private inline function get_x():Float { + return this.x; + } + + @:noCompletion + private inline function set_y(y:Float):Float { + return this.y = y; + } + + @:noCompletion + private inline function get_y():Float { + return this.y; + } +} diff --git a/src/raylib/RayMath.hx b/src/raylib/RayMath.hx index 04ed941..38c87b8 100644 --- a/src/raylib/RayMath.hx +++ b/src/raylib/RayMath.hx @@ -16,4 +16,22 @@ extern class RayMath { @:native("Lerp") public static function lerp(start:Float, end:Float, amount:Float):Float; + + @:native("Vector2Zero") + public static function vector2Zero():Vector2; + + @:native("Vector2One") + public static function vector2One():Vector2; + + @:native("Vector2Add") + public static function vector2Add(v1:Vector2, v2:Vector2):Vector2; + + @:native("Vector2AddValue") + public static function vector2AddValue(v:Vector2, add:Float):Vector2; + + @:native("Vector2Subtract") + public static function vector2Subtract(v1:Vector2, v2:Vector2):Vector2; + + @:native("Vector2SubtractValue") + public static function vector2SubtractValue(v1:Vector2, v2:Vector2):Vector2; }