Package net.egartley.beyondorigins
Class Util
- java.lang.Object
-
- net.egartley.beyondorigins.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 eventstatic boolean
fiftyFifty()
CallspercentChance(double)
with an equal chance of either true or falsestatic 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 boundariesstatic org.newdawn.slick.Image[]
getAnimationFrames(Sprite sprite)
Builds an array of images to use for the frames of an animationstatic 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 parametersstatic 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 areastatic 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 timestatic int
randomInt(int min, int max)
Returns a random integer between the minimum and maximumstatic int
randomInt(int min, int max, boolean inclusive)
Returns a random integer between the minimum and maximumstatic org.newdawn.slick.Image
stitchImage(org.newdawn.slick.Image base, org.newdawn.slick.Image toStitch)
Stitches two images together, side by sidestatic 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
-
-
-
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 lefttoStitch
- 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 retrievewidth
- Width of the animationheight
- Height of the animationrows
- Number of rows in the imageframes
- Number of framesframeDelay
- How long to wait between framesrowOffset
- 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 valueinclusive
- 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()
CallspercentChance(double)
with an equal chance of either true or false- Returns:
- True 50% of the time, false the other 50%
-
getAllBoundaryCollisions
public 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- Parameters:
baseEvent
- The collision to use forEntityEntityCollision.start(EntityEntityCollisionEvent)
andEntityEntityCollision.start(EntityEntityCollisionEvent)
entity
- The entity to generate collisions for all its boundariesbaseBoundary
- The other boundary to use for the generated collisions- Returns:
- Collisions based on the given collision and boundary, and all of the entity's boundaries
-
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 annulentity
- 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 occuredentity
- 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 linesfont
- The font being used to render these linesmaxLineLength
- 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 pointpointY
- The y-coordinate of the pointboundsX
- The x-coordinate of the boundsboundsY
- The y-coordinate of the boundswidth
- The width of the boundsheight
- The height of the bounds- Returns:
- Whether or not the point is located in the bounds
-
-