org.jrabbit.standard.game.main
Class StandardGame

java.lang.Object
  extended by org.jrabbit.base.core.loop.Loop
      extended by org.jrabbit.standard.game.loop.GameLoop
          extended by org.jrabbit.standard.game.main.StandardGame
All Implemented Interfaces:
Renderable, Updateable

public abstract class StandardGame
extends GameLoop

StandardGame is the base class for any jRabbit game. It extends GameLoop, adding controls on initializing the game. The game StandardGame creates is runnable from an executable jar. By default, it creates its own window (by default this window is also set to fullscreen), but it can be made to reside within an AWT or Swing application. (If this is done, it can be integrated with a GUI. An example use of this could be an editor.) It should be noted that the JVM needs to initialize LWJGL and the general jRabbit engine before and implementation of StandardGame is created and run. The init() methods provided automatically does everything required; calling any one of them will do. Thus, the contents of a main() method need only be something like: init(); new Class_Extending_StandardGame().run(); and the game will be created and will run as desired. Finally, it should be noted that StandardGame allows for a series of opening intros to be played (e.g., logos and/or intro scenes).

Author:
Chris Molini

Field Summary
static java.lang.String DEFAULT_ICON
          The location of the default icon for jRabbit games.
static java.lang.String DEFAULT_TITLE
          The default title for jRabbit games.
protected  boolean showIntro
          Whether or not the intro sequence should be displayed.
 
Fields inherited from class org.jrabbit.standard.game.loop.GameLoop
profiler, world
 
Fields inherited from class org.jrabbit.base.core.loop.Loop
controller, exit
 
Constructor Summary
StandardGame()
          Creates a StandardGame with the default title and default icon.
StandardGame(java.lang.String title)
          Creates a StandardGame with the indicated title.
StandardGame(java.lang.String title, java.lang.String icon)
          Creates a StandardGame with the indicated title and icon.
 
Method Summary
 void advanceGame(int delta)
          Extends GameLoop.advanceGame(int) to automatically exit the game if escape is pressed.
protected  void end()
          Exits the game, destroying LWJGL in the process.
static void init()
          Initializes the game engine using a default DesktopWindowController.
static void init(int width, int height)
          Initializes the game engine using a DesktopWindowController that creates a windowed instance of the game at the indicated dimensions.
static void init(WindowController controller)
          Initializes the game engine using the indicated DesktopWindowController.
protected static void initForOS(java.lang.String OS)
          Initializes the game engine based upon the operating system the game is running on.
protected  void onExit()
          When jRabbit exits, this is called to give the game a chance to execute some custom exit code.
protected abstract  void setup()
          Override this to set the initial state of the game.
protected  void setupIntro(IntroLoop intro)
          Override this to add custom Intro displays.
 boolean showingIntro()
          Learns if the openings are currently set to show at startup.
 void showIntro(boolean showIntro)
          Sets whether or not the opening Intros should play.
protected  void start()
          Prepares the StandardGame for execution, and runs the opening sequence if desired.
 
Methods inherited from class org.jrabbit.standard.game.loop.GameLoop
profiler, render, run, setProfiler, setWorld, update, world
 
Methods inherited from class org.jrabbit.base.core.loop.Loop
controller, exit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TITLE

public static final java.lang.String DEFAULT_TITLE
The default title for jRabbit games.

See Also:
Constant Field Values

DEFAULT_ICON

public static final java.lang.String DEFAULT_ICON
The location of the default icon for jRabbit games.

See Also:
Constant Field Values

showIntro

protected boolean showIntro
Whether or not the intro sequence should be displayed.

Constructor Detail

StandardGame

public StandardGame()
Creates a StandardGame with the default title and default icon.


StandardGame

public StandardGame(java.lang.String title)
Creates a StandardGame with the indicated title. The default icon is used.

Parameters:
title - The name of the game to run.

StandardGame

public StandardGame(java.lang.String title,
                    java.lang.String icon)
Creates a StandardGame with the indicated title and icon.

Parameters:
title - The name of the game to run.
icon - The filepath to the desired icon.
Method Detail

init

public static final void init()
Initializes the game engine using a default DesktopWindowController. This automatically creates a fullscreen game at full resolution.


init

public static final void init(int width,
                              int height)
Initializes the game engine using a DesktopWindowController that creates a windowed instance of the game at the indicated dimensions.

Parameters:
width - The width of the window to use.
height - The height of the window to use.

init

public static final void init(WindowController controller)
Initializes the game engine using the indicated DesktopWindowController.

Parameters:
controller - The WindowController that will control the Window settings and initialize LWJGL.

initForOS

protected static void initForOS(java.lang.String OS)
Initializes the game engine based upon the operating system the game is running on. This is automatically called in init().

Parameters:
OS - The name of the operating system, as returned by System.getProperty("os.name").
See Also:
init(), init(int, int), init(WindowController)

showingIntro

public boolean showingIntro()
Learns if the openings are currently set to show at startup.

Returns:
True if the opening sequence will play, false if not.

showIntro

public void showIntro(boolean showIntro)
Sets whether or not the opening Intros should play.

Parameters:
showIntro - True if the openings should show, false if not.

start

protected void start()
Prepares the StandardGame for execution, and runs the opening sequence if desired.

Overrides:
start in class GameLoop

setupIntro

protected void setupIntro(IntroLoop intro)
Override this to add custom Intro displays. NOTE: The intro specified already adds jRabbit's intro by default. To remove it, simply use intro.queue.clear(). :(

Parameters:
intro - The IntroLoop that is being prepared to start playing.

setup

protected abstract void setup()
Override this to set the initial state of the game. It is automatically called at the beginning of the main loop.


advanceGame

public void advanceGame(int delta)
Extends GameLoop.advanceGame(int) to automatically exit the game if escape is pressed. This behavior is intended to make quick testing easier.

Overrides:
advanceGame in class GameLoop
Parameters:
delta - The number of clock cycles that have passed since the last update.

end

protected void end()
Exits the game, destroying LWJGL in the process.

Overrides:
end in class GameLoop

onExit

protected void onExit()
When jRabbit exits, this is called to give the game a chance to execute some custom exit code. (Examples: emergency saving, disconnecting from a server, etc.)