Package org.xjge.core
Class Game
java.lang.Object
org.xjge.core.Game
public final class Game
extends java.lang.Object
Provides utilities for managing high-level game logic.
More specifically the game class can be used to change the current scene being rendered or the flow of execution through its access to the engines central event queue. In addition to these features the Game class also provides some convenience methods useful for general gameplay operations.
These gameplay methods include:
- Since:
- 2.0.0
-
Field Summary
Fields Modifier and Type Field Description static boolean
enableBloom
static Observable
observable
AnObservable
object that can be used to detect state changes occurring within the Game class. -
Constructor Summary
Constructors Constructor Description Game()
-
Method Summary
Modifier and Type Method Description static void
addEntity(java.lang.String name, Entity entity)
Adds an entity to the current scene.static void
addEvent(Event event)
Adds an event to the game event queue.static void
addLight(int index, Light light)
Inserts a light object into the current scenes lights array at the specified index.static int
getNumEvents()
Obtains the current number of events in the event queue.static java.lang.String
getSceneName()
Obtains the display name of the current Scene being rendered.static int
getTickCount()
Obtains the total number of cycles that the engines update loop has completed since the start of the application.static void
setBloomThreshold(float value)
Specifies the value which will be used to indicate how bright the surface of objects must be before the bloom effect is applied to it.static void
setClearColor(Color color)
Changes the color OpenGL will use to clear color buffers.static void
setScene(Scene scene)
Exits the current scene and enters the one specified.static boolean
tick(int speed)
Returns true anytime the specified number of update iterations (or cycles) have been reached.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
enableBloom
public static boolean enableBloom -
observable
AnObservable
object that can be used to detect state changes occurring within the Game class.
-
-
Constructor Details
-
Game
public Game()
-
-
Method Details
-
getTickCount
public static int getTickCount()Obtains the total number of cycles that the engines update loop has completed since the start of the application.NOTE: The tick count will roll over to zero every hour, with one hour being equivalent to approximately 3,600,000 ticks. Gameplay systems that require durations longer than this should consider instead utilizing the
Timer
class.- Returns:
- the number of cycles (or ticks) that have elapsed
-
getNumEvents
public static int getNumEvents()Obtains the current number of events in the event queue. Used primarily for debugging purposes.- Returns:
- the current number of unresolved events in the event queue
-
getSceneName
public static java.lang.String getSceneName()Obtains the display name of the current Scene being rendered.- Returns:
- the name of the current scene
-
setClearColor
Changes the color OpenGL will use to clear color buffers. Often used to set background or sky colors.- Parameters:
color
- the color empty space will be filled with
-
setScene
Exits the current scene and enters the one specified.- Parameters:
scene
- the new scene to enter
-
setBloomThreshold
public static void setBloomThreshold(float value)Specifies the value which will be used to indicate how bright the surface of objects must be before the bloom effect is applied to it. The lower the brightness threshold, the more abundant bloom will be.- Parameters:
value
- a number between 0 and 10 that the brightness of a surface will need to exceed
-
tick
public static boolean tick(int speed)Returns true anytime the specified number of update iterations (or cycles) have been reached. Intended to be used in for game systems that don't require the precision of theTimer
orStopWatch
classes.- Parameters:
speed
- the number of cycles to wait until the next tick will occur- Returns:
- true every time the specified number of cycles has been reached
-
addEntity
Adds an entity to the current scene. Generally speaking you'll only want to use this for instances where a brute-force solution is required, otherwise entity objects should be managed directly from within the scene subclass itself.- Parameters:
name
- the name that will be used to identify the entity in the current scenes entity collectionentity
- the entity object to add
-
addEvent
Adds an event to the game event queue. Events are processed in the order of their priority. As such, events are not guaranteed to be executed in the order from which calls to this method are made.- Parameters:
event
- the event to queue
-
addLight
Inserts a light object into the current scenes lights array at the specified index. This method is particularly useful in instances where lighting effects need to exhibit some level of dynamic behavior- such as an explosion in a dark tunnel emitting light for a brief period of time, etc.- Parameters:
index
- the index in the array to place the light object atlight
- the light object to add
-