GTGE API

com.golden.gamedev
Class GameObject

java.lang.Object
  extended by com.golden.gamedev.GameObject

public abstract class GameObject
extends Object

Similar like Game class except this class is working under GameEngine frame work.

GameObject class is plain same with Game class, you can first create the game as Game class, run it, test it, and then rename it to GameObject and attach it to GameEngine frame work as one of game entities.

Please read GameEngine documentation for more information about how to work with GameObject class.

See Also:
GameEngine, Game

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.
 GameFontManager fontManager
          Font manager.
 GameEngine parent
          The master GameEngine frame work.
 
Constructor Summary
GameObject(GameEngine parent)
          Creates new GameObject with specified GameEngine as the master engine.
 
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 this game, and back to game object chooser.
 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).
abstract  void initResources()
          All game resources initialization, everything that usually goes to constructor should be put in here.
 boolean keyDown(int keyCode)
          Effectively equivalent to the call bsInput.isKeyDown(int).
 boolean keyPressed(int keyCode)
          Effectively equivalent to the call bsInput.isKeyPressed(int).
 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 start()
          Starts the game main loop, this method will not return until the game is finished playing/running.
 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

parent

public final GameEngine parent
The master GameEngine frame work.


bsGraphics

public BaseGraphics bsGraphics
Graphics engine.


bsIO

public BaseIO bsIO
I/O file engine.


bsLoader

public BaseLoader bsLoader
Image loader engine.


bsInput

public BaseInput bsInput
Input engine.


bsTimer

public BaseTimer bsTimer
Timer engine.


bsMusic

public BaseAudio bsMusic
Audio engine for music.


bsSound

public BaseAudio bsSound
Audio engine for sound.


fontManager

public GameFontManager fontManager
Font manager.

Constructor Detail

GameObject

public GameObject(GameEngine parent)
Creates new GameObject with specified GameEngine as the master engine.

Method Detail

start

public final void start()
Starts the game main loop, this method will not return until the game is finished playing/running. To end the game call finish() method.


finish

public void finish()
End this game, and back to game object chooser.

See Also:
GameEngine.nextGameID, GameEngine.nextGame

initResources

public abstract void initResources()
All game resources initialization, everything that usually goes to constructor should be put in here.

This method is called only once for every newly created GameObject class.

See Also:
getImage(String), getImages(String, int, int), playMusic(String), setMaskColor(Color), com.golden.gamedev.object

update

public abstract void update(long elapsedTime)
Updates game variables.

See Also:
keyDown(int), keyPressed(int)

render

public abstract void render(Graphics2D g)
Renders game to the screen.

Parameters:
g - backbuffer graphics context

getRandom

public int getRandom(int low,
                     int hi)
Effectively equivalent to the call Utility.getRandom(int, int)


getWidth

public int getWidth()
Effectively equivalent to the call bsGraphics.getSize().width.


getHeight

public int getHeight()
Effectively equivalent to the call bsGraphics.getSize().height.


takeScreenShot

public BufferedImage takeScreenShot()
Returns a new created buffered image which the current game state is rendered into it.


takeScreenShot

public void takeScreenShot(File f)
Captures current game screen into specified file.

See Also:
takeScreenShot()

playMusic

public int playMusic(String audiofile)
Effectively equivalent to the call bsMusic.play(String).

See Also:
BaseAudio.setBaseRenderer(com.golden.gamedev.engine.BaseAudioRenderer), com.golden.gamedev.engine.audio

playSound

public int playSound(String audiofile)
Effectively equivalent to the call bsSound.play(String).

See Also:
BaseAudio.setBaseRenderer(com.golden.gamedev.engine.BaseAudioRenderer), com.golden.gamedev.engine.audio

setFPS

public void setFPS(int fps)
Effectively equivalent to the call bsTimer.setFPS(int).


getCurrentFPS

public int getCurrentFPS()
Effectively equivalent to the call bsTimer.getCurrentFPS().


getFPS

public int getFPS()
Effectively equivalent to the call BaseTimer.getFPS().


drawFPS

public void drawFPS(Graphics2D g,
                    int x,
                    int y)
Draws game frame-per-second (FPS) to specified location.


getMouseX

public int getMouseX()
Effectively equivalent to the call bsInput.getMouseX().


getMouseY

public int getMouseY()
Effectively equivalent to the call bsInput.getMouseY().


checkPosMouse

public boolean checkPosMouse(int x1,
                             int y1,
                             int x2,
                             int y2)
Returns whether the mouse pointer is inside specified screen boundary.


checkPosMouse

public boolean checkPosMouse(Sprite sprite,
                             boolean pixelCheck)
Returns whether the mouse pointer is inside specified sprite boundary.

Parameters:
sprite - sprite to check its intersection with mouse pointer
pixelCheck - true, checking the sprite image with pixel precision

click

public boolean click()
Effectively equivalent to the call bsInput.isMousePressed(java.awt.event.MouseEvent.BUTTON1).


rightClick

public boolean rightClick()
Effectively equivalent to the call bsInput.isMousePressed(java.awt.event.MouseEvent.BUTTON3).


keyDown

public boolean keyDown(int keyCode)
Effectively equivalent to the call bsInput.isKeyDown(int).


keyPressed

public boolean keyPressed(int keyCode)
Effectively equivalent to the call bsInput.isKeyPressed(int).


hideCursor

public void hideCursor()
Effectively equivalent to the call bsInput.setMouseVisible(false).


showCursor

public void showCursor()
Effectively equivalent to the call bsInput.setMouseVisible(true).


setMaskColor

public void setMaskColor(Color c)
Effectively equivalent to the call bsLoader.setMaskColor(java.awt.Color).


getImage

public BufferedImage getImage(String imagefile,
                              boolean useMask)
Effectively equivalent to the call bsLoader.getImage(String, boolean).


getImage

public BufferedImage getImage(String imagefile)
Effectively equivalent to the call bsLoader.getImage(String).


getImages

public BufferedImage[] getImages(String imagefile,
                                 int col,
                                 int row,
                                 boolean useMask)
Effectively equivalent to the call bsLoader.getImages(String, int, int, boolean).


getImages

public BufferedImage[] getImages(String imagefile,
                                 int col,
                                 int row)
Effectively equivalent to the call bsLoader.getImages(String, int, int).


getImages

public BufferedImage[] getImages(String imagefile,
                                 int col,
                                 int row,
                                 boolean useMask,
                                 String sequence,
                                 int digit)
Returns stripped images with specified sequence.

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).


getImages

public 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.


getImages

public BufferedImage[] getImages(String imagefile,
                                 int col,
                                 int row,
                                 boolean useMask,
                                 int start,
                                 int end)
Returns stripped images with cropped sequence.

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).


getImages

public 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.


GTGE API

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