|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Panel java.applet.Applet jgame.platform.JGEngine jgame.platform.StdGame
public abstract class 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, game-over, and highscore sequences.
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 continuegame key is pressed.
StartLevel: start level sequence is played. Transition to InGame after a certain time has elapsed or the continuegame 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 continuegame 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 continuegame 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 continuegame key is pressed.
Built in are also game exit (through the key_quitgame, which is Escape by default), pause game (through the key_pausegame, which defaults to 'P'), and program exit (key_quitprogram, default Escape).
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.applet.Applet |
---|
java.applet.Applet.AccessibleApplet |
Nested classes/interfaces inherited from class java.awt.Panel |
---|
java.awt.Panel.AccessibleAWTPanel |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
boolean |
accel_set_zero_menu
flag indicating that accelerometer set zero point menu should be active. |
AppConfig |
appconfig
The application configuration handler. |
boolean |
audio_dialog_at_startup
Flag indicating that sound enable dialog should be shown at startup |
boolean |
audioenabled
Flag indicating that audio is enabled |
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 |
double |
gametime
Game timer. |
JGColor |
highscore_color
Color to use to display highscores |
java.lang.String |
highscore_entry
String to display above highscore entry screen. |
JGFont |
highscore_font
Font to use to display highscores |
int |
highscore_maxnamelen
Maximum length of name typed by user. |
int |
highscore_showtime
Time to show highscores before going back to title screen. |
java.lang.String |
highscore_title
Title string to display above highscores |
JGColor |
highscore_title_color
Color to use to display highscore title information |
JGFont |
highscore_title_font
Font to use to display highscore title information |
int |
highscore_waittime
Time to wait in title screen before showing highscores. |
Highscore[] |
highscores
Highscore table, null (default) means not defined. |
int |
initial_lives
Initial value for lives; default=4 |
int |
key_action
Key for special action, default is X for JRE, 8 for MIDP. |
int |
key_continuegame
Key for continuing the game when in a sequence, JRE default is space, MIDP default is "*" |
int |
key_down
Key for moving, default = cursors. |
int |
key_fire
Key for firing (in case there are no separate directional fire keys), JRE default is Z, MIDP default is Fire. |
int |
key_firedown
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP. |
int |
key_fireleft
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP. |
int |
key_fireright
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP. |
int |
key_fireup
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP. |
int |
key_gamesettings
Key for invoking the game settings window, default = enter. |
int |
key_left
Key for moving, default = cursors. |
int |
key_pausegame
Key for pausing the game, JRE default is P, MIDP default is '0' |
int |
key_quitgame
Key for quitting the current game, JRE default is escape, MIDP default is "#". |
int |
key_quitprogram
Key for quitting the program, JRE default is escape, MIDP default is "#". |
int |
key_right
Key for moving, default = cursors. |
int |
key_startgame
Key for starting the game, JRE default is space, MIDP default is "*" |
int |
key_up
Key for moving, default = cursors. |
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 |
java.lang.String |
playername
Player's name being entered in EnterHighscore; is reset to the empty string before the EnterHighscore state is entered. |
int |
score
Player score; starts at 0 at beginning of game. |
double |
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 |
JGColor |
status_color
Color to use to display score |
JGFont |
status_font
Font to use to display score |
int |
status_l_margin
Horizontal margins to be used by status displays, default 12 pixels. |
int |
status_r_margin
Horizontal margins to be used by status displays, default 12 pixels. |
double |
timer
Animation timer. |
JGColor |
title_bg_color
Color to use to display background effects behind title and messages |
JGColor |
title_color
Color to use to display title and messages |
JGFont |
title_font
Font to use to display title and messages |
Fields inherited from class jgame.platform.JGEngine |
---|
KeyBackspace, KeyTab |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface jgame.impl.JGEngineInterface |
---|
CROSSHAIR_CURSOR, DEFAULT_CURSOR, HAND_CURSOR, JGameVersionString, KeyAlt, KeyCtrl, KeyDown, KeyEnter, KeyEsc, KeyFire, KeyLeft, KeyMouse1, KeyMouse2, KeyMouse3, KeyPound, KeyRight, KeyShift, KeyStar, KeyUp, NO_CURSOR, WAIT_CURSOR |
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. |
JGColor |
cycleColor(JGColor[] cycle,
double tmr,
double speed)
Get a colour from a colour cycle. |
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 |
doFrameEnterHighscore()
Default lets user type name into the variable playername. |
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,
double tmr,
double amplitude,
double pos_phaseshift,
double timer_phaseshift,
JGFont font,
JGColor 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. |
double[] |
getAccelZeroCorrected()
get zero vector corrected acceleration vector (slow) |
double[] |
getAccelZeroVector()
|
JGFont |
getZoomingFont(JGFont basejgfont,
double 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 |
initAppConfig()
Define appconfig for configuring keys. |
void |
initNewGame(int level_selected)
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 |
paintFrameEnterHighscore()
Default displays highscore_entry, and the player's score and playername currently being entered. |
void |
paintFrameGameOver()
Default displays "Game Over!". |
void |
paintFrameHighscores()
Default displays the highscore list. |
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 JGPoint |
parseSizeArgs(java.lang.String[] args,
int arg_ofs)
Look for two arguments starting at index arg_ofs, and parse them as width and height. |
int |
posWalkForwards(int begin_pos,
int end_pos,
double tmr,
int end_time,
int standstill_pos,
int standstill_time,
int standstill_count)
Walk across the screen, standing still momentarily at a specific position. |
boolean |
saveHighscores()
Try to save highscores to default location, $HOMEDIR/.jgame/$CLASSNAME.hsc. |
void |
setHighscoreDisplay(int waittime,
int showtime,
JGFont font,
JGColor color,
java.lang.String title,
java.lang.String entry,
JGFont titlefont,
JGColor titlecolor)
Set highscore display settings. |
void |
setHighscores(int nr_highscores,
Highscore default_hisc,
int maxnamelen)
Define highscore table. |
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(JGFont status_font,
JGColor status_color,
java.lang.String lives_img)
Set the status display variables in one go. |
void |
startEnterHighscore()
Initialise enter-highscore screen. |
void |
startGame()
Start game at level 0 |
void |
startGame(int level_selected)
Start game at given level |
void |
startGameOver()
Initialise game over sequence. |
void |
startHighscores()
Initialise the highscore display. |
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, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public boolean audioenabled
public boolean audio_dialog_at_startup
public boolean accel_set_zero_menu
public int key_startgame
public int key_gamesettings
public int key_continuegame
public int key_quitgame
public int key_quitprogram
public int key_pausegame
public int key_left
public int key_right
public int key_up
public int key_down
public int key_fire
public int key_fireleft
public int key_fireright
public int key_fireup
public int key_firedown
public int key_action
public double gametime
public double seqtimer
public double 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 int status_l_margin
public int status_r_margin
public JGFont status_font
public JGColor status_color
public java.lang.String lives_img
public JGFont title_font
public JGColor title_color
public JGColor title_bg_color
public AppConfig appconfig
public Highscore[] highscores
public int highscore_maxnamelen
public java.lang.String playername
public int highscore_waittime
public int highscore_showtime
public JGFont highscore_font
public JGColor highscore_color
public JGFont highscore_title_font
public JGColor highscore_title_color
public java.lang.String highscore_title
public java.lang.String highscore_entry
Constructor Detail |
---|
public StdGame()
Method Detail |
---|
public void setStatusDisplay(JGFont status_font, JGColor 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 double[] getAccelZeroVector()
public double[] getAccelZeroCorrected()
public void setHighscores(int nr_highscores, Highscore default_hisc, int maxnamelen)
public void setHighscoreDisplay(int waittime, int showtime, JGFont font, JGColor color, java.lang.String title, java.lang.String entry, JGFont titlefont, JGColor titlecolor)
public static JGPoint parseSizeArgs(java.lang.String[] args, int arg_ofs)
public void initNewGame(int level_selected)
public void initNewLife()
public void defineLevel()
public void decrementLives()
public void incrementLevel()
public void startGame()
public void startGame(int level_selected)
public final void lifeLost()
public final void levelDone()
public final void gameOver()
public void initAppConfig()
appconfig = new AppConfig("[title]", this, getConfigPath("[filename]");getConfigPath returns a path to a writable file in [user.home]/.jgame/
public void doFrame()
doFrame
in interface JGEngineInterface
doFrame
in class JGEngine
public void doFrameEnterHighscore()
public boolean saveHighscores()
public void startTitle()
public void startHighscores()
public void startInGame()
public void startStartLevel()
public void startStartGame()
public void startLevelDone()
public void startLifeLost()
public void startGameOver()
public void startEnterHighscore()
public void paintFrame()
paintFrame
in interface JGEngineInterface
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 void paintFrameEnterHighscore()
public void paintFrameHighscores()
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, double tmr, double amplitude, double pos_phaseshift, double timer_phaseshift, JGFont font, JGColor col)
public JGFont getZoomingFont(JGFont basejgfont, double tmr, double min_size_fac, double speed)
public JGColor cycleColor(JGColor[] cycle, double tmr, double speed)
public int posWalkForwards(int begin_pos, int end_pos, double 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 |