jgame.platform
Class StdGame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by jgame.platform.JGEngine
                      extended by jgame.platform.StdGame
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, JGEngineInterface

public abstract class StdGame
extends JGEngine

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

See Also:
Serialized Form

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 jgame.platform.JGEngine
addGameState, and, andTileCid, atan2, checkBGCollision, checkBGCollision, checkCollision, checkCollision, clearGameState, clearKey, clearLastKey, clearMouseButton, countObjects, countObjects, countTiles, dbgExceptionToString, dbgPrint, dbgPrint, dbgSetDebugColor1, dbgSetDebugColor2, dbgSetMessageExpiry, dbgSetMessageFont, dbgShowBoundingBox, dbgShowException, dbgShowFullStackTrace, dbgShowGameState, dbgShowMessagesInPf, defineAnimation, defineAnimation, defineAudioClip, defineImage, defineImage, defineImage, defineImage, defineImageMap, defineImageRotated, defineMedia, destroy, destroyApp, disableAudio, displayHeight, displayWidth, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImageString, drawImageString, drawLine, drawLine, drawLine, drawOval, drawOval, drawOval, drawPolygon, drawRect, drawRect, drawRect, drawRect, drawRect, drawString, drawString, drawString, drawTile, enableAudio, existsObject, exitEngine, fillBG, getAccelVec, getAccelX, getAccelY, getAccelZ, getAnimation, getAWTColor, getBufferGraphics, getConfigPath, getFontHeight, getFrameRate, getFrameSkip, getGameSpeed, getImage, getImageBBox, getImageSize, getKey, getKeyCode, getKeyCodeStatic, getKeyDesc, getKeyDescStatic, getLastKey, getLastKeyChar, getMinScaleFactor, getMouseButton, getMouseInside, getMousePos, getMouseX, getMouseY, getObject, getObjects, getOffscreenMarginX, getOffscreenMarginY, getTileCid, getTileCid, getTileCid, getTileCidAtCoord, getTileCoord, getTileCoord, getTileIndex, getTiles, getTiles, getTileStr, getTileStr, getTileStrAtCoord, getVideoSyncedUpdate, getXAlignOfs, getXDist, getXScaleFactor, getYAlignOfs, getYDist, getYScaleFactor, hasAccelerometer, inGameState, inGameStateNextFrame, init, initCanvas, initEngine, initEngineApplet, initEngineComponent, initGame, invokeUrl, isAndroid, isApplet, isMidlet, isOpenGL, isRunning, isXAligned, isYAligned, lastPlayedAudio, markAddObject, moduloXPos, moduloYPos, moveObjects, moveObjects, optsAddBoolean, optsAddEnum, optsAddKey, optsAddNumber, optsAddString, optsAddTitle, optsClear, orTileCid, pauseApp, pfHeight, pfTilesX, pfTilesY, pfWidth, pfWrapX, pfWrapY, playAudio, playAudio, random, random, random, registerTimer, removeAllTimers, removeGameState, removeObject, removeObjects, removeObjects, requestGameFocus, setAuthorMessage, setBGColor, setBGImage, setBGImage, setBGImgOffset, setBlendMode, setCanvasSettings, setColor, setColorsFont, setFGColor, setFont, setFont, setFrameRate, setGameSpeed, setGameState, setKey, setMouseButton, setMouseCursor, setMouseCursor, setMsgFont, setOffscreenMargin, setPFSize, setPFWrap, setProgressBar, setProgressMessage, setRenderSettings, setScalingPreferences, setSmoothing, setStroke, setTextOutline, setTile, setTile, setTileCid, setTileCid, setTiles, setTileSettings, setTilesMulti, setVideoSyncedUpdate, setViewOffset, setViewZoomRotate, snapToGrid, snapToGridX, snapToGridY, start, startApp, stop, stopAudio, stopAudio, storeExists, storeReadDouble, storeReadInt, storeReadString, storeRemove, storeWriteDouble, storeWriteInt, storeWriteString, tileHeight, tileIDToStr, tileStrToID, tileWidth, viewHeight, viewTilesX, viewTilesY, viewWidth, viewXOfs, viewYOfs, wakeUpOnKey
 
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

audioenabled

public boolean audioenabled
Flag indicating that audio is enabled


audio_dialog_at_startup

public boolean audio_dialog_at_startup
Flag indicating that sound enable dialog should be shown at startup


accel_set_zero_menu

public boolean accel_set_zero_menu
flag indicating that accelerometer set zero point menu should be active.


key_startgame

public int key_startgame
Key for starting the game, JRE default is space, MIDP default is "*"


key_gamesettings

public int key_gamesettings
Key for invoking the game settings window, default = enter.


key_continuegame

public int key_continuegame
Key for continuing the game when in a sequence, JRE default is space, MIDP default is "*"


key_quitgame

public int key_quitgame
Key for quitting the current game, JRE default is escape, MIDP default is "#".


key_quitprogram

public int key_quitprogram
Key for quitting the program, JRE default is escape, MIDP default is "#".


key_pausegame

public int key_pausegame
Key for pausing the game, JRE default is P, MIDP default is '0'


key_left

public int key_left
Key for moving, default = cursors.


key_right

public int key_right
Key for moving, default = cursors.


key_up

public int key_up
Key for moving, default = cursors.


key_down

public int key_down
Key for moving, default = cursors.


key_fire

public int key_fire
Key for firing (in case there are no separate directional fire keys), JRE default is Z, MIDP default is Fire.


key_fireleft

public int key_fireleft
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP.


key_fireright

public int key_fireright
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP.


key_fireup

public int key_fireup
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP.


key_firedown

public int key_firedown
Key for directional firing, default is WSAD keys for JRE, 2456 for MIDP.


key_action

public int key_action
Key for special action, default is X for JRE, 8 for MIDP.


gametime

public double gametime
Game timer. Is reset to 0 at the beginning of each level, increments with gamespeed during InGame.


seqtimer

public double seqtimer
Sequence timer. Is reset to 0 at the start of the Title, Highscores, EnterHighscore, StartLevel, StartGame, LevelDone, LifeLost, GameOver sequences. Increments with gamespeed always. Can be used to time animations for these sequences.


timer

public double timer
Animation timer. Always increments with gamespeed. Can be used to time animations etc.


score

public int score
Player score; starts at 0 at beginning of game.


level

public int level
Difficulty level; starts at 0 at beginning of game. Can be incremented each time a level is complete. Can be used to determine game difficulty settings throughout the game.


stage

public 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. Can be used to vary graphic sets, display stage number, etc.


lives

public int lives
Lives count, 0 means game over.


initial_lives

public int initial_lives
Initial value for lives; default=4


startgame_ticks

public int startgame_ticks
Number of ticks to stay in StartLevel/StartGame state, 0 = skip


leveldone_ticks

public int leveldone_ticks
Number of ticks to stay in LevelDone state, 0 = skip


lifelost_ticks

public int lifelost_ticks
Number of ticks to stay in LifeLost state, 0 = skip


gameover_ticks

public int gameover_ticks
Number of ticks to stay in GameOver state, 0 = skip


startgame_ingame

public boolean startgame_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state.


leveldone_ingame

public boolean leveldone_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state.


lifelost_ingame

public boolean lifelost_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state.


gameover_ingame

public boolean gameover_ingame
Indicates whether the InGame state should be retained when in the corresponding sequence state.


status_l_margin

public int status_l_margin
Horizontal margins to be used by status displays, default 12 pixels.


status_r_margin

public int status_r_margin
Horizontal margins to be used by status displays, default 12 pixels.


status_font

public JGFont status_font
Font to use to display score


status_color

public JGColor status_color
Color to use to display score


lives_img

public java.lang.String lives_img
Image to use to display lives


title_font

public JGFont title_font
Font to use to display title and messages


title_color

public JGColor title_color
Color to use to display title and messages


title_bg_color

public JGColor title_bg_color
Color to use to display background effects behind title and messages


appconfig

public AppConfig appconfig
The application configuration handler. Default is null, use initAppConfig to initialise it.


highscores

public Highscore[] highscores
Highscore table, null (default) means not defined. Use setHighscores to define the table. If defined, the game will handle highscores by means of the states Highscores and EnterHighscore.


highscore_maxnamelen

public int highscore_maxnamelen
Maximum length of name typed by user.


playername

public java.lang.String playername
Player's name being entered in EnterHighscore; is reset to the empty string before the EnterHighscore state is entered. Is altered by doFrameEnterHighscore.


highscore_waittime

public int highscore_waittime
Time to wait in title screen before showing highscores.


highscore_showtime

public int highscore_showtime
Time to show highscores before going back to title screen.


highscore_font

public JGFont highscore_font
Font to use to display highscores


highscore_color

public JGColor highscore_color
Color to use to display highscores


highscore_title_font

public JGFont highscore_title_font
Font to use to display highscore title information


highscore_title_color

public JGColor highscore_title_color
Color to use to display highscore title information


highscore_title

public java.lang.String highscore_title
Title string to display above highscores


highscore_entry

public java.lang.String highscore_entry
String to display above highscore entry screen.

Constructor Detail

StdGame

public StdGame()
Method Detail

setStatusDisplay

public void setStatusDisplay(JGFont status_font,
                             JGColor status_color,
                             java.lang.String lives_img)
Set the status display variables in one go.


setSequences

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)
Set all sequence variables in one go.


getAccelZeroVector

public double[] getAccelZeroVector()

getAccelZeroCorrected

public double[] getAccelZeroCorrected()
get zero vector corrected acceleration vector (slow)


setHighscores

public void setHighscores(int nr_highscores,
                          Highscore default_hisc,
                          int maxnamelen)
Define highscore table.


setHighscoreDisplay

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


parseSizeArgs

public 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. Returns (0.0) if there are no arguments. Prints a usage message otherwise.


initNewGame

public void initNewGame(int level_selected)
Initialise the game when a new game is started. Default sets stage, score to 0, and lives to initial_lives. Level is set to supplied argument.


initNewLife

public void initNewLife()
Initialise play specifically after a new life is introduced (that is, at game start and after the player has died. This is typically used to reinitialise the player. If you want a specific initialisation at both the beginning of the level or after the player death, use startInGame(). Default is do nothing.


defineLevel

public void defineLevel()
Initialise a level. Default is do nothing.


decrementLives

public void decrementLives()
Code for losing a life before transition from LifeLost to InGame is made. Default is decrement lives.


incrementLevel

public void incrementLevel()
Code for incrementing a level before transition from LevelDone to InGame is made. Default is increment level and stage.


startGame

public void startGame()
Start game at level 0


startGame

public void startGame(int level_selected)
Start game at given level


lifeLost

public final void lifeLost()
Call to make state transition to LifeLost. Is ignored when in another state than InGame or {InGame,StartLevel/StartGame}. After the LifeLost sequence, goes to InGame or GameOver, depending on lives left.


levelDone

public final void levelDone()
Call to make state transition to LevelDone. Is ignored when state is not InGame or {Ingame,StartLevel/StartGame}. After the LevelDone sequence, it sets gametime to 0, calls incrementLevel and defineLevel, and goes to StartLevel/StartGame.


gameOver

public final void gameOver()
Call to make straight transition to GameOver; is called automatically by lifeLost when appropriate. Is ignored when game state is not {InGame}, {Ingame,Start*}, or LifeLost. Will go to Title after GameOver sequence.


initAppConfig

public void initAppConfig()
Define appconfig for configuring keys. Override to define your own appconfig; define an empty method to remove the ability of game configuration. Default behaviour is: create appconfig, set the "key_" fields as configuration fields, then load them from a file named $JGAMEHOME/[classname].cfg, and save these in the StdGame object. Create your own AppConfig like this:
 appconfig = new AppConfig("[title]", this, getConfigPath("[filename]");
 
getConfigPath returns a path to a writable file in [user.home]/.jgame/


doFrame

public void doFrame()
The main doFrame takes care of all the standard game actions. If you override it, you should typically call super.doFrame(). doFrame increments timer, increments gametime when in InGame, quits game when key_quitgame is pressed in InGame. In Title, it waits for the user to press the key_startgame, then sets gametime to 0, calls initNewGame, defineLevel, and goes to StartLevel. It also handles the continue_game key inside the sequences, and the gamesettings and quitprogram keys in Title. It also ensures the audioenabled flag is passed to engine.

Specified by:
doFrame in interface JGEngineInterface
Overrides:
doFrame in class JGEngine

doFrameEnterHighscore

public void doFrameEnterHighscore()
Default lets user type name into the variable playername. If enter is pressed, highscore is put in table and saved to disk.


saveHighscores

public boolean saveHighscores()
Try to save highscores to default location, $HOMEDIR/.jgame/$CLASSNAME.hsc. Returns true on success, false on failure.


startTitle

public void startTitle()
Initialise the title screen. This is a standard state transition function. Default is do nothing.


startHighscores

public void startHighscores()
Initialise the highscore display. This is a standard state transition function. Default is do nothing.


startInGame

public void startInGame()
Initialisation at the start of the in-game action. This is a standard state transition function. Note that it is always called after StartLevel and LifeLost, even if startgame_ingame and lifelost_ingame are set. Default is do nothing.


startStartLevel

public void startStartLevel()
Initialise start-level sequence. This is a standard state transition function. Default is do nothing.


startStartGame

public void startStartGame()
Initialise start-game sequence. This is a standard state transition function. Default is do nothing.


startLevelDone

public void startLevelDone()
Initialise next-level sequence. This is a standard state transition function. Default is do nothing.


startLifeLost

public void startLifeLost()
Initialise death sequence. This is a standard state transition function. Default is do nothing.


startGameOver

public void startGameOver()
Initialise game over sequence. This is a standard state transition function. Default is do nothing.


startEnterHighscore

public void startEnterHighscore()
Initialise enter-highscore screen. This is a standard state transition function. Default is clear lastkey and set playername to the empty string.


paintFrame

public void paintFrame()
Default paintFrame displays score at top left, lives at top right. When lives_img is set, it uses that image to display lives.

Specified by:
paintFrame in interface JGEngineInterface
Overrides:
paintFrame in class JGEngine

paintFrameTitle

public void paintFrameTitle()
Default displays class name as title, and "press [key_startgame] to start" below it.


paintFramePaused

public void paintFramePaused()
The game is halted in pause mode, but the paintFrame is still done to refresh the screen. Default behaviour of paintFramePaused() is display "Paused", "Press [key_pausegame] to continue" using title_font, title_color


paintFrameStartLevel

public void paintFrameStartLevel()
Default displays "Level "+(stage+1).


paintFrameStartGame

public void paintFrameStartGame()
Default displays "Start !".


paintFrameLevelDone

public void paintFrameLevelDone()
Default displays "Level Done !".


paintFrameLifeLost

public void paintFrameLifeLost()
Default displays "Life Lost !".


paintFrameGameOver

public void paintFrameGameOver()
Default displays "Game Over!".


paintFrameEnterHighscore

public void paintFrameEnterHighscore()
Default displays highscore_entry, and the player's score and playername currently being entered.


paintFrameHighscores

public void paintFrameHighscores()
Default displays the highscore list. Fields are not yet supported.


checkTime

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


checkTime

public boolean checkTime(int increment)
Returns true every increment ticks.


drawCount

public 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. This is typically used to indicate lives left.


drawWavyString

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)
Draw a string with letters that move up and down individually.


getZoomingFont

public JGFont getZoomingFont(JGFont basejgfont,
                             double tmr,
                             double min_size_fac,
                             double speed)
Get font for zooming text in and out. Note that tmr = 0 will start the font zooming in from the farthest position.


cycleColor

public JGColor cycleColor(JGColor[] cycle,
                          double tmr,
                          double speed)
Get a colour from a colour cycle.


posWalkForwards

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