Class Util


  • public class Util
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void annulCollisionEvent​(EntityEntityCollisionEvent event, Entity entity)
      Annuls, or "cancels," the movement restrictions specified by the collision event
      static boolean fiftyFifty()
      Calls percentChance(double) with an equal chance of either true or false
      static java.util.ArrayList<EntityEntityCollision> getAllBoundaryCollisions​(EntityEntityCollision baseEvent, Entity entity, EntityBoundary baseBoundary)
      Generates an array list of collisions between the base boundary and all of the entity's boundaries
      static org.newdawn.slick.Image[] getAnimationFrames​(Sprite sprite)
      Builds an array of images to use for the frames of an animation
      static org.newdawn.slick.Animation getTemplateAnimation​(byte imageStore, int width, int height, int rows, int frames, int frameDelay, int rowOffset)
      Builds an animation from the given image and supplied parameters
      static boolean isWithinBounds​(int pointX, int pointY, int boundsX, int boundsY, int width, int height)
      Returns whether or not the specified point is "within bounds," or overlapping, the specified area
      static void onCollisionWithNonTraversableEntity​(EntityEntityCollisionEvent event, Entity entity)
      Disallows movement opposite of the side of the collision.
      static boolean percentChance​(double percent)
      Returns true the given percentage of the time
      static int randomInt​(int min, int max)
      Returns a random integer between the minimum and maximum
      static int randomInt​(int min, int max, boolean inclusive)
      Returns a random integer between the minimum and maximum
      static org.newdawn.slick.Image stitchImage​(org.newdawn.slick.Image base, org.newdawn.slick.Image toStitch)
      Stitches two images together, side by side
      static java.lang.String[] toLines​(java.lang.String dialogue, org.newdawn.slick.Font font, int maxLineLength)
      Returns an array containing the given dialogue split into seperate lines, wrapped at words
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • stitchImage

        public static org.newdawn.slick.Image stitchImage​(org.newdawn.slick.Image base,
                                                          org.newdawn.slick.Image toStitch)
        Stitches two images together, side by side
        Parameters:
        base - The image on the left
        toStitch - The image on the right
        Returns:
        The resulting combination of both images
      • getAnimationFrames

        public static org.newdawn.slick.Image[] getAnimationFrames​(Sprite sprite)
        Builds an array of images to use for the frames of an animation
        Parameters:
        sprite - The sprite to get frames from
        Returns:
        An array of images, each representing a single frame
      • getTemplateAnimation

        public static org.newdawn.slick.Animation getTemplateAnimation​(byte imageStore,
                                                                       int width,
                                                                       int height,
                                                                       int rows,
                                                                       int frames,
                                                                       int frameDelay,
                                                                       int rowOffset)
        Builds an animation from the given image and supplied parameters
        Parameters:
        imageStore - The number representing the image to retrieve
        width - Width of the animation
        height - Height of the animation
        rows - Number of rows in the image
        frames - Number of frames
        frameDelay - How long to wait between frames
        rowOffset - The row to get from the resulting image
        Returns:
        An animation built from the image
      • randomInt

        public static int randomInt​(int min,
                                    int max)
        Returns a random integer between the minimum and maximum
        Parameters:
        min - The smallest value (inclusive)
        max - The largest value (exclusive)
        Returns:
        An integer between the minimum and maximum
      • randomInt

        public static int randomInt​(int min,
                                    int max,
                                    boolean inclusive)
        Returns a random integer between the minimum and maximum
        Parameters:
        min - The smallest value (inclusive)
        max - The largest value
        inclusive - Whether or not the maximum value could be returned
        Returns:
        An integer between the minimum and maximum
      • percentChance

        public static boolean percentChance​(double percent)
        Returns true the given percentage of the time
        Parameters:
        percent - The percent chance that true will be returned
        Returns:
        True the given percentage of the time, false otherwise
      • fiftyFifty

        public static boolean fiftyFifty()
        Calls percentChance(double) with an equal chance of either true or false
        Returns:
        True 50% of the time, false the other 50%
      • annulCollisionEvent

        public static void annulCollisionEvent​(EntityEntityCollisionEvent event,
                                               Entity entity)
        Annuls, or "cancels," the movement restrictions specified by the collision event
        Parameters:
        event - The collision event to annul
        entity - The entity to modify movement restrictions on
      • onCollisionWithNonTraversableEntity

        public static void onCollisionWithNonTraversableEntity​(EntityEntityCollisionEvent event,
                                                               Entity entity)
        Disallows movement opposite of the side of the collision. For example, if the player collided with a tree on its top side, downward movement would no longer be allowed until that collision is no longer active
        Parameters:
        event - The collision event that occured
        entity - The entity to modify movement "allowing" for
      • toLines

        public static java.lang.String[] toLines​(java.lang.String dialogue,
                                                 org.newdawn.slick.Font font,
                                                 int maxLineLength)
        Returns an array containing the given dialogue split into seperate lines, wrapped at words
        Parameters:
        dialogue - The entire dialogue to split into lines
        font - The font being used to render these lines
        maxLineLength - The maximum length, in pixels (not characters), that a line can be before being wrapped
        Returns:
        An array of strings, each containing a line split from the full dialogue
      • isWithinBounds

        public static boolean isWithinBounds​(int pointX,
                                             int pointY,
                                             int boundsX,
                                             int boundsY,
                                             int width,
                                             int height)
        Returns whether or not the specified point is "within bounds," or overlapping, the specified area
        Parameters:
        pointX - The x-coordinate of the point
        pointY - The y-coordinate of the point
        boundsX - The x-coordinate of the bounds
        boundsY - The y-coordinate of the bounds
        width - The width of the bounds
        height - The height of the bounds
        Returns:
        Whether or not the point is located in the bounds