Class Utils

java.lang.Object
io.github.espressoengine.Utils

public class Utils extends Object
Utility functions to help reduce the amount of code in a game.
Version:
$Id: $Id
Author:
pastthepixels
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    clamp(double value, double min, double max)
    Returns min if value is lower than min and max if value is higher than max.
    static int
    clamp(int value, int min, int max)
    Returns min if value is lower than min and max if value is higher than max.
    static float
    clamp(Float value, float min, float max)
    Returns min if value is lower than min and max if value is higher than max.
    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, by step every time the function is called.
    static float
    stepTo(float from, float to, float step)
    Moves a number, from, closer to a target, to, by step every time the function is called.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 double
      max - 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)
      Returns min if value is lower than min and max if value is higher than max.
      Parameters:
      value - a double
      min - a double
      max - a double
      Returns:
      a double
    • clamp

      public static float clamp(Float value, float min, float max)
      Returns min if value is lower than min and max if value is higher than max.
      Parameters:
      value - a Float object
      min - a float
      max - a float
      Returns:
      a float
    • clamp

      public static int clamp(int value, int min, int max)
      Returns min if value is lower than min and max if value is higher than max.
      Parameters:
      value - a int
      min - a int
      max - 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, by step every time the function is called.
      Parameters:
      from - a double
      to - a double
      step - 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, by step every time the function is called.
      Parameters:
      from - a float
      to - a float
      step - a float
      Returns:
      a float