Skip to content

Commit

Permalink
FlxPoint stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 30, 2024
1 parent aeb2e3e commit 353c5c1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/flixel/FlxObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 54 additions & 1 deletion src/flixel/math/FlxPoint.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
package flixel.math;

import haxe.ds.Vector;
import raylib.Vector2;

typedef FlxPoint = Vector2;
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;
}
}
18 changes: 18 additions & 0 deletions src/raylib/RayMath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 353c5c1

Please sign in to comment.