jgame.platform
Class JGEngine

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
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, JGEngineInterface
Direct Known Subclasses:
StdGame

public abstract class JGEngine
extends java.applet.Applet
implements JGEngineInterface

Contains the main functionality of the game engine. Subclass it to write your own game. The engine can be run as applet, application, or midlet. To run as an application, have your main() construct an instance of your subclass (using a constructor other than the zero-parameter one). Then call initEngine(), with the desired window size, which will open a window, and initialise. To run as an applet or midlet, ensure that your subclass has a parameterless constructor which enables the browser to create it as an applet. Within this constructor, you call initEngineApplet() to initialise. After initialisation, initCanvas() will be called, within which you can call setCanvasSettings and setScalingPreferences. Note that applet parameters will only become available at this point, and not earlier.

Upon initialisation, the engine will create a new thread in which all game action will run. First it calls initGame() in your subclass. Here, you can define any initialisation code, such as variable initialisation and image loading. You can configure the load screen using setProgressBar, setProgressMessage, and setAuthorMessage, and by defining splash_image. The progress bar is set automatically when defineMedia is loading a table. Then, the engine will start producing frames. Each frame it will call doFrame() in your subclass, where you can call engine functions to move the game objects, check collisions, and everything else you want to do in a frame. Then, it will draw the current frame on the screen, after which it calls paintFrame(), where you can do any customised drawing on the frame, such as status messages. The engine enables you to specify states that the game may be in, say, the title screen state or the in-game state. When a state is set, the engine will first try to call start<state>() once at the beginning of the next frame. Then it will try to call additional doFrame<state>() and paintFrame<state>() methods every frame, where you can handle the game action for that specific state. Multple states may be set simultaneously, resulting in multiple method calls for each frame. Due to absence of the reflection framework, MIDlets do not support arbitrary state names, but only the following state names: "StartGame", "LevelDone", "InGame", "Title", "Highscore", "EnterHighscore", "LifeLost", "GameOver", "Paused".

The engine manages a list of sprite objects, and a matrix of equal-sized tiles. Its primary way to draw graphics is images. Images may be loaded from Gifs, JPegs, or PNGs (PNGs not in java 1.2), which may contain either single images, or regularly spaced arrays or matrices of images (i.e. sprite sheets, we will call them image maps). An image is identified by a unique name, and is defined by the image file it comes from, the index within that file in case the file is an image map, and any flip and rotate actions that are to be be done on the file image to arrive at the final image. Animations may be defined in terms of sequences of images. Image maps, images, and animations can be defined by calling resp. defineImageMap, defineImage, or defineAnimation, or the definitions can be loaded from a text-file table file using defineImages().

Objects are of the class JGObject; see this class for more information. Objects are identified within the engine by unique String identifiers. Creating a new object with the same identifier as an old object will replace the old one. Objects are drawn on the screen in lexical order. The main methods for handling objects are moveObjects(), checkCollision(), and checkBGCollision().

Tiles can be used to define a background that the sprite objects can interact with, using a set of shorthands for reading, writing, and colliding with tiles. Tiles are uniquely identified by a short string (1-4 characters). Tiles may be transparent; a decorative background image can be displayed behind the tiles.

Collision is done by assigning collision IDs (cids) to both objects and tiles. A cid is basically a bit string (usually, one allocates 1 bit per basic object or tile type). Collision is done by specifying that a certain set of object types should be notified of collision with a certain set of object or tile types. Such a set is specified by a bit mask, which matches a cid when cid&mask != 0. JGObject defines collision methods (hit and hit_bg) which can then be implemented to handle the collisions. Objects have two bounding boxes: one for object-object collision (the sprite bounding box, or simply bounding box), and one for object-tile collision (the tile bounding box). The two bounding boxes may be dependent on the image (typically, you want these bounding boxes to approximate the shape of each individual image). For this purpose, you can define a collision bounding box with each image definition. This image bounding box is the default bounding box used by the object, but both sprite bbox and tile bbox can be overridden separately. Often, you want to set the tile bbox to a constant value, such as equal to the size of 1 tile.

Scrolling is done by defining a playfield that's larger than the game window, using setPFSize(). The game window (or view) can then be panned across the playfield using setViewOffset(). The game objects always move relative to the playfield. The draw methods take coordinates either relative to the playfield or to the view.

The engine supports arbitrary runtime scaling of the playfield. This means that you can code your game for a specific "virtual" screen size, and have it scale to any other screen size by simply supplying the desired "real" screen size at startup. Applets will scale to the size as given by the width and height fields in the HTML code. Midlets will scale to fit the available canvas. The scale factor will in no way affect the behaviour of the game (except performance-wise). Scaling is done using an anti-aliasing algorithm. Sometimes however, graphics may look a bit blocky or jaggy, because the engine uses a translucency-free scaling algorithm to ensure good performance.

The engine supports keyboard and mouse input. The state of the keyboard is maintained in a keymap, which can be read by getKey. The mouse can be read using getMouseButton and getMouseX/Y. The mouse buttons also have special keycodes. MIDP does not support mouse yet, so the mouse state is always coordinate (0,0) and no mouse buttons pressed.

Sound clips can be loaded using defineAudio or by appropriate entries in a table loaded by defineMedia. playAudio and stopAudio can be used to control clip playing. enableAudio and disableAudio can be used to globally turn audio on and off for the entire application. Sound is not yet implemented in MIDP, so sound calls are ignored.

A game speed variable is used to determine the update speed of velocities and timers. Game speed can be adapted by calling setGameSpeed, or is adapted automatically in video synced frame rate mode (as set by setVideoSyncedUpdate).

Upon initialisation, the engine shows an initialisation screen with a progress bar that reflects progress on the current graphics table being loaded. A splash image can be displayed during the init screen, by defining an image called splash_image. As soon as this image is defined, it is displayed above the progress message. Typically, one defines splash_image at the beginning of the graphics table, so that it displays as soon as possible during the init screen.

JGame applications can be quit by pressing Shift-Esc.

JGame has a number of debug features. It is possible to display the game state and the JGObjects' bounding boxes. There is also the possibility to output debug messages, using dbgPrint. A debug message is associated with a specific source (either a game object or the mainloop). Generated exceptions will generally be treated as debug messages. The messages can be printed on the playfield, next to the objects that output them. See dbgSetMessagesInPf for more information. Debug facilities are not yet implemented in MIDP, so debug calls are ignored.

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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int KeyBackspace
           
static int 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, KeyAlt, KeyCtrl, KeyDown, KeyEnter, KeyEsc, KeyFire, KeyLeft, KeyMouse1, KeyMouse2, KeyMouse3, KeyPound, KeyRight, KeyShift, KeyStar, KeyUp, WAIT_CURSOR
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JGEngine()
          Construct engine, but do not initialise it yet.
 
Method Summary
 void addGameState(java.lang.String state)
          Add the given state to the game's existing state on the next frame.
 boolean and(int value, int mask)
          A Boolean AND shorthand to use for collision; returns (value&mask) != 0.
 void andTileCid(int x, int y, int and_mask)
          Modify the cid of a single tile by ANDing a bit mask, leaving the actual tile.
 double atan2(double y, double x)
          Replacement for Math.atan2 for the sake of MIDP portability.
 void checkBGCollision(int tilecid, int objcid)
          Calls all bg colliders of objects that match objid that collide with tiles that match tileid.
 int checkBGCollision(JGRectangle r)
          Check collision of tiles within given rectangle, return the OR of all cids found.
 void checkCollision(int srccid, int dstcid)
          Calls all colliders of objects that match dstcid that collide with objects that match srccid.
 int checkCollision(int cidmask, JGObject obj)
          Checks collision of objects with given cid mask with given object.
 void clearGameState()
          Set the game's main state to none, on the next frame.
 void clearKey(int key)
          Set the key status of a key to released.
 void clearLastKey()
          Clear the lastkey status.
 void clearMouseButton(int nr)
          Set state of button to released.
 int countObjects(java.lang.String prefix, int cidmask)
          Count how many objects there are with both the given name prefix and have colid&cidmask != 0.
 int countObjects(java.lang.String prefix, int cidmask, boolean suspended_obj)
          Count how many objects there are with both the given name prefix and have colid&cidmask != 0.
 int countTiles(int tilecidmask)
          Count number of tiles with given mask.
 java.lang.String dbgExceptionToString(java.lang.Throwable e)
          Convert the relevant information of an exception to a multiline String.
 void dbgPrint(java.lang.String msg)
          Print a debug message, with the main program being the source.
 void dbgPrint(java.lang.String source, java.lang.String msg)
          Print a debug message from a specific source, which is either the main program or a JGObject.
 void dbgSetDebugColor1(JGColor col)
          Set debug color 1, used for printing debug information.
 void dbgSetDebugColor2(JGColor col)
          Set debug color 2, used for printing debug information.
 void dbgSetMessageExpiry(int ticks)
          Set the number of frames a debug message of a removed object should remain on the playfield.
 void dbgSetMessageFont(JGFont font)
          Set the font for displaying debug messages.
 void dbgShowBoundingBox(boolean enabled)
          Show bounding boxes around the objects: the image bounding box (getBBox) , the tile span (getTiles), and the center tiles (getCenterTiles).
 void dbgShowException(java.lang.String source, java.lang.Throwable e)
          Print the relevant information of an exception as a debug message.
 void dbgShowFullStackTrace(boolean enabled)
          Indicates whether to show full exception stack traces or just the first lines.
 void dbgShowGameState(boolean enabled)
          Show the game state in the bottom right corner of the screen.
 void dbgShowMessagesInPf(boolean enabled)
          Output messages on playfield instead of console.
 void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed)
          Define new animation sequence.
 void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed, boolean pingpong)
          Define new animation sequence.
 void defineAudioClip(java.lang.String clipid, java.lang.String filename)
          Associate given clipid with a filename.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgmap, int mapidx, java.lang.String img_op)
          Define new sprite/tile image from map, with collision bounding box equal to the image's dimensions.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgmap, int mapidx, java.lang.String img_op, int top, int left, int width, int height)
          Define new sprite/tile image from map.
 void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op)
          Define new sprite/tile image from a file, with collision bounding box equal to the image's dimensions.
 void defineImage(java.lang.String name, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op, int top, int left, int width, int height)
          Define new sprite/tile image from a file.
 void defineImageMap(java.lang.String mapname, java.lang.String imgfile, int xofs, int yofs, int tilex, int tiley, int skipx, int skipy)
          Define image map, a large image containing a number of smaller images to use for sprites or fonts.
 void defineMedia(java.lang.String filename)
          Load a set of imagemap, image, animation, and audio clip definitions from a file.
 void destroy()
          Destroy function for deinitialising the engine properly.
 void destroyApp(boolean unconditional)
          Called by the application manager to exit app.
 void disableAudio()
          Disable audio, stop all currently playing audio.
 int displayHeight()
          Get the real display height on this device.
 int displayWidth()
          Get the real display width on this device.
 void doFrame()
          Is called every frame.
 void drawImage(double x, double y, java.lang.String imgname)
          Draw image with given ID.
 void drawImage(double x, double y, java.lang.String imgname, boolean pf_relative)
          Draw image with given ID.
 void drawImage(double x, double y, java.lang.String imgname, JGColor blend_col, double alpha, double rot, double scale, boolean pf_relative)
          Extended version of drawImage for platforms with opengl capabilities.
 void drawImageString(java.lang.String string, double x, double y, int align, java.lang.String imgmap, int char_offset, int spacing)
          Draws a single line of text using an image map as font; text alignment is same as drawString.
 void drawImageString(java.lang.String string, double x, double y, int align, java.lang.String imgmap, int char_offset, int spacing, boolean pf_relative)
          Draws a single line of text using an image map as font; text alignment is same as drawString.
 void drawLine(double x1, double y1, double x2, double y2)
          Draw a line with current thickness and colour.
 void drawLine(double x1, double y1, double x2, double y2, boolean pf_relative)
          Draw a line with current thickness and colour.
 void drawLine(double x1, double y1, double x2, double y2, double thickness, JGColor color)
          DrawLine combined with thickness/colour setting.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered)
          Draw oval with default thickness and colour.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative)
          Draw oval with default thickness and colour.
 void drawOval(double x, double y, double width, double height, boolean filled, boolean centered, double thickness, JGColor color)
          Set thickness/colour and draw oval.
 void drawPolygon(double[] x, double[] y, JGColor[] col, boolean filled, boolean pf_relative)
          Draw convex polygon.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered)
          Draw rectangle in default colour and thickness.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative)
          Draw rectangle in default colour and thickness.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, boolean pf_relative, JGColor[] shadecol)
          Draw shaded rectangle.
 void drawRect(double x, double y, double width, double height, boolean filled, boolean centered, double thickness, JGColor color)
          Set colour/thickness and draw rectangle.
 void drawString(java.lang.String str, double x, double y, int align)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawString(java.lang.String str, double x, double y, int align, boolean pf_relative)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawString(java.lang.String str, double x, double y, int align, JGFont font, JGColor color)
          Draws string so that (x,y) is the topleft coordinate (align=-1), the top middle coordinate (align=0), or the top right coordinate (align=1).
 void drawTile(int xi, int yi, int tileid)
          xi,yi are tile indexes relative to the tileofs, that is, the top left of the bg, + 1.
 void enableAudio()
          Enable audio, restart any audio loops.
 boolean existsObject(java.lang.String index)
          Get object if it exists.
 void exitEngine(java.lang.String msg)
          Exit, optionally reporting an exit message.
 void fillBG(java.lang.String filltile)
          Fill the background with the given tile.
 jgame.impl.Animation getAnimation(java.lang.String id)
          Get animation definition, don't call directly.
 java.awt.Color getAWTColor(JGColor col)
          Convert JGColor to AWT color (JRE only).
 java.awt.Graphics getBufferGraphics()
          get Graphics used to draw on buffer (JRE, non JOGL only).
 java.lang.String getConfigPath(java.lang.String filename)
          Returns path to writable location for a file with the given name.
 double getFontHeight(JGFont jgfont)
          Get height of given font in pixels.
 double getFrameRate()
           
 double getFrameSkip()
           
 double getGameSpeed()
          Get game speed variable.
 JGImage getImage(java.lang.String imgname)
          Gets (scaled) image directly.
 JGRectangle getImageBBox(java.lang.String imgname)
          Gets the collision bounding box of an image.
 JGPoint getImageSize(java.lang.String imgname)
          Gets (non-scaled) image's physical size directly.
 boolean getKey(int key)
          Get the key status of the given key.
 int getKeyCode(java.lang.String keydesc)
          Non-static version for the sake of the interface.
static int getKeyCodeStatic(java.lang.String keydesc)
           
 java.lang.String getKeyDesc(int key)
          Non-static version for the sake of the interface.
static java.lang.String getKeyDescStatic(int key)
           
 int getLastKey()
          Get the keycode of the key that was pressed last, 0=none.
 char getLastKeyChar()
          Get the keycode of the key that was pressed last, 0=none.
 double getMinScaleFactor()
          Get minimum of the x and y scale factors
 boolean getMouseButton(int nr)
          Get state of button.
 boolean getMouseInside()
          Check if mouse is inside game window
 JGPoint getMousePos()
          Get current mouse position in logical coordinates, inverse projected through last set view zoom/rotate setting.
 int getMouseX()
          Get current mouse X position
 int getMouseY()
          Get current mouse Y position
 JGObject getObject(java.lang.String index)
          Get object if it exists, null if not.
 java.util.Vector getObjects(java.lang.String prefix, int cidmask, boolean suspended_obj, JGRectangle bbox)
          Query the object list for objects matching the given name prefix, CID mask, and collide with the given bounding box.
 int getOffscreenMarginX()
          Get offscreen X margin.
 int getOffscreenMarginY()
          Get offscreen Y margin.
 int getTileCid(int xidx, int yidx)
          Get collision id of tile at given tile index position.
 int getTileCid(JGPoint center, int xofs, int yofs)
          Get the tile cid of the point that is (xofs,yofs) from the tile index coordinate center.
 int getTileCid(JGRectangle tiler)
          Get the OR of the cids at the tile indexes given by tiler
 int getTileCidAtCoord(double x, double y)
          Get collision id of the tile at given pixel coordinates.
 JGPoint getTileCoord(int tilex, int tiley)
          Get pixel coordinate corresponding to the top left of the tile at the given index
 JGPoint getTileCoord(JGPoint tileidx)
          Get pixel coordinate corresponding to the top left of the tile at the given index
 JGPoint getTileIndex(double x, double y)
          Get tile index of the tile the coordinate is on.
 JGRectangle getTiles(JGRectangle r)
          Get tile index range of all tiles overlapping given rectangle of pixel coordinates.
 boolean getTiles(JGRectangle dest, JGRectangle r)
          Get tile index range of all tiles overlapping given rectangle of pixel coordinates, version without object creation.
 java.lang.String getTileStr(int xidx, int yidx)
          get string id of tile at given index position.
 java.lang.String getTileStr(JGPoint center, int xofs, int yofs)
          Get the tile string of the point that is (xofs,yofs) from the tile index coordinate center.
 java.lang.String getTileStrAtCoord(double x, double y)
          Get string id of the tile at given pixel coordinates.
 boolean getVideoSyncedUpdate()
           
 double getXAlignOfs(double x)
          Returns the difference between position and the closest tile-aligned position.
 double getXDist(double x1, double x2)
          Calculates length of the shortest path between x1 and x2, with x1, x2 being playfield coordinates, taking into account the wrap setting.
 double getXScaleFactor()
          Get scale factor of real screen width wrt virtual screen width
 double getYAlignOfs(double y)
          Returns the difference between position and the closest tile-aligned position.
 double getYDist(double y1, double y2)
          Calculates length of the shortest path between y1 and y2, with y1, y2 being playfield coordinates, taking into account the wrap setting.
 double getYScaleFactor()
          Get scale factor of real screen height wrt virtual screen height
 boolean inGameState(java.lang.String state)
          Check if game is in given state.
 boolean inGameStateNextFrame(java.lang.String state)
          Check if game will be in given state the next frame.
 void init()
          Initialise engine; don't call directly.
abstract  void initCanvas()
          Override to define your own initialisations before the engine initialises.
 void initEngine(int width, int height)
          Init engine as application.
 void initEngineApplet()
          Init engine as applet; call this in your engine constructor.
abstract  void initGame()
          Override to define your own initialisations after the engine initialised.
 boolean isApplet()
          Are we running as an applet or as an application?
 boolean isMidlet()
          Are we running as a midlet?
 boolean isOpenGL()
          Are we running with an OpenGL backend?
 boolean isRunning()
          True if engine is running, false if paused.
 boolean isXAligned(double x, double margin)
          Returns true if x falls within margin of the tile snap grid.
 boolean isYAligned(double y, double margin)
          Returns true if y falls within margin of the tile snap grid.
 java.lang.String lastPlayedAudio(java.lang.String channel)
          Returns the audioclip that was last played, null if audio was stopped with stopAudio.
 void markAddObject(JGObject obj)
          Add new object, will become active next frame, do not call directly.
 double moduloXPos(double x)
          A modulo that moduloes symmetrically, relative to the middle of the view.
 double moduloYPos(double y)
          A modulo that moduloes symmetrically, relative to the middle of the view.
 void moveObjects()
          Call the move() methods of all registered objects.
 void moveObjects(java.lang.String prefix, int cidmask)
          Call the move() methods of those objects matching the given name prefix and collision id mask.
 void orTileCid(int x, int y, int or_mask)
          Modify the cid of a single tile by ORing a bit mask, leaving the actual tile.
 void paintFrame()
          Is called when the engine's default screen painting is finished, and custom painting actions may be carried out.
 void pauseApp()
          Called by the application manager to pause app.
 int pfHeight()
          Get the virtual height in pixels (not the scaled screen height)
 int pfTilesX()
          Get the number of tiles in X direction
 int pfTilesY()
          Get the number of tiles in Y direction
 int pfWidth()
          Get the virtual width in pixels (not the scaled screen width)
 boolean pfWrapX()
          Is playfield X wrap enabled?
 boolean pfWrapY()
          Is playfield Y wrap enabled?
 void playAudio(java.lang.String clipid)
          Play audio clip on unnamed channel, which means it will not replace another clip, and cannot be stopped.
 void playAudio(java.lang.String channel, java.lang.String clipid, boolean loop)
          Play clip on channel with given name.
 double random(double min, double max)
          A floating-point random number between min and max
 double random(double min, double max, double interval)
          Generates discrete random number between min and max inclusive, with steps of interval.
 int random(int min, int max, int interval)
          Generates discrete random number between min and max inclusive, with steps of interval, integer version.
 void registerTimer(JGTimer timer)
          Register a timer with the engine, don't call directly.
 void removeAllTimers()
          Remove all JGTimers still ticking in the system.
 void removeGameState(java.lang.String state)
          Remove the given state from the game's existing state on the next frame.
 void removeObject(JGObject obj)
          Remove one particular object.
 void removeObjects(java.lang.String prefix, int cidmask)
          Remove all objects which have the given name prefix and/or match the given cidmask.
 void removeObjects(java.lang.String prefix, int cidmask, boolean suspended_obj)
          Remove all objects which have the given name prefix and/or match the given cidmask.
 void requestGameFocus()
          Call this to get focus.
 void setAuthorMessage(java.lang.String msg)
          Set author message, default "JGame [version]"
 void setBGColor(JGColor bgcolor)
          Set global background colour, which is displayed in borders, and behind transparent tiles if no BGImage is defined.
 void setBGImage(int depth, java.lang.String bgimg, boolean wrapx, boolean wrapy)
          Set image to display at a particular parallax scroll level.
 void setBGImage(java.lang.String bgimg)
          Set image to display behind transparent tiles.
 void setBGImgOffset(int depth, double xofs, double yofs, boolean centered)
          Change (absolute) offset of BG image independently of view offset.
 void setBlendMode(int src_func, int dst_func)
          Set blend mode, for platforms that support blending.
 void setCanvasSettings(int nrtilesx, int nrtilesy, int tilex, int tiley, JGColor fgcolor, JGColor bgcolor, JGFont msgfont)
          Set canvas dimensions and message colours/fonts.
 void setColor(JGColor col)
          Set current drawing colour.
 void setColorsFont(JGColor fgcolor, JGColor bgcolor, JGFont msgfont)
          Set foreground and background colour, and message font in one go; passing a null means ignore that argument.
 void setFGColor(JGColor fgcolor)
          Set global foreground colour, used for printing text and status messages.
 void setFont(java.awt.Graphics g, JGFont jgfont)
           
 void setFont(JGFont font)
          Set current font, scale the font to screen size.
 void setFrameRate(double fps, double maxframeskip)
          Set frame rate in frames per second, and maximum number of frames that may be skipped before displaying a frame again.
 void setGameSpeed(double gamespeed)
          Set game speed variable, default is 1.0.
 void setGameState(java.lang.String state)
          Set the game's main state on the next frame.
 void setKey(int key)
          Set the key status of a key to pressed.
 void setMouseButton(int nr)
          Set state of button to pressed.
 void setMouseCursor(int cursor)
          Set mouse cursor to a platform-independent standard cursor.
 void setMouseCursor(java.lang.Object cursor)
          Set mouse cursor, null means hide cursor.
 void setMsgFont(JGFont msgfont)
          Set the (unscaled) message font, used for displaying status messages.
 void setOffscreenMargin(int xmargin, int ymargin)
          Set margin used for testing if object should expire or suspend when off-view or off-playfield.
 void setPFSize(int nrtilesx, int nrtilesy)
          Set the playfield size to be any size larger or equal to the view size.
 void setPFWrap(boolean wrapx, boolean wrapy, int shiftx, int shifty)
          Set playfield wraparound setting.
 void setProgressBar(double pos)
          Set progress bar position in the load screen.
 void setProgressMessage(java.lang.String msg)
          Set progress message, default "Loading files..."
 void setRenderSettings(int alpha_thresh, JGColor render_bg_col)
          Configure image rendering.
 void setScalingPreferences(double min_aspect_ratio, double max_aspect_ratio, int crop_top, int crop_left, int crop_bottom, int crop_right)
          Set scaling preferences for translating the virtual playfield to the actual display.
 void setSmoothing(boolean smooth_magnify)
          Magnification can be set to smooth or blocky.
 void setStroke(double thickness)
          Set the line thickness
 void setTextOutline(int thickness, JGColor colour)
          Set parameters of outline surrounding text (for example, used to increase contrast).
 void setTile(int x, int y, java.lang.String tilestr)
          Set a single tile.
 void setTile(JGPoint tileidx, java.lang.String tilename)
          Set a single tile.
 void setTileCid(int x, int y, int value)
          Set the cid of a single tile to the given value, leaving the actual tile.
 void setTileCid(int x, int y, int and_mask, int or_mask)
          Set the cid of a single tile using and and or mask.
 void setTiles(int xofs, int yofs, java.lang.String[] tilemap)
          Set a block of tiles according to the single-letter tile names in the nxm character array tilemap.
 void setTileSettings(java.lang.String out_of_bounds_tile, int out_of_bounds_cid, int preserve_cids)
          Define background tile settings.
 void setTilesMulti(int xofs, int yofs, java.lang.String[] tilemap)
          Set a block of tiles according to the tile names in the nxm element array tilemap.
 void setVideoSyncedUpdate(boolean value)
          Enable/disable video synced update (jogl only).
 void setViewOffset(int xofs, int yofs, boolean centered)
          Change offset of playfield view.
 void setViewZoomRotate(double zoom, double rotate)
          Zoom/rotate view.
 void snapToGrid(JGPoint p, int gridsnapx, int gridsnapy)
          Snap p to grid in case p is close enough to the grid lines.
 double snapToGridX(double x, double gridsnapx)
          Snap to grid, double version.
 double snapToGridY(double y, double gridsnapy)
          Snap to grid, double version.
 void start()
          Signal that the engine should start running.
 void startApp()
          Called when midlet is first initialised, or unpaused.
 void stop()
          signal that the engine should stop running and wait.
 void stopAudio()
          Stop all audio channels.
 void stopAudio(java.lang.String channel)
          Stop one audio channel.
 int tileHeight()
          Get the tile height in (virtual) pixels.
 int tileWidth()
          Get the tile width in (virtual) pixels.
 int viewHeight()
          Get the virtual height in pixels (not the scaled screen height)
 int viewTilesX()
          Get the number of tiles of view window in X direction
 int viewTilesY()
          Get the number of tiles of view window in Y direction
 int viewWidth()
          Get the virtual width in pixels (not the scaled screen width)
 int viewXOfs()
          Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.
 int viewYOfs()
          Get view offset as it will be at the next frame draw, in case we are not inside a frame draw, or the view offset as it is, when we are.
 void wakeUpOnKey(int key)
          Make engine call start() when a key is pressed.
 
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, transferFocusBackward, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KeyBackspace

public static final int KeyBackspace
See Also:
Constant Field Values

KeyTab

public static final int KeyTab
See Also:
Constant Field Values
Constructor Detail

JGEngine

public JGEngine()
Construct engine, but do not initialise it yet. Call initEngine or initEngineApplet to initialise the engine.

Method Detail

getImage

public JGImage getImage(java.lang.String imgname)
Description copied from interface: JGEngineInterface
Gets (scaled) image directly. Is usually not necessary. Returns null if image is a null image; throws error if image is not defined.

Specified by:
getImage in interface JGEngineInterface

getImageSize

public JGPoint getImageSize(java.lang.String imgname)
Description copied from interface: JGEngineInterface
Gets (non-scaled) image's physical size directly. The object returned may be a reference to an internal variable, do not change it!

Specified by:
getImageSize in interface JGEngineInterface

defineImage

public void defineImage(java.lang.String name,
                        java.lang.String tilename,
                        int collisionid,
                        java.lang.String imgfile,
                        java.lang.String img_op,
                        int top,
                        int left,
                        int width,
                        int height)
Description copied from interface: JGEngineInterface
Define new sprite/tile image from a file. If an image with this id is already defined, it is removed from any caches, so that the old image is really unloaded. This can be used to load large (background) images on demand, rather than have them all in memory. Note that the unloading does not work for images defined from image maps.

Specified by:
defineImage in interface JGEngineInterface
Parameters:
name - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgfile - filespec in resource path; "null" means no file
top - collision bounding box dimensions
left - collision bounding box dimensions
width - collision bounding box dimensions
height - collision bounding box dimensions

defineImage

public void defineImage(java.lang.String imgname,
                        java.lang.String tilename,
                        int collisionid,
                        java.lang.String imgfile,
                        java.lang.String img_op)
Description copied from interface: JGEngineInterface
Define new sprite/tile image from a file, with collision bounding box equal to the image's dimensions. If an image with this id is already defined, it is removed from any caches, so that the old image is really unloaded. This can be used to load large (background) images on demand, rather than have them all in memory. Note that the unloading does not work for images defined from image maps.

Specified by:
defineImage in interface JGEngineInterface
Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgfile - filespec in resource path; "null" means no file

defineImage

public void defineImage(java.lang.String imgname,
                        java.lang.String tilename,
                        int collisionid,
                        java.lang.String imgmap,
                        int mapidx,
                        java.lang.String img_op,
                        int top,
                        int left,
                        int width,
                        int height)
Description copied from interface: JGEngineInterface
Define new sprite/tile image from map.

Specified by:
defineImage in interface JGEngineInterface
Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for