|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.Game
public abstract class Game
Game
class is Golden T Game Engine (GTGE) core class
that initializes all GTGE game engines, wrap the engines up, and setup the
basic game frame work to be play on.
Every game is a subclass of Game
class. And every subclass of
Game
class have to do three things :
How-to-subclass Game
class to create a new game :
(this is the basic skeleton of every game)
import java.awt.*; import com.golden.gamedev.*; public class YourGame extends Game { public void initResources() { // initialize game variables } public void update(long elapsedTime) { // update the game variables } public void render(Graphics2D g) { // render the game to the screen } }
And to launch/init the game use GameLoader
class :
import java.awt.*; import com.golden.gamedev.*; public class YourGame extends Game { public void initResources() { } public void update(long elapsedTime) { } public void render(Graphics2D g) { } public static void main(String[] args) { GameLoader game = new GameLoader(); // init the game with fullscreen mode, 640x480 screen resolution game.setup(new YourGame(), new Dimension(640,480), true); game.start(); } }
There are two main tasks of Game
class that we need to know :
initEngine()
method.
GameLoader
,
initEngine()
Field Summary | |
---|---|
BaseGraphics |
bsGraphics
Graphics engine. |
BaseInput |
bsInput
Input engine. |
BaseIO |
bsIO
I/O file engine. |
BaseLoader |
bsLoader
Image loader engine. |
BaseAudio |
bsMusic
Audio engine for music. |
BaseAudio |
bsSound
Audio engine for sound. |
BaseTimer |
bsTimer
Timer engine. |
protected boolean |
distribute
Indicates whether this game is finished and ready to distribute or still in development stage. |
GameFontManager |
fontManager
Font manager. |
static String |
GTGE_VERSION
Current GTGE version. |
Constructor Summary | |
---|---|
Game()
Creates new instance of Game class, please see note
below. |
Method Summary | |
---|---|
boolean |
checkPosMouse(int x1,
int y1,
int x2,
int y2)
Returns whether the mouse pointer is inside specified screen boundary. |
boolean |
checkPosMouse(Sprite sprite,
boolean pixelCheck)
Returns whether the mouse pointer is inside specified sprite boundary. |
boolean |
click()
Effectively equivalent to the call bsInput.isMousePressed(java.awt.event.MouseEvent.BUTTON1). |
void |
drawFPS(Graphics2D g,
int x,
int y)
Draws game frame-per-second (FPS) to specified location. |
void |
finish()
End the game and back to operating system. |
int |
getCurrentFPS()
Effectively equivalent to the call bsTimer.getCurrentFPS(). |
int |
getFPS()
Effectively equivalent to the call BaseTimer.getFPS(). |
int |
getHeight()
Effectively equivalent to the call bsGraphics.getSize().height. |
BufferedImage |
getImage(String imagefile)
Effectively equivalent to the call bsLoader.getImage(String). |
BufferedImage |
getImage(String imagefile,
boolean useMask)
Effectively equivalent to the call bsLoader.getImage(String, boolean). |
BufferedImage[] |
getImages(String imagefile,
int col,
int row)
Effectively equivalent to the call bsLoader.getImages(String, int, int). |
BufferedImage[] |
getImages(String imagefile,
int col,
int row,
boolean useMask)
Effectively equivalent to the call bsLoader.getImages(String, int, int, boolean). |
BufferedImage[] |
getImages(String imagefile,
int col,
int row,
boolean useMask,
int start,
int end)
Returns stripped images with cropped sequence. |
BufferedImage[] |
getImages(String imagefile,
int col,
int row,
boolean useMask,
String sequence,
int digit)
Returns stripped images with specified sequence. |
BufferedImage[] |
getImages(String imagefile,
int col,
int row,
int start,
int end)
Same as getImages(imagefile, col, row, useMask, start, end) with mask color is turned on by default. |
BufferedImage[] |
getImages(String imagefile,
int col,
int row,
String sequence,
int digit)
Same as getImages(imagefile, col, row, useMask, sequence, digit) with mask color is turned on by default. |
int |
getMouseX()
Effectively equivalent to the call bsInput.getMouseX(). |
int |
getMouseY()
Effectively equivalent to the call bsInput.getMouseY(). |
int |
getRandom(int low,
int hi)
Effectively equivalent to the call Utility.getRandom(int, int) |
int |
getWidth()
Effectively equivalent to the call bsGraphics.getSize().width. |
void |
hideCursor()
Effectively equivalent to the call bsInput.setMouseVisible(false). |
protected void |
initEngine()
Game engines is initialized in this method. |
abstract void |
initResources()
All game resources initialization, everything that usually goes to constructor should be put in here. |
boolean |
isDistribute()
Returns whether this game is ready to distribute or still in development stage. |
boolean |
isFinish()
Returns true, if the game has been finished playing and the game is about to return back to operating system. |
boolean |
isRunning()
Returns whether the game is currently running/playing or not. |
boolean |
keyDown(int keyCode)
Effectively equivalent to the call bsInput.isKeyDown(int). |
boolean |
keyPressed(int keyCode)
Effectively equivalent to the call bsInput.isKeyPressed(int). |
protected void |
notifyError(Throwable error)
Notified of any unexpected or uncatch error thrown by the game when the game is ready to distribute ( distribute = true). |
protected void |
notifyExit()
Notified when the game is about to quit. |
int |
playMusic(String audiofile)
Effectively equivalent to the call bsMusic.play(String). |
int |
playSound(String audiofile)
Effectively equivalent to the call bsSound.play(String). |
abstract void |
render(Graphics2D g)
Renders game to the screen. |
boolean |
rightClick()
Effectively equivalent to the call bsInput.isMousePressed(java.awt.event.MouseEvent.BUTTON3). |
void |
setFPS(int fps)
Effectively equivalent to the call bsTimer.setFPS(int). |
void |
setMaskColor(Color c)
Effectively equivalent to the call bsLoader.setMaskColor(java.awt.Color). |
void |
showCursor()
Effectively equivalent to the call bsInput.setMouseVisible(true). |
void |
showLogo()
Shows GTGE logo/splash screen, GTGE is freeware library, please support GTGE by showing this logo on your game, thank you. |
void |
start()
Starts the game main loop, this method will not return until the game is finished playing/running. |
void |
stop()
Stops the game from running, and to resume the game call start()
method. |
BufferedImage |
takeScreenShot()
Returns a new created buffered image which the current game state is rendered into it. |
void |
takeScreenShot(File f)
Captures current game screen into specified file. |
abstract void |
update(long elapsedTime)
Updates game variables. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String GTGE_VERSION
public BaseGraphics bsGraphics
public BaseIO bsIO
public BaseLoader bsLoader
public BaseInput bsInput
public BaseTimer bsTimer
public BaseAudio bsMusic
public BaseAudio bsSound
public GameFontManager fontManager
protected boolean distribute
A distributed game (distribute = true) will catch any uncatch/unexpected
game exception and send the error to notifyError(Throwable)
method.
When your game is completed and it is time to distribute the game to the world, set this distribute value to true in class initialization :
public class YourGame extends Game { // class initialization, put it here { distribute = true; } // do not put it in initResources() method or other place! public void initResources() { } public void update(long elapsedTime) { } public void render(Graphics2D g) { } }
notifyError(Throwable)
Constructor Detail |
---|
public Game()
Game
class, 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 and simply do not use constructor!
initResources()
,
update(long)
,
render(Graphics2D)
Method Detail |
---|
public void stop()
start()
method. This method is only holding the game, to quit the game call
finish()
instead. During the holding time, no action is taken,
even the game rendering, therefore this method is not suitable for making
game pause event. By default this stop method is only called in applet environment whenever the applet stop method is executed by the webpage.
start()
,
finish()
public void finish()
Only call this method when the game has been finished playing. Calling this method will immediatelly makes the game to quit and the game can not be resumed/played anymore.
stop()
public boolean isFinish()
public boolean isRunning()
start()
public final void start()
finish()
to quit the game or stop()
to hold the game. Be sure the game graphics engine has been initialized (not null) before attempt to call this method.
finish()
,
initEngine()
,
distribute
,
notifyError(Throwable)
,
notifyExit()
protected void initEngine()
List of default game engines initialized in this method :
SystemTimer
AWTInput
MidiRenderer
WaveRenderer
BaseIO
BaseLoader
Example how to modify or change the default game engine :
protected void initEngine() { super.initEngine(); // change the timer engine bsTimer = new GageTimer(); // modify the music engine base renderer bsMusic.setBaseRenderer(new JOrbisOggRenderer()); }
bsGraphics
,
bsIO
,
bsLoader
,
bsInput
,
bsTimer
,
bsMusic
,
bsSound
,
fontManager
,
com.golden.gamedev.engine
public abstract void initResources()
This method is called only once for every newly created Game
class.
getImage(String)
,
getImages(String, int, int)
,
playMusic(String)
,
setMaskColor(Color)
,
com.golden.gamedev.object
public abstract void update(long elapsedTime)
keyDown(int)
,
keyPressed(int)
public abstract void render(Graphics2D g)
g
- backbuffer graphics contextprotected void notifyExit()
System.exit()
to ensure everything is properly
shut down.
Override this method to create a custom exit dialog, and be sure to call
System.exit()
at the end.
protected void notifyError(Throwable error)
distribute
= true).
By default this method creates an
ErrorNotificationDialog
to show the
error to the user.
Override this method to make a custom error dialog, or simply use the ErrorNotificationDialog with your email address provided so the user can directly send the exception to your email.
For example:
protected void notifyError(Throwable error) { new ErrorNotificationDialog(error, bsGraphics, "Game Title v1.0", // the game title "yourmail@address.com"); // your email }
distribute
,
ErrorNotificationDialog
public final boolean isDistribute()
distribute
public final void showLogo()
Keep this method intact!
distribute
,
notifyError(Throwable)
public int getRandom(int low, int hi)
public int getWidth()
public int getHeight()
public BufferedImage takeScreenShot()
public void takeScreenShot(File f)
takeScreenShot()
public int playMusic(String audiofile)
BaseAudio.setBaseRenderer(com.golden.gamedev.engine.BaseAudioRenderer)
,
com.golden.gamedev.engine.audio
public int playSound(String audiofile)
BaseAudio.setBaseRenderer(com.golden.gamedev.engine.BaseAudioRenderer)
,
com.golden.gamedev.engine.audio
public void setFPS(int fps)
public int getCurrentFPS()
public int getFPS()
public void drawFPS(Graphics2D g, int x, int y)
public int getMouseX()
public int getMouseY()
public boolean checkPosMouse(int x1, int y1, int x2, int y2)
public boolean checkPosMouse(Sprite sprite, boolean pixelCheck)
sprite
- sprite to check its intersection with mouse pointerpixelCheck
- true, checking the sprite image with pixel precisionpublic boolean click()
public boolean rightClick()
public boolean keyDown(int keyCode)
public boolean keyPressed(int keyCode)
public void hideCursor()
public void showCursor()
public void setMaskColor(Color c)
public BufferedImage getImage(String imagefile, boolean useMask)
public BufferedImage getImage(String imagefile)
public BufferedImage[] getImages(String imagefile, int col, int row, boolean useMask)
public BufferedImage[] getImages(String imagefile, int col, int row)
public BufferedImage[] getImages(String imagefile, int col, int row, boolean useMask, String sequence, int digit)
First the image is stripped by column and row, and then the images is arranged with specified sequence order. The images then stored into cache (bsLoader) with key as followed: the image file + sequence + digit.
For example:
// we want the images sequence is as followed String sequence = "020120"; BufferedImage[] image = getImages("imagestrip.png", 3, 1, true, sequence, 1); // this is plain same like above code except we use 2 digits here // 2 digits is used for image strip larger than 10 String sequence = "000200010200"; BufferedImage[] image = getImages("imagestrip.png", 20, 1, true, sequence, 1);Notice that the first image is start from 0 (zero).
This is used to make custom animation (012321).
public BufferedImage[] getImages(String imagefile, int col, int row, String sequence, int digit)
public BufferedImage[] getImages(String imagefile, int col, int row, boolean useMask, int start, int end)
First the image is stripped by column and row, and then the images is arranged with specified series sequence order. The images then stored into cache (bsLoader with key as followed: start sequence + the image file + end sequence.
For example:
int start = 2, end = 4; BufferedImage[] image = getImages("imagestrip.png", 6, 1, true, start, end);Notice that the first image is start from 0 (zero).
public BufferedImage[] getImages(String imagefile, int col, int row, int start, int end)
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |