Game class is the core of every game.
It is a big wrapper of all available game engine. It initialize game engine and use it in game.
Almost all methods in Game class are
simply called its game engine method.
For example Game class playMusic method:
public abstract class Game extends HybridMode {
protected BaseAudio bsMusic;
public void playMusic(String audiofile) {
bsMusic.play (audiofile);
}
}
From there you could see, Game class playMusic method is simply called the bsMusic play method (audio engine).
So it is technically same if you want to use the engine method directly.
We use this kind of wrapper for
convenient and easy to code.
Note:
not all game engine methods are wrapped, only common and frequently used methods is wrapped.
Let's see all wrapped game engine and how to use it.
Game Engine
Game class has 7 engines wrapped :
(see com.golden.gamedev.engine package)
- BaseInput bsInput : polling game input (keyboard, mouse).
- BaseLoader bsLoader : the image loader.
- BaseIO bsIO : getting external resources, such as java.io.File, java.net.URL.
- BaseTimer bsTimer : game timer to make constant frame rate.
- BaseAudio bsMusic : audio engine for playing music (an exclusive and continous sound).
- BaseAudio bsSound : audio engine for playing sound.
And BaseGraphics, the graphics engine (has been explained in
prev page).
GTGE currently supports only
keyboard and
mouse input (joystick not supported).
Note: only graphics engine is manually setup, input and other game engine is automatically set by Game class.
Keyboard
Built-in method for keyboard:
keyDown (java.awt.event.KeyEvent.VK_SHIFT);
keyPressed (java.awt.event.KeyEvent.VK_SHIFT);
keyDown is always print true while specified button is being pressed.
keyPressed print true only once the specified button pressed.
Mouse
Built-in method for mouse:
click ();
rightClick ();
middleClick ();
getMouseX ();
getMouseY ();
checkPosMouse (10, 10, 100, 100);
Game class is wrapping input methods from
BaseInput.
Game class has several built-in method for
loading image.
The commonly used are:
java.awt.image.BufferedImage image = getImage ("block.gif");
java.awt.image.BufferedImage[] images = getImages ("block.gif", 1, 1);
For complete method see
Game API Documentation.
Game class is wrapping image methods from
BaseLoader.
Game class does not provide built-in method for input/output, use directly from
BaseIO class instead.
BaseIO class provides methods to
get external resources, such as java.io.File, java.net.URL, etc.
java.io.File f = bsIO.getFile ("filename.ext");
Built-in method for
timer:
setFPS (60);
getCurrentFPS ();
getRequestedFPS ();
Wrapping from
BaseTimer.
Music is a sound that play continously and exclusive (only one sound can be played at once).
Built-in method for
playing music:
playMusic ("music1.wav");
Wrapping from
BaseAudio.
Built-in method for
playing sound:
playSound ("fire.wav");
Wrapping from
BaseAudio.
Now you should have understand the basic concept of a game.
Next we're going into the fun part (the game aspect), SPRITE !