Package io.github.espressoengine
Class Utils
java.lang.Object
io.github.espressoengine.Utils
Utility functions to help reduce the amount of code in a game.
- Version:
- $Id: $Id
- Author:
- pastthepixels
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double value, double min, double max) Returnsminifvalueis lower thanminandmaxifvalueis higher thanmax.static intclamp(int value, int min, int max) Returnsminifvalueis lower thanminandmaxifvalueis higher thanmax.static floatReturnsminifvalueis lower thanminandmaxifvalueis higher thanmax.static booleanReturns true or false, randomly.static doublerand_range(double min, double max) Returns a random number within a range of numbers.static doublestepTo(double from, double to, double step) Moves a number,from, closer to a target,to, bystepevery time the function is called.static floatstepTo(float from, float to, float step) Moves a number,from, closer to a target,to, bystepevery time the function is called.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
rand_range
public static double rand_range(double min, double max) Returns a random number within a range of numbers.- Parameters:
min- a doublemax- a double- Returns:
- a double
-
flip_coin
public static boolean flip_coin()Returns true or false, randomly.- Returns:
- a boolean
-
clamp
public static double clamp(double value, double min, double max) Returnsminifvalueis lower thanminandmaxifvalueis higher thanmax.- Parameters:
value- a doublemin- a doublemax- a double- Returns:
- a double
-
clamp
Returnsminifvalueis lower thanminandmaxifvalueis higher thanmax.- Parameters:
value- aFloatobjectmin- a floatmax- a float- Returns:
- a float
-
clamp
public static int clamp(int value, int min, int max) Returnsminifvalueis lower thanminandmaxifvalueis higher thanmax.- Parameters:
value- a intmin- a intmax- a int- Returns:
- a int
-
stepTo
public static double stepTo(double from, double to, double step) Moves a number,from, closer to a target,to, bystepevery time the function is called.- Parameters:
from- a doubleto- a doublestep- a double- Returns:
- a double
-
stepTo
public static float stepTo(float from, float to, float step) Moves a number,from, closer to a target,to, bystepevery time the function is called.- Parameters:
from- a floatto- a floatstep- a float- Returns:
- a float
-