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 double
clamp
(double value, double min, double max) Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is higher thanmax
.static int
clamp
(int value, int min, int max) Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is higher thanmax
.static float
Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is higher thanmax
.static boolean
Returns true or false, randomly.static double
rand_range
(double min, double max) Returns a random number within a range of numbers.static double
stepTo
(double from, double to, double step) Moves a number,from
, closer to a target,to
, bystep
every time the function is called.static float
stepTo
(float from, float to, float step) Moves a number,from
, closer to a target,to
, bystep
every 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) Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is higher thanmax
.- Parameters:
value
- a doublemin
- a doublemax
- a double- Returns:
- a double
-
clamp
Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is higher thanmax
.- Parameters:
value
- aFloat
objectmin
- a floatmax
- a float- Returns:
- a float
-
clamp
public static int clamp(int value, int min, int max) Returnsmin
ifvalue
is lower thanmin
andmax
ifvalue
is 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
, bystep
every 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
, bystep
every time the function is called.- Parameters:
from
- a floatto
- a floatstep
- a float- Returns:
- a float
-