6

UNDERSTANDING GAME CLASS

Game API Documentation

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.
A fact of Game class

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)

And BaseGraphics, the graphics engine (has been explained in prev page).

Input

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.

Image Loader

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.

Other I/O

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");

Timer

Built-in method for timer:
   setFPS (60);
   getCurrentFPS ();
   getRequestedFPS ();
Wrapping from BaseTimer.

Music

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.

Sound

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 !

1 2 3 4 5 6 7
<< Previous Page Next Page >>