GTGE API

com.golden.gamedev
Class GameEngine

java.lang.Object
  extended by com.golden.gamedev.Game
      extended by com.golden.gamedev.GameEngine

public abstract class GameEngine
extends Game

Extending Game class functionality to be able to handle multiple game screen in order to separate game logic into separated entities. For example: manage intro screen, title screen, menu screen, and main game screen as separated entity.

Each game entity is subclass of GameObject class (in above example: intro, title, main game screen are subclass of GameObject class). GameObject class is equally with Game class except it works under GameEngine frame work. Thus you can create the game entities as Game class first, run and test it like usual, and then rename it to GameObject in order to attach it into GameEngine frame work.

The first game to be played is GameObject which use ID = 0.

GameEngine class also can be used to store global variables that can be accessed within all game object entities.

Example how-to-use GameEngine class:

 import com.golden.gamedev.*;

 public class YourGame extends GameEngine {

    public GameObject getGame(int GameID) {
       switch (GameID) {
          case 0: // GameID = 0 is always the first to play
             return new IntroMenu(this);
          case 1: return new ......
          case 2: return new ......
       }

       return null;
    }

    public static void main(String[] args) {
       // GameEngine class creation is equal with Game class creation
       GameLoader game = new GameLoader();
       game.setup(new YourGame(), new Dimension(640,480), false);
       game.start();
    }

 }


 public class IntroMenu extends GameObject { // change Game to GameObject

    public GameObject(GameEngine parent) {
       super(parent);
    }

    public void update(long elapsedTime) {
       if (....) { // change screen
          // GameObject with ID = 1 will be played next
          parent.nextGameID = 1;
          finish();
       }
    }

 }
 

See Also:
GameObject

Field Summary
 GameObject nextGame
          GameObject to be played next, null to exit game.
 int nextGameID
          Game ID to be played next, -1 to exit game.
 
Fields inherited from class com.golden.gamedev.Game
bsGraphics, bsInput, bsIO, bsLoader, bsMusic, bsSound, bsTimer, distribute, fontManager, GTGE_VERSION
 
Constructor Summary
GameEngine()
          Creates new GameEngine, the first game to be played is GameObject with ID = 0 (zero), please see note below.
 
Method Summary
 GameObject getCurrentGame()
          Returns currently playing GameObject entity.
 int getCurrentGameID()
          Returns the ID of currently playing GameObject entity.
abstract  GameObject getGame(int GameID)
          Returns GameObject with specific ID, the returned GameObject will be the game to be played next.
 void initResources()
          Initialization of global game resources.
 void refresh()
          Refresh game global variables, called right before playing next game object.
 void render(Graphics2D g)
          Global game render.
 void update(long elapsedTime)
          Global game update.
 
Methods inherited from class com.golden.gamedev.Game
checkPosMouse, checkPosMouse, click, drawFPS, finish, getCurrentFPS, getFPS, getHeight, getImage, getImage, getImages, getImages, getImages, getImages, getImages, getImages, getMouseX, getMouseY, getRandom, getWidth, hideCursor, initEngine, isDistribute, isFinish, isRunning, keyDown, keyPressed, notifyError, notifyExit, playMusic, playSound, rightClick, setFPS, setMaskColor, showCursor, showLogo, start, stop, takeScreenShot, takeScreenShot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextGame

public GameObject nextGame
GameObject to be played next, null to exit game.

See Also:
nextGameID

nextGameID

public int nextGameID
Game ID to be played next, -1 to exit game.

See Also:
nextGame
Constructor Detail

GameEngine

public GameEngine()
Creates new GameEngine, the first game to be played is GameObject with ID = 0 (zero), please see note below.

Note: Do not make any overloading constructors. All that belong to constructor (this method) should be put in initResources() method. Leave this method empty!

Method Detail

initResources

public void initResources()
Initialization of global game resources.

The implementation of this method provided by the GameEngine class does nothing.

Specified by:
initResources in class Game
See Also:
Game.getImage(String), Game.getImages(String, int, int), Game.playMusic(String), Game.setMaskColor(Color), com.golden.gamedev.object

update

public void update(long elapsedTime)
Global game update.

The implementation of this method provided by the GameEngine class does nothing.

Specified by:
update in class Game
Parameters:
elapsedTime - time elapsed since last update
See Also:
Game.keyDown(int), Game.keyPressed(int)

render

public void render(Graphics2D g)
Global game render.

The implementation of this method provided by the GameEngine class does nothing.

Specified by:
render in class Game
Parameters:
g - graphics backbuffer

refresh

public void refresh()
Refresh game global variables, called right before playing next game object.

The implementation of this method provided by the GameEngine class does nothing.


getGame

public abstract GameObject getGame(int GameID)
Returns GameObject with specific ID, the returned GameObject will be the game to be played next.

Parameters:
GameID - the id of the GameObject
Returns:
GameObject to be played next.
See Also:
nextGame

getCurrentGame

public GameObject getCurrentGame()
Returns currently playing GameObject entity.


getCurrentGameID

public int getCurrentGameID()
Returns the ID of currently playing GameObject entity.


GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id