|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.Game
com.golden.gamedev.GameEngine
public abstract class GameEngine
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(); } } }
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 |
---|
public GameObject nextGame
nextGameID
public int nextGameID
nextGame
Constructor Detail |
---|
public GameEngine()
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 |
---|
public void initResources()
The implementation of this method provided by the GameEngine
class does nothing.
initResources
in class Game
Game.getImage(String)
,
Game.getImages(String, int, int)
,
Game.playMusic(String)
,
Game.setMaskColor(Color)
,
com.golden.gamedev.object
public void update(long elapsedTime)
The implementation of this method provided by the GameEngine
class does nothing.
update
in class Game
elapsedTime
- time elapsed since last updateGame.keyDown(int)
,
Game.keyPressed(int)
public void render(Graphics2D g)
The implementation of this method provided by the GameEngine
class does nothing.
render
in class Game
g
- graphics backbufferpublic void refresh()
The implementation of this method provided by the GameEngine
class does nothing.
public abstract GameObject getGame(int GameID)
GameObject
with specific ID, the returned GameObject
will be the game to be played next.
GameID
- the id of the GameObject
nextGame
public GameObject getCurrentGame()
GameObject
entity.
public int getCurrentGameID()
GameObject
entity.
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |