|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
jgame.JGEngine
jgame.StdGame
A basic framework for a game. It supports an animation and game timer, object creation at fixed intervals, score, lives, levels, configurable keys. There are title, start-level, next-level, death, and game-over sequences. Todo: highscores, key configuration file and GUI.
To initialise this class, use the regular initEngine (from main), or initEngineApplet (from parameterless constructor). You can supply the width and height of the window as command line arguments by calling parseSizeArgs(args) from your main(). Define initGame() as usual. StdGame does all its logic in the doFrame method, so you should ensure that it is called (i.e. call super.doFrame() if you choose to override doFrame). The game will automatically start in the "Title" gamestate when it finds that it isn't in this state in the first call to doFrame(). You can also set the "Title" state in initGame if you even want the first frame to be in "Title".
The class uses the following state machine, using JGEngine's state machine mechanism:
Title: displays title screen. Transition to {StartLevel,StartGame} when the key_startgame is pressed. Before the transition, initNewGame(), defineLevel(), and initNewLife() are called.
InGame: game is playing. Transition to LifeLost when lifeLost() is called from within the game. Transition to LevelDone when levelDone() is called from within the game. Transition to GameOver when gameOver() is called (i.e. to quit game). The gametime timer indicates how many ticks the game has been running since the beginning of the level.
StdGame supports a set of standard game sequences, which are represented as game states: StartLevel/StartGame, LevelDone, LifeLost, GameOver. These can be configured so they add the InGame state to the sequence state (i.e. the game is in both states simultaneously). This can be used to animate the game while playing the corresponding sequence. This is off by default. The seqtimer timer is set to 0 at the beginning of each sequence, and increments during the sequence to indicate how many ticks the sequence has been playing. The number of ticks that the sequence should take can be configured, or the sequence can be skipped altogether by setting ticks to 0.
StartGame: start game sequence is played. Transition to InGame after a certain time has elapsed or the contgame key is pressed.
StartLevel: start level sequence is played. Transition to InGame after a certain time has elapsed or the contgame key is pressed. Is always active in combination with StartGame; it's just an indication that StartGame is also a start of a new level.
LevelDone: next level sequence is played. Transition to StartLevel/StartGame after a certain time has elapsed or the contgame key is pressed. Before the transition, resp. incrementLevel() and defineLevel() are called.
LifeLost: player has just died, a death sequence is played. Transition to either GameOver or StartGame after a certain time has elapsed or the contgame key is pressed, dependent of whether there are lives left. Before the transition to StartGame, decrementLives() and initNewLife are called.
GameOver: game over sequence is played. Transition to Title after a certain time or the contgame key is pressed.
Built in are also game exit (through the key_quitgame, which is Escape by default), and pause game (through the key_pausegame, which defaults to 'P').
Field Summary | |
boolean |
gameover_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state. |
int |
gameover_ticks
Number of ticks to stay in GameOver state, 0 = skip |
int |
gametime
Game timer. |
int |
initial_lives
Initial value for lives; default=4 |
int[] |
key_action
Keys for special actions. |
int |
key_contgame
Key for continuing the game when in a sequence, default = space. |
int |
key_down
Key for moving, default = cursors. |
int |
key_downleft
Key for moving diagonally, default = none. |
int |
key_downright
Key for moving diagonally, default = none. |
int |
key_fire
Key for firing (in case there are no separate directional fire keys), default=Shift. |
int |
key_firedown
Key for directional firing, default = WSAD keys |
int |
key_firedownleft
Key for diagonal firing, default = none |
int |
key_firedownright
Key for diagonal firing, default = none |
int |
key_fireleft
Key for directional firing, default = WSAD keys |
int |
key_fireright
Key for directional firing, default = WSAD keys |
int |
key_fireup
Key for directional firing, default = WSAD keys |
int |
key_fireupleft
Key for diagonal firing, default = none |
int |
key_fireupright
Key for diagonal firing, default = none |
int |
key_left
Key for moving, default = cursors. |
int |
key_pausegame
Key for pausing the game, default = P. |
int |
key_quitgame
Key for quitting the game, default = escape. |
int |
key_right
Key for moving, default = cursors. |
int |
key_startgame
Key for starting the game, default = space. |
int |
key_up
Key for moving, default = cursors. |
int |
key_upleft
Key for moving diagonally, default = none. |
int |
key_upright
Key for moving diagonally, default = none. |
int |
level
Difficulty level; starts at 0 at beginning of game. |
boolean |
leveldone_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state. |
int |
leveldone_ticks
Number of ticks to stay in LevelDone state, 0 = skip |
boolean |
lifelost_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state. |
int |
lifelost_ticks
Number of ticks to stay in LifeLost state, 0 = skip |
int |
lives
Lives count, 0 means game over. |
java.lang.String |
lives_img
Image to use to display lives |
int |
score
Player score; starts at 0 at beginning of game. |
int |
seqtimer
Sequence timer. |
int |
stage
Game stage, which is usually the same as level, but typically goes on counting, while level may stop increasing at a certain value. |
boolean |
startgame_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state. |
int |
startgame_ticks
Number of ticks to stay in StartLevel/StartGame state, 0 = skip |
java.awt.Color |
status_color
Color to use to display score |
java.awt.Font |
status_font
Font to use to display score |
int |
timer
Animation timer. |
java.awt.Color |
title_bg_color
Color to use to display background effects behind title and messages |
java.awt.Color |
title_color
Color to use to display title and messages |
java.awt.Font |
title_font
Font to use to display title and messages |
Fields inherited from class jgame.JGEngine |
KeyAlt, KeyCtrl, KeyDown, KeyLeft, KeyMouse1, KeyMouse2, KeyMouse3, KeyRight, KeyShift, KeyUp |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
StdGame()
|
Method Summary | |
boolean |
checkTime(int increment)
Returns true every increment ticks. |
boolean |
checkTime(int min_time,
int max_time,
int increment)
Returns true every increment ticks, but only when gametime is between min_time and max_time. |
void |
decrementLives()
Code for losing a life before transition from LifeLost to InGame is made. |
void |
defineLevel()
Initialise a level. |
void |
doFrame()
The main doFrame takes care of all the standard game actions. |
void |
drawCount(int count,
java.lang.String image,
int x,
int y,
int increment_x)
Draw a row of objects to indicate the value count. |
void |
drawWavyString(java.lang.String s,
int x,
int y,
int align,
int increment_x,
int tmr,
double amplitude,
double pos_phaseshift,
double timer_phaseshift,
java.awt.Font font,
java.awt.Color col)
Draw a string with letters that move up and down individually. |
void |
gameOver()
Call to make straight transition to GameOver; is called automatically by lifeLost when appropriate. |
java.awt.Font |
getZoomingFont(java.awt.Font basefont,
int tmr,
double min_size_fac,
double speed)
Get font for zooming text in and out. |
void |
incrementLevel()
Code for incrementing a level before transition from LevelDone to InGame is made. |
void |
initNewGame()
Initialise the game when a new game is started. |
void |
initNewLife()
Initialise play specifically after a new life is introduced (that is, at game start and after the player has died. |
void |
levelDone()
Call to make state transition to LevelDone. |
void |
lifeLost()
Call to make state transition to LifeLost. |
void |
paintFrame()
Default paintFrame displays score at top left, lives at top right. |
void |
paintFrameGameOver()
Default displays "Game Over!". |
void |
paintFrameLevelDone()
Default displays "Level Done !". |
void |
paintFrameLifeLost()
Default displays "Life Lost !". |
void |
paintFramePaused()
The game is halted in pause mode, but the paintFrame is still done to refresh the screen. |
void |
paintFrameStartGame()
Default displays "Start !". |
void |
paintFrameStartLevel()
Default displays "Level "+(stage+1). |
void |
paintFrameTitle()
Default displays class name as title, and "press [key_startgame] to start" below it. |
static java.awt.Dimension |
parseSizeArgs(java.lang.String[] args)
Parse the first two arguments assuming they are width and height. |
int |
posWalkForwards(int begin_pos,
int end_pos,
int tmr,
int end_time,
int standstill_pos,
int standstill_time,
int standstill_count)
Walk across the screen, standing still momentarily at a specific position. |
void |
setSequences(boolean startgame_ingame,
int startgame_ticks,
boolean leveldone_ingame,
int leveldone_ticks,
boolean lifelost_ingame,
int lifelost_ticks,
boolean gameover_ingame,
int gameover_ticks)
Set all sequence variables in one go. |
void |
setStatusDisplay(java.awt.Font status_font,
java.awt.Color status_color,
java.lang.String lives_img)
Set the status display variables in one go. |
void |
startGameOver()
Initialise game over sequence. |
void |
startInGame()
Initialisation at the start of the in-game action. |
void |
startLevelDone()
Initialise next-level sequence. |
void |
startLifeLost()
Initialise death sequence. |
void |
startStartGame()
Initialise start-game sequence. |
void |
startStartLevel()
Initialise start-level sequence. |
void |
startTitle()
Initialise the title screen. |
Methods inherited from class java.applet.Applet |
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus |
Methods inherited from class java.awt.Panel |
addNotify |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public int key_startgame
public int key_contgame
public int key_quitgame
public int key_pausegame
public int key_left
public int key_right
public int key_up
public int key_down
public int key_upleft
public int key_downleft
public int key_upright
public int key_downright
public int key_fire
public int key_fireleft
public int key_fireright
public int key_fireup
public int key_firedown
public int key_fireupleft
public int key_firedownleft
public int key_fireupright
public int key_firedownright
public int[] key_action
public int gametime
public int seqtimer
public int timer
public int score
public int level
public int stage
public int lives
public int initial_lives
public int startgame_ticks
public int leveldone_ticks
public int lifelost_ticks
public int gameover_ticks
public boolean startgame_ingame
public boolean leveldone_ingame
public boolean lifelost_ingame
public boolean gameover_ingame
public java.awt.Font status_font
public java.awt.Color status_color
public java.lang.String lives_img
public java.awt.Font title_font
public java.awt.Color title_color
public java.awt.Color title_bg_color
Constructor Detail |
public StdGame()
Method Detail |
public void setStatusDisplay(java.awt.Font status_font, java.awt.Color status_color, java.lang.String lives_img)
public void setSequences(boolean startgame_ingame, int startgame_ticks, boolean leveldone_ingame, int leveldone_ticks, boolean lifelost_ingame, int lifelost_ticks, boolean gameover_ingame, int gameover_ticks)
public static java.awt.Dimension parseSizeArgs(java.lang.String[] args)
public void initNewGame()
public void initNewLife()
public void defineLevel()
public void decrementLives()
public void incrementLevel()
public final void lifeLost()
public final void levelDone()
public final void gameOver()
public void doFrame()
doFrame
in class JGEngine
public void startTitle()
public void startInGame()
public void startStartLevel()
public void startStartGame()
public void startLevelDone()
public void startLifeLost()
public void startGameOver()
public void paintFrame()
paintFrame
in class JGEngine
public void paintFrameTitle()
public void paintFramePaused()
public void paintFrameStartLevel()
public void paintFrameStartGame()
public void paintFrameLevelDone()
public void paintFrameLifeLost()
public void paintFrameGameOver()
public boolean checkTime(int min_time, int max_time, int increment)
public boolean checkTime(int increment)
public void drawCount(int count, java.lang.String image, int x, int y, int increment_x)
public void drawWavyString(java.lang.String s, int x, int y, int align, int increment_x, int tmr, double amplitude, double pos_phaseshift, double timer_phaseshift, java.awt.Font font, java.awt.Color col)
public java.awt.Font getZoomingFont(java.awt.Font basefont, int tmr, double min_size_fac, double speed)
public int posWalkForwards(int begin_pos, int end_pos, int tmr, int end_time, int standstill_pos, int standstill_time, int standstill_count)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |