de.rico.engine.game
Class AbstractBaseGame

java.lang.Object
  extended by de.rico.engine.game.AbstractBaseGame
All Implemented Interfaces:
GameIface, java.util.EventListener, javax.media.opengl.GLEventListener
Direct Known Subclasses:
Adventure, WorldEditor

public abstract class AbstractBaseGame
extends java.lang.Object
implements GameIface

This abstract class represents a base class for writing a game. You will have to extend this class for your own project and implement the abstract methods like update(), draw() etc. This is the most basic version of an abstract game class available. It provides a camera only, but no inherent movement capabilities. You will have to implement your own movement capabilities by using the camera object together with InputActions and the InputManager class.

Author:
Frank Bruns

Constructor Summary
AbstractBaseGame(java.lang.String title, int maxFps)
          Creates a new base game with the specified window title and upper framerate boundary.
 
Method Summary
 void display(javax.media.opengl.GLAutoDrawable gld)
           
 void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
           
abstract  void draw(javax.media.opengl.GL gl)
          This method is used to draw the scene and its content.
 void enableBackFaceCulling()
          Enables back face culling for a (possibly) slight performance boost.
 javax.swing.JFrame getMainFrame()
          Returns the main window (main frame) of the game
 javax.media.opengl.GLCanvas getOGLCanvas()
          Returns the component that is the OpenGL canvas.
 void init(javax.media.opengl.GLAutoDrawable gld)
           
 void initCamera(float camX, float camY, float camZ, float rotX, float rotY, float near, float far)
          This method needs to be called before the start() method.
abstract  void initResources(javax.media.opengl.GLDrawable gld, javax.media.opengl.GL gl, int width, int height)
          This method is used to initialize all the objects and resources that are neccessary at startup of the game.
 boolean isSetDisplayFPS()
          Determines whether or not the framerate is set to be displayed on screen.
 void resetElapsedTime()
          Resets the calculation of the elapsed time between two frames.
 void reshape(javax.media.opengl.GLAutoDrawable gld, int x, int y, int width, int height)
           
 void setDisplayFPS(boolean enable)
          Sets whethter or not the framerate (frames per second) ought to be displayed.
 void setDisplayMode(EngineDisplayMode mode)
          Sets the display mode of the game window.
 void start(GameIface game)
          Call this method to start the game after every other method that influences the game startup has been called.
 void stop()
          This method is used to savely stop the game.
abstract  void update(long elapsedTime)
          This method is used to update the scene and its content.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBaseGame

public AbstractBaseGame(java.lang.String title,
                        int maxFps)
Creates a new base game with the specified window title and upper framerate boundary.

Parameters:
title - window title
maxFps - framerate to fix the game to, if possible
Method Detail

init

public void init(javax.media.opengl.GLAutoDrawable gld)
Specified by:
init in interface javax.media.opengl.GLEventListener

reshape

public void reshape(javax.media.opengl.GLAutoDrawable gld,
                    int x,
                    int y,
                    int width,
                    int height)
Specified by:
reshape in interface javax.media.opengl.GLEventListener

display

public void display(javax.media.opengl.GLAutoDrawable gld)
Specified by:
display in interface javax.media.opengl.GLEventListener

displayChanged

public void displayChanged(javax.media.opengl.GLAutoDrawable drawable,
                           boolean modeChanged,
                           boolean deviceChanged)
Specified by:
displayChanged in interface javax.media.opengl.GLEventListener

start

public void start(GameIface game)
Description copied from interface: GameIface
Call this method to start the game after every other method that influences the game startup has been called.

Specified by:
start in interface GameIface
Parameters:
game - game object

stop

public void stop()
Description copied from interface: GameIface
This method is used to savely stop the game.

Specified by:
stop in interface GameIface

initResources

public abstract void initResources(javax.media.opengl.GLDrawable gld,
                                   javax.media.opengl.GL gl,
                                   int width,
                                   int height)
Description copied from interface: GameIface
This method is used to initialize all the objects and resources that are neccessary at startup of the game. In your abstract game class you have to make this method abstract and call it in the init() method.

Specified by:
initResources in interface GameIface
Parameters:
gld - GLDrawable object
gl - GL object
width - window width (important viewport initialisation)
height - window height (important viewport initialisation)

update

public abstract void update(long elapsedTime)
Description copied from interface: GameIface
This method is used to update the scene and its content. In your abstract game class you have to make this method abstract and call it within JOGL's display() method. It significant to call this method before the draw() method that is specified in this interface, too to assure correct behaviour of the Monitor and Mirror classes.

Specified by:
update in interface GameIface
Parameters:
elapsedTime - time between two frames

draw

public abstract void draw(javax.media.opengl.GL gl)
Description copied from interface: GameIface
This method is used to draw the scene and its content. In your abstract game class you will have to make this method abstract and call it in the display() method (after the update() method).

Specified by:
draw in interface GameIface

initCamera

public void initCamera(float camX,
                       float camY,
                       float camZ,
                       float rotX,
                       float rotY,
                       float near,
                       float far)
Description copied from interface: GameIface
This method needs to be called before the start() method.

Specified by:
initCamera in interface GameIface
Parameters:
camX - camera's x coordinate
camY - camera's y coordinate
camZ - camera's z coordinate
rotX - camera's rotation around x axis (up/down)
rotY - camera's rotation around y axis (left/right)
near - near clipping plane distance
far - far clipping plane distance

resetElapsedTime

public void resetElapsedTime()
Description copied from interface: GameIface
Resets the calculation of the elapsed time between two frames.

Specified by:
resetElapsedTime in interface GameIface

getMainFrame

public javax.swing.JFrame getMainFrame()
Description copied from interface: GameIface
Returns the main window (main frame) of the game

Specified by:
getMainFrame in interface GameIface
Returns:
main frame of the game

getOGLCanvas

public javax.media.opengl.GLCanvas getOGLCanvas()
Description copied from interface: GameIface
Returns the component that is the OpenGL canvas. This is the canvas that is rendered to.

Specified by:
getOGLCanvas in interface GameIface
Returns:
GLCanvas object

setDisplayMode

public void setDisplayMode(EngineDisplayMode mode)
Description copied from interface: GameIface
Sets the display mode of the game window. You can retrieve the display mode by a call to ScreenResSelector.showSelectionDialog(). A JDialog opens and shows a list of possible display modes. The dialog blocks the application until a mode has been selected and returns the according EngineDisplayMode object.

Specified by:
setDisplayMode in interface GameIface
Parameters:
mode - display mode

setDisplayFPS

public void setDisplayFPS(boolean enable)
Description copied from interface: GameIface
Sets whethter or not the framerate (frames per second) ought to be displayed.

Specified by:
setDisplayFPS in interface GameIface
Parameters:
enable - display fps --> true=yes, false=no

isSetDisplayFPS

public boolean isSetDisplayFPS()
Description copied from interface: GameIface
Determines whether or not the framerate is set to be displayed on screen.

Specified by:
isSetDisplayFPS in interface GameIface
Returns:
is framerate being displayed? --> true=yes, false=no

enableBackFaceCulling

public void enableBackFaceCulling()
Description copied from interface: GameIface
Enables back face culling for a (possibly) slight performance boost.

Specified by:
enableBackFaceCulling in interface GameIface