Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 30, 2024
1 parent bce06b1 commit aeb2e3e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/flixel/math/FlxMath.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
package flixel.math;

import raylib.RayMath;

class FlxMath {
/**
* Minimum value of a floating point number.
*/
public static inline var MIN_VALUE_FLOAT:Float = 5e-324;

/**
* Maximum value of a floating point number.
*/
public static inline var MAX_VALUE_FLOAT:Float = 1.79e+308;

/**
* Minimum value of an integer.
*/
public static inline var MIN_VALUE_INT:Int = -MAX_VALUE_INT;

/**
* Maximum value of an integer.
*/
public static inline var MAX_VALUE_INT:Int = 0x7FFFFFFF;

/**
* Approximation of `Math.sqrt(2)`.
*/
public static inline var SQUARE_ROOT_OF_TWO:Float = 1.41421356237;


/**
* Round a decimal number to have reduced precision (less decimal numbers).
* @param value The number to round
* @param precision The number of decimal numbers.
* @return The rounded number to the specified precision
*/
public static function roundDecimal(value:Float, precision:Int):Float {
var mult:Float = 1;
for (i in 0...precision) {
mult *= 10;
}
return Math.fround(value * mult) / mult;
}

public static inline function lerp(start:Float, end:Float, amount:Float):Float {
return RayMath.lerp(start, end, amount);
}
}
5 changes: 3 additions & 2 deletions test/src/PlayState.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import flixel.math.FlxMath;
import flixel.FlxG;
import flixel.FlxState;
import flixel.FlxSprite;
Expand Down Expand Up @@ -30,8 +31,8 @@ class PlayState extends FlxState {
override public function update(elapsed:Float) {
super.update(elapsed);

scythe.x = RayMath.lerp(scythe.x, Raylib.getMousePosition().x, elapsed * 10);
scythe.y = RayMath.lerp(scythe.y, Raylib.getMousePosition().y, elapsed * 10);
scythe.x = FlxMath.lerp(scythe.x, Raylib.getMousePosition().x, elapsed * 10);
scythe.y = FlxMath.lerp(scythe.y, Raylib.getMousePosition().y, elapsed * 10);

if (Raylib.isKeyPressed(KEY_SPACE)) {
FlxG.switchState(new OtherState());
Expand Down

0 comments on commit aeb2e3e

Please sign in to comment.