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, and GIFs are not always supported in MIDP, not even on new phones), 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. In MIDP, touch screens will generate mouse events. Button 1 is pressed when the user touches the screen. The mouse coordinates change only when the user touches or swipes the screen.

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. In MIDP, sound always has only one channel, so the channel parameter is ignored. Due to limitations in typical MIDP implementations, playing a new sound while a sound is already playing will not trigger the new sound, but the old sound will keep playing.

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

User statistics, game progress, and basic save game information can be stored using the store...() API. It enables persistent storage of numbers and Strings. It works with both MIDP and JRE, but JRE applets will need to be signed because persistent storage requires access to the local file system.

The opts... methods provide a standard options menu API. When an option is defined, a standard option menu item is created which is directly linked to a persistent storage variable. Currently implemented on Android only.

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 most debug calls are ignored, except dbgPrint and dbgShowException, which print to stdout.

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
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, 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
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 defineImageRotated(java.lang.String name, java.lang.String tilename, int collisionid, java.lang.String srcname, double angle)
          Define new image by rotating an already loaded image.
 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 OpenGL or Android.
 void drawImage(java.lang.String imgname, double x, double y)
          Draw image with given ID, new version.
 void drawImage(java.lang.String imgname, double x, double y, boolean pf_relative)
          Draw image with given ID, new version.
 void drawImage(java.lang.String imgname, double x, double y, boolean pf_relative, JGColor blend_col, double alpha, double rot, double scale)
          Extended version of drawImage for OpenGL or Android, new version.
 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, int len, 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, boolean pf_relative, JGColor[] shadecol, java.lang.String tileimage)
          Draw shaded or patterned 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.
 double[] getAccelVec()
          get double[3] vector representing acceleration
 double getAccelX()
          get accelerometer vector X coordinate
 double getAccelY()
          get accelerometer vector Y coordinate
 double getAccelZ()
          get accelerometer vector Z coordinate (positive = towards user)
 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 hasAccelerometer()
          returns true if device has accelerometer (currently only android)
 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.
 void initEngineComponent(int width, int height)
          Init engine as component to be embedded in a frame or panel; call this in your engine constructor.
abstract  void initGame()
          Override to define your own initialisations after the engine initialised.
 int invokeUrl(java.lang.String url, java.lang.String target)
          Execute or go to URL (action depends on file type).
 boolean isAndroid()
          Are we running on Android?
 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 optsAddBoolean(java.lang.String varname, java.lang.String title, java.lang.String desc, boolean initial)
          Adds boolean that can be configured with a checkbox.
 void optsAddEnum(java.lang.String varname, java.lang.String title, java.lang.String desc, java.lang.String[] values, int initial)
          Adds enum that can be configured with radio buttons.
 void optsAddKey(java.lang.String varname, java.lang.String title, java.lang.String desc, int initial)
          Adds "key" option that can be configured by selecting a key or button on the device.
 void optsAddNumber(java.lang.String varname, java.lang.String title, java.lang.String desc, int decimals, double lower, double upper, double step, double initial)
          adds (int or float) number that can be configured with a slider.
 void optsAddString(java.lang.String varname, java.lang.String title, java.lang.String desc, int maxlen, boolean isPassword, java.lang.String initial)
          Adds String that can be configured by typing text.
 void optsAddTitle(java.lang.String title)
          Adds title to be displayed above subsequent items.
 void optsClear()
          Clear all previous option definitions.
 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.
 boolean storeExists(java.lang.String id)
          Checks if item exists in store
 double storeReadDouble(java.lang.String id, double undef)
          Reads double from store, use undef if ID not found
 int storeReadInt(java.lang.String id, int undef)
          Reads int from store, use undef if ID not found
 java.lang.String storeReadString(java.lang.String id, java.lang.String undef)
          Reads String from store, use undef if ID not found
 void storeRemove(java.lang.String id)
          Remove record if it exists
 void storeWriteDouble(java.lang.String id, double value)
          Writes double to store under given ID
 void storeWriteInt(java.lang.String id, int value)
          Writes integer to store under given ID
 void storeWriteString(java.lang.String id, java.lang.String value)
          Writes string to store under given ID
 int tileHeight()
          Get the tile height in (virtual) pixels.
 java.lang.String tileIDToStr(int tileid)
          Convert tile ID code to tile name (as used internally).
 int tileStrToID(java.lang.String tilestr)
          Convert tile name to integer ID code (as used internally).
 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, 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

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, initEngineApplet, or initEngineComponent 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. Defining an image with the same name and filename twice does not cause the image to be reloaded, but keeps the old image.

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. Defining an image with the same name and filename twice does not cause the image to be reloaded, but keeps the old image.

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 tile collision matching
imgmap - id of image map
mapidx - index of image in map, 0=first
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 imgmap,
                        int mapidx,
                        java.lang.String img_op)
Description copied from interface: JGEngineInterface
Define new sprite/tile image from map, with collision bounding box equal to the image's dimensions.

Specified by:
defineImage in interface JGEngineInterface
Parameters:
imgname - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
imgmap - id of image map
mapidx - index of image in map, 0=first

defineImageRotated

public void defineImageRotated(java.lang.String name,
                               java.lang.String tilename,
                               int collisionid,
                               java.lang.String srcname,
                               double angle)
Description copied from interface: JGEngineInterface
Define new image by rotating an already loaded image. This method does not yet work for images defined from image maps! The destination image is always a square which is large enough to fit the source image at any angle. Its dimension is calculated as: max(width, height, 0.75*(width+height)). The source image is rendered to its center.

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:
defineImageRotated in interface JGEngineInterface
Parameters:
name - image id
tilename - tile id (1-4 characters)
collisionid - cid to use for tile collision matching
srcname - image id of (already loaded) source image
angle - the angle in radians by which to rotate

defineImageMap

public void defineImageMap(java.lang.String mapname,
                           java.lang.String imgfile,
                           int xofs,
                           int yofs,
                           int tilex,
                           int tiley,
                           int skipx,
                           int skipy)
Description copied from interface: JGEngineInterface
Define image map, a large image containing a number of smaller images to use for sprites or fonts. The images must be in a regularly spaced matrix. One may define multiple image maps with the same image but different matrix specs.

Specified by:
defineImageMap in interface JGEngineInterface
Parameters:
mapname - id of image map
imgfile - filespec in resource path
xofs - x offset of first image
yofs - y offset of first image
tilex - width of an image
tiley - height of an image
skipx - nr of pixels to skip between successive images
skipy - nr of pixels to skip between successive images vertically.

getImageBBox

public JGRectangle getImageBBox(java.lang.String imgname)
Description copied from interface: JGEngineInterface
Gets the collision bounding box of an image.

Specified by:
getImageBBox in interface JGEngineInterface

defineMedia

public void defineMedia(java.lang.String filename)
Description copied from interface: JGEngineInterface
Load a set of imagemap, image, animation, and audio clip definitions from a file. The file contains one image / imagemap / animation definition / audio clip on each line, with the fields separated by one or more tabs. Lines not matching the required number of fields are ignored. The fields have the same order as in defineImage, defineImageMap, defineAnimation, and defineAudioClip. For example:

defineImage("mytile", "#", 1,"gfx/myimage.gif", "-");

is equivalent to the following line in the table:

mytile     #     1     gfx/myimage.gif     -

with the whitespace between the fields consisting of one or more tabs. The defineAnimation methods take an array of names as the second argument. This is represented in table format as the names separated by semicolon ';' characters. So:

defineAnimation("anim",new String[]{"frame0","frame1",...},0.5);

is equivalent to:

anim     frame0;frame1;...     0.5

Specified by:
defineMedia in interface JGEngineInterface

markAddObject

public void markAddObject(JGObject obj)
Description copied from interface: JGEngineInterface
Add new object, will become active next frame, do not call directly. This method is normally called automatically by the JGObject constructor. You should not need to call this directly.

Specified by:
markAddObject in interface JGEngineInterface

existsObject

public boolean existsObject(java.lang.String index)
Description copied from interface: JGEngineInterface
Get object if it exists.

Specified by:
existsObject in interface JGEngineInterface

getObject

public JGObject getObject(java.lang.String index)
Description copied from interface: JGEngineInterface
Get object if it exists, null if not.

Specified by:
getObject in interface JGEngineInterface

moveObjects

public void moveObjects(java.lang.String prefix,
                        int cidmask)
Description copied from interface: JGEngineInterface
Call the move() methods of those objects matching the given name prefix and collision id mask.

Specified by:
moveObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore

moveObjects

public void moveObjects()
Description copied from interface: JGEngineInterface
Call the move() methods of all registered objects.

Specified by:
moveObjects in interface JGEngineInterface

checkCollision

public void checkCollision(int srccid,
                           int dstcid)
Description copied from interface: JGEngineInterface
Calls all colliders of objects that match dstcid that collide with objects that match srccid.

Specified by:
checkCollision in interface JGEngineInterface

checkCollision

public int checkCollision(int cidmask,
                          JGObject obj)
Description copied from interface: JGEngineInterface
Checks collision of objects with given cid mask with given object. Suspended objects are not counted (same as checkCollision(int,int)). This method should be a more efficient way to check for object overlap than getObjects, though it's still not very efficient.

Specified by:
checkCollision in interface JGEngineInterface
Parameters:
cidmask - cid mask of objects to consider, 0 means any
Returns:
the OR of the CIDs of all object overlapping r

checkBGCollision

public int checkBGCollision(JGRectangle r)
Description copied from interface: JGEngineInterface
Check collision of tiles within given rectangle, return the OR of all cids found.

Specified by:
checkBGCollision in interface JGEngineInterface
Parameters:
r - bounding box in pixel coordinates

checkBGCollision

public void checkBGCollision(int tilecid,
                             int objcid)
Description copied from interface: JGEngineInterface
Calls all bg colliders of objects that match objid that collide with tiles that match tileid.

Specified by:
checkBGCollision in interface JGEngineInterface

getObjects

public java.util.Vector getObjects(java.lang.String prefix,
                                   int cidmask,
                                   boolean suspended_obj,
                                   JGRectangle bbox)
Description copied from interface: JGEngineInterface
Query the object list for objects matching the given name prefix, CID mask, and collide with the given bounding box. If suspended_obj is true, suspended objects are also included. The list of objects returned match all the supplied criteria. This is an inefficient method, use sparingly.

Specified by:
getObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore
suspended_obj - also count suspended objects
bbox - collision bounding box, null means ignore

removeObject

public void removeObject(JGObject obj)
Description copied from interface: JGEngineInterface
Remove one particular object. The actual removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop.

Specified by:
removeObject in interface JGEngineInterface

removeObjects

public void removeObjects(java.lang.String prefix,
                          int cidmask)
Description copied from interface: JGEngineInterface
Remove all objects which have the given name prefix and/or match the given cidmask. It also removes suspended objects. The actual matching and removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop. It also removes any matching objects which are pending to be added the next frame.

Specified by:
removeObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore

removeObjects

public void removeObjects(java.lang.String prefix,
                          int cidmask,
                          boolean suspended_obj)
Description copied from interface: JGEngineInterface
Remove all objects which have the given name prefix and/or match the given cidmask. You can specify whether to remove suspended objects or not. The actual matching and removal is done after the current moveObjects or check*Collision ends, or immediately if done from within the main doFrame loop. It also removes any matching objects which are pending to be added the next frame.

Specified by:
removeObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore
suspended_obj - also count suspended objects

countObjects

public int countObjects(java.lang.String prefix,
                        int cidmask)
Description copied from interface: JGEngineInterface
Count how many objects there are with both the given name prefix and have colid&cidmask != 0. Either criterion can be left out. It also counts suspended objects. Actually searches the object array, so it may be inefficient to use it a lot of times.

Specified by:
countObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore

countObjects

public int countObjects(java.lang.String prefix,
                        int cidmask,
                        boolean suspended_obj)
Description copied from interface: JGEngineInterface
Count how many objects there are with both the given name prefix and have colid&cidmask != 0. Either criterion can be left out. You can specify whether to count suspended objects or not. Actually searches the object array, so it may be inefficient to use it a lot of times.

Specified by:
countObjects in interface JGEngineInterface
Parameters:
prefix - ID prefix, null means ignore
cidmask - collision id mask, 0 means ignore
suspended_obj - also count suspended objects

setBGImage

public void setBGImage(java.lang.String bgimg)
Description copied from interface: JGEngineInterface
Set image to display behind transparent tiles. Image size must be a multiple of the tile size. Passing null turns off background image; the background colour will be used instead.

Specified by:
setBGImage in interface JGEngineInterface
Parameters:
bgimg - image name, null=turn off background image

setBGImage

public void setBGImage(int depth,
                       java.lang.String bgimg,
                       boolean wrapx,
                       boolean wrapy)
Description copied from interface: JGEngineInterface
Set image to display at a particular parallax scroll level. Only some platforms support parallax scrolling. On other platforms, only the level 0 image is displayed, with its offset equal to the view offset. Level 0 corresponds to the top level; setBGImage(String) is equivalent to setBGImage(String,0,true,true). The level 0 image follows the view offset by default, higher levels are initialised to offset (0,0) by default.

Specified by:
setBGImage in interface JGEngineInterface
Parameters:
depth - depth level, 0=topmost
bgimg - image name, null=turn off image at this level
wrapx - image should wrap in x direction
wrapy - image should wrap in y direction

setTileSettings

public void setTileSettings(java.lang.String out_of_bounds_tile,
                            int out_of_bounds_cid,
                            int preserve_cids)
Description copied from interface: JGEngineInterface
Define background tile settings. Default is setBGCidSettings("",0,0).

Specified by:
setTileSettings in interface JGEngineInterface
Parameters:
out_of_bounds_tile - tile string to use outside of screen bounds
out_of_bounds_cid - cid to use outside of screen boundaries
preserve_cids - cid mask to preserve when setting tiles

fillBG

public void fillBG(java.lang.String filltile)
Description copied from interface: JGEngineInterface
Fill the background with the given tile.

Specified by:
fillBG in interface JGEngineInterface
Parameters:
filltile - null means use background colour

setTileCid

public void setTileCid(int x,
                       int y,
                       int and_mask,
                       int or_mask)
Description copied from interface: JGEngineInterface
Set the cid of a single tile using and and or mask.

Specified by:
setTileCid in interface JGEngineInterface

setTile

public void setTile(int x,
                    int y,
                    java.lang.String tilestr)
Description copied from interface: JGEngineInterface
Set a single tile.

Specified by:
setTile in interface JGEngineInterface

drawTile

public 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. They must be within both the tilemap and the view.

Specified by:
drawTile in interface JGEngineInterface

countTiles

public int countTiles(int tilecidmask)
Description copied from interface: JGEngineInterface
Count number of tiles with given mask. Actually searches all tiles, so it's inefficient and should be used sparingly (such as, determine the number of something at the beginning of a game).

Specified by:
countTiles in interface JGEngineInterface

getTileCid

public int getTileCid(int xidx,
                      int yidx)
Description copied from interface: JGEngineInterface
Get collision id of tile at given tile index position. Moduloes the given position if wraparound

Specified by:
getTileCid in interface JGEngineInterface

getTileStr

public java.lang.String getTileStr(int xidx,
                                   int yidx)
Description copied from interface: JGEngineInterface
get string id of tile at given index position. Moduloes the given position if wraparound

Specified by:
getTileStr in interface JGEngineInterface

getTileCid

public int getTileCid(JGRectangle tiler)
Description copied from interface: JGEngineInterface
Get the OR of the cids at the tile indexes given by tiler

Specified by:
getTileCid in interface JGEngineInterface

getTiles

public JGRectangle getTiles(JGRectangle r)
Description copied from interface: JGEngineInterface
Get tile index range of all tiles overlapping given rectangle of pixel coordinates. Get tile position range of all tiles overlapping given rectangle. Returns null is rectangle is null.

Specified by:
getTiles in interface JGEngineInterface
Parameters:
r - rectangle in pixel coordinates, null is none
Returns:
tile indices

getTiles

public boolean getTiles(JGRectangle dest,
                        JGRectangle r)
Description copied from interface: JGEngineInterface
Get tile index range of all tiles overlapping given rectangle of pixel coordinates, version without object creation. Get tile position range of all tiles overlapping given rectangle. Returns false is rectangle is null.

Specified by:
getTiles in interface JGEngineInterface
Parameters:
dest - rectangle to copy tile range into
r - rectangle in pixel coordinates, null is none
Returns:
true if rectangle exists, false if null

setTileCid

public void setTileCid(int x,
                       int y,
                       int value)
Description copied from interface: JGEngineInterface
Set the cid of a single tile to the given value, leaving the actual tile.

Specified by:
setTileCid in interface JGEngineInterface

orTileCid

public void orTileCid(int x,
                      int y,
                      int or_mask)
Description copied from interface: JGEngineInterface
Modify the cid of a single tile by ORing a bit mask, leaving the actual tile.

Specified by:
orTileCid in interface JGEngineInterface

andTileCid

public void andTileCid(int x,
                       int y,
                       int and_mask)
Description copied from interface: JGEngineInterface
Modify the cid of a single tile by ANDing a bit mask, leaving the actual tile.

Specified by:
andTileCid in interface JGEngineInterface

setTile

public void setTile(JGPoint tileidx,
                    java.lang.String tilename)
Description copied from interface: JGEngineInterface
Set a single tile.

Specified by:
setTile in interface JGEngineInterface

setTiles

public void setTiles(int xofs,
                     int yofs,
                     java.lang.String[] tilemap)
Description copied from interface: JGEngineInterface
Set a block of tiles according to the single-letter tile names in the nxm character array tilemap.

Specified by:
setTiles in interface JGEngineInterface

setTilesMulti

public void setTilesMulti(int xofs,
                          int yofs,
                          java.lang.String[] tilemap)
Description copied from interface: JGEngineInterface
Set a block of tiles according to the tile names in the nxm element array tilemap. The tile names may be multiple characters. Each String in the tilemap consists of a list of tile names separated by spaces. So: "x aa ab abc" stands for a sequence of four tiles, "x", "aa", "ab", and "abc".

Specified by:
setTilesMulti in interface JGEngineInterface

getTileCidAtCoord

public int getTileCidAtCoord(double x,
                             double y)
Description copied from interface: JGEngineInterface
Get collision id of the tile at given pixel coordinates.

Specified by:
getTileCidAtCoord in interface JGEngineInterface

getTileCid

public int getTileCid(JGPoint center,
                      int xofs,
                      int yofs)
Description copied from interface: JGEngineInterface
Get the tile cid of the point that is (xofs,yofs) from the tile index coordinate center.

Specified by:
getTileCid in interface JGEngineInterface

getTileStrAtCoord

public java.lang.String getTileStrAtCoord(double x,
                                          double y)
Description copied from interface: JGEngineInterface
Get string id of the tile at given pixel coordinates.

Specified by:
getTileStrAtCoord in interface JGEngineInterface

getTileStr

public java.lang.String getTileStr(JGPoint center,
                                   int xofs,
                                   int yofs)
Description copied from interface: JGEngineInterface
Get the tile string of the point that is (xofs,yofs) from the tile index coordinate center.

Specified by:
getTileStr in interface JGEngineInterface

tileStrToID

public int tileStrToID(java.lang.String tilestr)
Description copied from interface: JGEngineInterface
Convert tile name to integer ID code (as used internally). The ID code basically encodes the four characters of the string into the bytes of the four-byte integer. The ID code is NOT related to the collision ID (CID).

Specified by:
tileStrToID in interface JGEngineInterface
Parameters:
tilestr - tilename, null or empty string -> ID = 0

tileIDToStr

public java.lang.String tileIDToStr(int tileid)
Description copied from interface: JGEngineInterface
Convert tile ID code to tile name (as used internally). The ID code basically encodes the four characters of the string into the bytes of the four-byte integer. The ID code is NOT related to the collision ID (CID).

Specified by:
tileIDToStr in interface JGEngineInterface
Parameters:
tileid - tile ID, tileid==0 -> tilename = empty string

moduloXPos

public double moduloXPos(double x)
Description copied from interface: JGEngineInterface
A modulo that moduloes symmetrically, relative to the middle of the view. That is, the returned x/ypos falls within -pfwidth/height_half and pfwidth/height_half of x/yofs_mid

Specified by:
moduloXPos in interface JGEngineInterface

moduloYPos

public double moduloYPos(double y)
Description copied from interface: JGEngineInterface
A modulo that moduloes symmetrically, relative to the middle of the view. That is, the returned x/ypos falls within -pfwidth/height_half and pfwidth/height_half of x/yofs_mid

Specified by:
moduloYPos in interface JGEngineInterface

setProgressBar

public void setProgressBar(double pos)
Description copied from interface: JGEngineInterface
Set progress bar position in the load screen.

Specified by:
setProgressBar in interface JGEngineInterface
Parameters:
pos - a number between 0 and 1

setProgressMessage

public void setProgressMessage(java.lang.String msg)
Description copied from interface: JGEngineInterface
Set progress message, default "Loading files..."

Specified by:
setProgressMessage in interface JGEngineInterface

setAuthorMessage

public void setAuthorMessage(java.lang.String msg)
Description copied from interface: JGEngineInterface
Set author message, default "JGame [version]"

Specified by:
setAuthorMessage in interface JGEngineInterface

dbgShowBoundingBox

public void dbgShowBoundingBox(boolean enabled)
Description copied from interface: JGEngineInterface
Show bounding boxes around the objects: the image bounding box (getBBox) , the tile span (getTiles), and the center tiles (getCenterTiles).

Specified by:
dbgShowBoundingBox in interface JGEngineInterface

dbgShowGameState

public void dbgShowGameState(boolean enabled)
Description copied from interface: JGEngineInterface
Show the game state in the bottom right corner of the screen. The message font and foreground colour are used to draw the text.

Specified by:
dbgShowGameState in interface JGEngineInterface

dbgShowFullStackTrace

public void dbgShowFullStackTrace(boolean enabled)
Description copied from interface: JGEngineInterface
Indicates whether to show full exception stack traces or just the first lines. Default is false.

Specified by:
dbgShowFullStackTrace in interface JGEngineInterface

dbgShowMessagesInPf

public void dbgShowMessagesInPf(boolean enabled)
Description copied from interface: JGEngineInterface
Output messages on playfield instead of console. Default is true. Messages printed by an object are displayed close to that object. Messages printed by the main program are shown at the bottom of the screen. The debug message font is used to display the messages.

A message that is generated in this frame is shown in the foreground colour at the appropriate source. If the source did not generate a message, the last printed message remains visible, and is shown in debug colour 1. If an object prints a message, and then dies, the message will remain for a period of time after the object is gone. These messages are shown in debug colour 2.

Specified by:
dbgShowMessagesInPf in interface JGEngineInterface

dbgSetMessageExpiry

public void dbgSetMessageExpiry(int ticks)
Description copied from interface: JGEngineInterface
Set the number of frames a debug message of a removed object should remain on the playfield.

Specified by:
dbgSetMessageExpiry in interface JGEngineInterface

dbgSetMessageFont

public void dbgSetMessageFont(JGFont font)
Description copied from interface: JGEngineInterface
Set the font for displaying debug messages.

Specified by:
dbgSetMessageFont in interface JGEngineInterface

dbgSetDebugColor1

public void dbgSetDebugColor1(JGColor col)
Description copied from interface: JGEngineInterface
Set debug color 1, used for printing debug information.

Specified by:
dbgSetDebugColor1 in interface JGEngineInterface

dbgSetDebugColor2

public void dbgSetDebugColor2(JGColor col)
Description copied from interface: JGEngineInterface
Set debug color 2, used for printing debug information.

Specified by:
dbgSetDebugColor2 in interface JGEngineInterface

dbgPrint

public void dbgPrint(java.lang.String msg)
Description copied from interface: JGEngineInterface
Print a debug message, with the main program being the source.

Specified by:
dbgPrint in interface JGEngineInterface

dbgPrint

public void dbgPrint(java.lang.String source,
                     java.lang.String msg)
Description copied from interface: JGEngineInterface
Print a debug message from a specific source, which is either the main program or a JGObject.

Specified by:
dbgPrint in interface JGEngineInterface
Parameters:
source - may be object ID or "MAIN" for the main program.

dbgShowException

public void dbgShowException(java.lang.String source,
                             java.lang.Throwable e)
Description copied from interface: JGEngineInterface
Print the relevant information of an exception as a debug message.

Specified by:
dbgShowException in interface JGEngineInterface
Parameters:
source - may be object ID or "MAIN" for the main program.

dbgExceptionToString

public java.lang.String dbgExceptionToString(java.lang.Throwable e)
Description copied from interface: JGEngineInterface
Convert the relevant information of an exception to a multiline String.

Specified by:
dbgExceptionToString in interface JGEngineInterface

exitEngine

public void exitEngine(java.lang.String msg)
Description copied from interface: JGEngineInterface
Exit, optionally reporting an exit message. The exit message can be used to report fatal errors. In case of an application or midlet, the program exits. In case of an applet, destroy is called, and the exit message is displayed on the playfield.

Specified by:
exitEngine in interface JGEngineInterface
Parameters:
msg - an exit message, null means none

initEngineComponent

public void initEngineComponent(int width,
                                int height)
Description copied from interface: JGEngineInterface
Init engine as component to be embedded in a frame or panel; call this in your engine constructor.

Specified by:
initEngineComponent in interface JGEngineInterface
Parameters:
width - canvas width
height - canvas height

initEngineApplet

public void initEngineApplet()
Init engine as applet; call this in your engine constructor. Applet init() will start the game.

Specified by:
initEngineApplet in interface JGEngineInterface

initEngine

public void initEngine(int width,
                       int height)
Init engine as application. Passing (0,0) for width, height will result in a full-screen window without decoration. Passing another value results in a regular window with decoration.

Specified by:
initEngine in interface JGEngineInterface
Parameters:
width - real screen width, 0 = use screen size
height - real screen height, 0 = use screen size

setCanvasSettings

public void setCanvasSettings(int nrtilesx,
                              int nrtilesy,
                              int tilex,
                              int tiley,
                              JGColor fgcolor,
                              JGColor bgcolor,
                              JGFont msgfont)
Description copied from interface: JGEngineInterface
Set canvas dimensions and message colours/fonts. You must call this in initCanvas().

Specified by:
setCanvasSettings in interface JGEngineInterface
Parameters:
nrtilesx - nr of tiles horizontally
nrtilesy - nr of tiles vertically
tilex - width of one tile
tiley - height of one tile
fgcolor - pen/text colour, null for default white
bgcolor - background colour, null for default black
msgfont - font for messages and text drawing, null for default

setScalingPreferences

public void setScalingPreferences(double min_aspect_ratio,
                                  double max_aspect_ratio,
                                  int crop_top,
                                  int crop_left,
                                  int crop_bottom,
                                  int crop_right)
Description copied from interface: JGEngineInterface
Set scaling preferences for translating the virtual playfield to the actual display. You can only call this in initCanvas(). You can set the allowed aspect ratio and the crop margin here. Aspect ratio is defined as the ratio (actual_tile_width / actual_tile_height) / (virtual_tile_width / virtual_tile_height). So, if the tile size of the scaled display is (3,2) pixels, and the original was (4,4) pixels, the aspect ratio is 1.5. Default values for min_aspect_ratio and max_aspect_ratio are resp 0.75 and 1.333. Setting both to 1.0 means you always get a square aspect ratio.

Crop margin can be used if you wish to allow the scaling algorithm to take just a few pixels off your playfield in order to make a wider tile size fit. The tile size is always integer, so even a best-fit scaled tile size may leave an unused border around the playfield, which may be undesirable for small screens. Cropping just a few pixels off the playfield may be just enough to make the tiles 1 pixel larger. Setting a crop to a value greater than zero means you allow the playfield to fall off the canvas for the amount of actual pixels specified, in order to make a larger tile size fit. Default crop margin is 0.

Specified by:
setScalingPreferences in interface JGEngineInterface
Parameters:
min_aspect_ratio - minimum width:height ratio allowed
max_aspect_ratio - maximum width:height ratio allowed
crop_top - number of pixels to crop at top
crop_left - number of pixels to crop at left size
crop_bottom - number of pixels to crop at bottom
crop_right - number of pixels to crop at right size

setSmoothing

public void setSmoothing(boolean smooth_magnify)
Description copied from interface: JGEngineInterface
Magnification can be set to smooth or blocky. For platforms that enable smooth magnification (OpenGL), smoothing may look too blurry when magnifying by a large amount, so blocky magnification may actually look more charming.

Specified by:
setSmoothing in interface JGEngineInterface
Parameters:
smooth_magnify - smooth images when magnifying

requestGameFocus

public void requestGameFocus()
Description copied from interface: JGEngineInterface
Call this to get focus.

Specified by:
requestGameFocus in interface JGEngineInterface

isApplet

public boolean isApplet()
Description copied from interface: JGEngineInterface
Are we running as an applet or as an application?

Specified by:
isApplet in interface JGEngineInterface

isMidlet

public boolean isMidlet()
Description copied from interface: JGEngineInterface
Are we running as a midlet?

Specified by:
isMidlet in interface JGEngineInterface

isOpenGL

public boolean isOpenGL()
Description copied from interface: JGEngineInterface
Are we running with an OpenGL backend?

Specified by:
isOpenGL in interface JGEngineInterface

isAndroid

public boolean isAndroid()
Description copied from interface: JGEngineInterface
Are we running on Android?

Specified by:
isAndroid in interface JGEngineInterface

viewWidth

public int viewWidth()
Description copied from interface: JGEngineInterface
Get the virtual width in pixels (not the scaled screen width)

Specified by:
viewWidth in interface JGEngineInterface

viewHeight

public int viewHeight()
Description copied from interface: JGEngineInterface
Get the virtual height in pixels (not the scaled screen height)

Specified by:
viewHeight in interface JGEngineInterface

viewTilesX

public int viewTilesX()
Description copied from interface: JGEngineInterface
Get the number of tiles of view window in X direction

Specified by:
viewTilesX in interface JGEngineInterface

viewTilesY

public int viewTilesY()
Description copied from interface: JGEngineInterface
Get the number of tiles of view window in Y direction

Specified by:
viewTilesY in interface JGEngineInterface

viewXOfs

public int viewXOfs()
Description copied from interface: JGEngineInterface
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.

Specified by:
viewXOfs in interface JGEngineInterface

viewYOfs

public int viewYOfs()
Description copied from interface: JGEngineInterface
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.

Specified by:
viewYOfs in interface JGEngineInterface

pfWidth

public int pfWidth()
Description copied from interface: JGEngineInterface
Get the virtual width in pixels (not the scaled screen width)

Specified by:
pfWidth in interface JGEngineInterface

pfHeight

public int pfHeight()
Description copied from interface: JGEngineInterface
Get the virtual height in pixels (not the scaled screen height)

Specified by:
pfHeight in interface JGEngineInterface

pfTilesX

public int pfTilesX()
Description copied from interface: JGEngineInterface
Get the number of tiles in X direction

Specified by:
pfTilesX in interface JGEngineInterface

pfTilesY

public int pfTilesY()
Description copied from interface: JGEngineInterface
Get the number of tiles in Y direction

Specified by:
pfTilesY in interface JGEngineInterface

pfWrapX

public boolean pfWrapX()
Description copied from interface: JGEngineInterface
Is playfield X wrap enabled?

Specified by:
pfWrapX in interface JGEngineInterface

pfWrapY

public boolean pfWrapY()
Description copied from interface: JGEngineInterface
Is playfield Y wrap enabled?

Specified by:
pfWrapY in interface JGEngineInterface

tileWidth

public int tileWidth()
Description copied from interface: JGEngineInterface
Get the tile width in (virtual) pixels.

Specified by:
tileWidth in interface JGEngineInterface

tileHeight

public int tileHeight()
Description copied from interface: JGEngineInterface
Get the tile height in (virtual) pixels.

Specified by:
tileHeight in interface JGEngineInterface

displayWidth

public int displayWidth()
Description copied from interface: JGEngineInterface
Get the real display width on this device.

Specified by:
displayWidth in interface JGEngineInterface

displayHeight

public int displayHeight()
Description copied from interface: JGEngineInterface
Get the real display height on this device.

Specified by:
displayHeight in interface JGEngineInterface

getFrameRate

public double getFrameRate()
Specified by:
getFrameRate in interface JGEngineInterface
Returns:
frame rate in frames per second

getGameSpeed

public double getGameSpeed()
Description copied from interface: JGEngineInterface
Get game speed variable. This can be used if you have other stuff in your game that is affected by game speed, besides the standard game speed adaptation done by the engine.

Specified by:
getGameSpeed in interface JGEngineInterface

getFrameSkip

public double getFrameSkip()
Specified by:
getFrameSkip in interface JGEngineInterface
Returns:
max successive frames to skip

getVideoSyncedUpdate

public boolean getVideoSyncedUpdate()
Specified by:
getVideoSyncedUpdate in interface JGEngineInterface
Returns:
true = video synced mode enabled

getOffscreenMarginX

public int getOffscreenMarginX()
Description copied from interface: JGEngineInterface
Get offscreen X margin.

Specified by:
getOffscreenMarginX in interface JGEngineInterface
See Also:
JGEngineInterface.setOffscreenMargin(int,int)

getOffscreenMarginY

public int getOffscreenMarginY()
Description copied from interface: JGEngineInterface
Get offscreen Y margin.

Specified by:
getOffscreenMarginY in interface JGEngineInterface
See Also:
JGEngineInterface.setOffscreenMargin(int,int)

getXScaleFactor

public double getXScaleFactor()
Description copied from interface: JGEngineInterface
Get scale factor of real screen width wrt virtual screen width

Specified by:
getXScaleFactor in interface JGEngineInterface

getYScaleFactor

public double getYScaleFactor()
Description copied from interface: JGEngineInterface
Get scale factor of real screen height wrt virtual screen height

Specified by:
getYScaleFactor in interface JGEngineInterface

getMinScaleFactor

public double getMinScaleFactor()
Description copied from interface: JGEngineInterface
Get minimum of the x and y scale factors

Specified by:
getMinScaleFactor in interface JGEngineInterface

init

public void init()
Initialise engine; don't call directly. This is supposed to be called by the applet viewer or the initer.

Overrides:
init in class java.applet.Applet

initCanvas

public abstract void initCanvas()
Description copied from interface: JGEngineInterface
Override to define your own initialisations before the engine initialises. This method is meant for doing initialisations after the applet has been initialised (in case we're an applet) but before the engine initialises. This can be considered a replacement of the regular constructor, making it independent of whether we're an applet or application. Typically you only need to call setCanvasSettings here, and, optionally, setScalingPreferences(). This is the place where you can read applet parameters and initialise accordingly. In case you want to adapt to the real display dimensions, you can get them using displayWidth/Height at this point.

Specified by:
initCanvas in interface JGEngineInterface

initGame

public abstract void initGame()
Description copied from interface: JGEngineInterface
Override to define your own initialisations after the engine initialised. This method is called by the game thread after initEngine(), initEngineApplet(), or initEngineComponent() was called.

Specified by:
initGame in interface JGEngineInterface

start

public void start()
Description copied from interface: JGEngineInterface
Signal that the engine should start running. May be called by the web browser.

Specified by:
start in interface JGEngineInterface
Overrides:
start in class java.applet.Applet

stop

public void stop()
Description copied from interface: JGEngineInterface
signal that the engine should stop running and wait. May be called by the web browser.

Specified by:
stop in interface JGEngineInterface
Overrides:
stop in class java.applet.Applet

startApp

public void startApp()
Description copied from interface: JGEngineInterface
Called when midlet is first initialised, or unpaused. Midlet version of init() when called for the first time, and start() for subsequent calls.

Specified by:
startApp in interface JGEngineInterface

pauseApp

public void pauseApp()
Description copied from interface: JGEngineInterface
Called by the application manager to pause app. Basically the midlet version of stop(), behaves the same as stop().

Specified by:
pauseApp in interface JGEngineInterface

destroyApp

public void destroyApp(boolean unconditional)
Description copied from interface: JGEngineInterface
Called by the application manager to exit app. Basically the midlet version of destroy(), behaves the same as destroy().

Specified by:
destroyApp in interface JGEngineInterface

isRunning

public boolean isRunning()
Description copied from interface: JGEngineInterface
True if engine is running, false if paused.

Specified by:
isRunning in interface JGEngineInterface

wakeUpOnKey

public void wakeUpOnKey(int key)
Description copied from interface: JGEngineInterface
Make engine call start() when a key is pressed. This can be used to determine a start criterion when halting the engine from within using stop().

Specified by:
wakeUpOnKey in interface JGEngineInterface
Parameters:
key - keycode to wake up on, -1=any key or mouse, 0=none

destroy

public void destroy()
Description copied from interface: JGEngineInterface
Destroy function for deinitialising the engine properly. This is called by the applet viewer to dispose the applet. Use exitEngine to destroy the applet and exit the system.

Specified by:
destroy in interface JGEngineInterface
Overrides:
destroy in class java.applet.Applet

setViewOffset

public void setViewOffset(int xofs,
                          int yofs,
                          boolean centered)
Description copied from interface: JGEngineInterface
Change offset of playfield view. The offset will become active at the next frame draw. If the view would be out of the playfield's bounds, the offset is corrected so that it is inside them. The offset of the parallax level 0 background image is set to the offset as well, the other levels remain unchanged.

Specified by:
setViewOffset in interface JGEngineInterface
centered - center view on (xofs, yofs), topleft otherwise

setBGImgOffset

public void setBGImgOffset(int depth,
                           double xofs,
                           double yofs,
                           boolean centered)
Description copied from interface: JGEngineInterface
Change (absolute) offset of BG image independently of view offset. Only supported by parallax scrolling platforms. Note that parallax level 0 follows the view offset, so a call to this method to set level 0 should be done after calling setViewOffset.

Specified by:
setBGImgOffset in interface JGEngineInterface
Parameters:
depth - depth level of image to set
centered - center view on (xofs, yofs), topleft otherwise

setViewZoomRotate

public void setViewZoomRotate(double zoom,
                              double rotate)
Description copied from interface: JGEngineInterface
Zoom/rotate view. Can be used to create special effects, like speed-dependent zoom, explosion shake, etc. Only works in OpenGL. If you zoom out too far, parts that are beyond the borders of the defined view may get exposed, the appearance of which is undefined. This also happens when you rotate, so you will also need to zoom in to ensure this does not happen. Everything that is drawn relative to the playfield is zoomed/rotated, everything that is not is unaffected. Game logic is unaffected.

Mouse coordinates are inverse projected through the last set zoom/rotate setting, so that a playfield relative pixel drawn at the logical mouse coordinates coincides with the physical position of the mouse pointer. If you don't want this, you can set zoom/rotate to (1,0), read the mouse position, then set zoom/rotate to the desired value.

The zoom/rotate setting used for actual drawing is the last value set at the end of the doFrame phase. Should not be called during the paintFrame phase.

Specified by:
setViewZoomRotate in interface JGEngineInterface
Parameters:
zoom - zoom factor, 1.0 is normal size
rotate - angle in radians

setPFSize

public void setPFSize(int nrtilesx,
                      int nrtilesy)
Description copied from interface: JGEngineInterface
Set the playfield size to be any size larger or equal to the view size.

Specified by:
setPFSize in interface JGEngineInterface
Parameters:
nrtilesx - number of tiles, >= viewTilesX()
nrtilesy - number of tiles, >= viewTilesY()

setPFWrap

public void setPFWrap(boolean wrapx,
                      boolean wrapy,
                      int shiftx,
                      int shifty)
Description copied from interface: JGEngineInterface
Set playfield wraparound setting. When wraparound is enabled, the playfield theoretically behaves as if it is infinitely long or high, with tiles and objects repeating periodically, with playfield size being the period. Tile coordinates in a wrapped playfield are effectively modulo the playfield size. Object coordinates are wrapped symmetrically to the view offset, that is, they are kept within -playfieldsize, +playfieldsize of the center of the view offset. This ensures that regular coordinate comparison and collision usually work as expected, without having to actually model the infinite repetition of the objects in the wrap direction. The shiftx and shifty can be used to shift the object's wrap center by some pixels, to ensure they enter and leave the sides / top-bottom of the screen neatly when the playfield is not larger than the view. For this case, use the following formula: ensure the playfield is slightly larger than the view (namely, one sprite length), and set the shift to sprite length/2.

Specified by:
setPFWrap in interface JGEngineInterface

setFrameRate

public void setFrameRate(double fps,
                         double maxframeskip)
Description copied from interface: JGEngineInterface
Set frame rate in frames per second, and maximum number of frames that may be skipped before displaying a frame again. Default is 35 frames per second, with a maxframeskip of 4.

Specified by:
setFrameRate in interface JGEngineInterface
Parameters:
fps - frames per second, useful range 2...80
maxframeskip - max successive frames to skip, useful range 0..10

setVideoSyncedUpdate

public void setVideoSyncedUpdate(boolean value)
Description copied from interface: JGEngineInterface
Enable/disable video synced update (jogl only). This method has no effect on non-jogl platforms, where it is always disabled. The game state update becomes synced with the screen refresh rate. Frame rate is no longer fixed, but depends on the machine the game is running on. Gamespeed is set at the beginning of each frame to compensate for this. Gamespeed is 1 when actual frame rate == frame rate set with setFrameRate, less than 1 if frame rate greater than setFrameRate, more than 1 if frame rate less than setFrameRate. There is a hard upper and lower bound for gamespeed, to ensure it does not attain wild values under rare conditions. Lower bound for game speed is determined by a fixed upper bound for the expected screen refresh rate, 95 hz. Upper bound for game speed is determined by the frameskip setting.

Specified by:
setVideoSyncedUpdate in interface JGEngineInterface

setGameSpeed

public void setGameSpeed(double gamespeed)
Description copied from interface: JGEngineInterface
Set game speed variable, default is 1.0. Game speed affects certain parts of the game engine automatically to offload some of the work involved of adapting a game to different speeds. These are the following: it is used as JGTimer tick increment, animation increment, JGObject expiry increment, and is used as multiplier for object x/yspeed, and for the default margins of is...Aligned and snapToGrid.

Specified by:
setGameSpeed in interface JGEngineInterface

setRenderSettings

public void setRenderSettings(int alpha_thresh,
                              JGColor render_bg_col)
Description copied from interface: JGEngineInterface
Configure image rendering. alpha_thresh is used to determine how a translucent image is converted to a bitmask image. Alpha values below the threshold are set to 0, the others to 255. render_bg_col is used to render transparency for scaled images; it is the background colour that interpolations between transparent and non-transparent pixels are rendered to. Currently, this has an effect in Jdk1.2 only. The default render_bg_col is null, meaning the global background colour is used.

Specified by:
setRenderSettings in interface JGEngineInterface
Parameters:
alpha_thresh - bitmask threshold, 0...255, default=128
render_bg_col - bg colour for render, null=use background colour

setOffscreenMargin

public void setOffscreenMargin(int xmargin,
                               int ymargin)
Description copied from interface: JGEngineInterface
Set margin used for testing if object should expire or suspend when off-view or off-playfield. Default is 16,16.

Specified by:
setOffscreenMargin in interface JGEngineInterface

setBGColor

public void setBGColor(JGColor bgcolor)
Set global background colour, which is displayed in borders, and behind transparent tiles if no BGImage is defined.

Specified by:
setBGColor in interface JGEngineInterface

setFGColor

public void setFGColor(JGColor fgcolor)
Set global foreground colour, used for printing text and status messages. It is also the default colour for painting

Specified by:
setFGColor in interface JGEngineInterface

setMsgFont

public void setMsgFont(JGFont msgfont)
Set the (unscaled) message font, used for displaying status messages. It is also the default font for painting.

Specified by:
setMsgFont in interface JGEngineInterface

setColorsFont

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

Specified by:
setColorsFont in interface JGEngineInterface

setTextOutline

public void setTextOutline(int thickness,
                           JGColor colour)
Set parameters of outline surrounding text (for example, used to increase contrast).

Specified by:
setTextOutline in interface JGEngineInterface
Parameters:
thickness - 0 = turn off outline

setMouseCursor

public void setMouseCursor(int cursor)
Description copied from interface: JGEngineInterface
Set mouse cursor to a platform-independent standard cursor.

Specified by:
setMouseCursor in interface JGEngineInterface

setMouseCursor

public void setMouseCursor(java.lang.Object cursor)
Set mouse cursor, null means hide cursor.

Specified by:
setMouseCursor in interface JGEngineInterface
Parameters:
cursor - is of type java.awt.Cursor

removeAllTimers

public void removeAllTimers()
Description copied from interface: JGEngineInterface
Remove all JGTimers still ticking in the system.

Specified by:
removeAllTimers in interface JGEngineInterface

registerTimer

public void registerTimer(JGTimer timer)
Description copied from interface: JGEngineInterface
Register a timer with the engine, don't call directly. This is called automatically by the JGTimer constructor.

Specified by:
registerTimer in interface JGEngineInterface

setGameState

public void setGameState(java.lang.String state)
Description copied from interface: JGEngineInterface
Set the game's main state on the next frame. Methods with the names doFrame<state> and paintFrame<state> will be called in addition to doFrame() and paintFrame(). Before the next frame, start<state> is called once. Note that setGameState may actually set a state that's already set, in which case start<state> is not called. Also, if the setGameState is superseded by another setGameState within the same frame, the first setGameState is ignored.

Specified by:
setGameState in interface JGEngineInterface

addGameState

public void addGameState(java.lang.String state)
Description copied from interface: JGEngineInterface
Add the given state to the game's existing state on the next frame. The methods doFrame<state> and paintFrame<state> will be called in addition to the methods of any states already set. Before the next frame, start<state> is called once. Note that addGameState may actually set a state that's already set, in which case start<state> is not called.

Specified by:
addGameState in interface JGEngineInterface

removeGameState

public void removeGameState(java.lang.String state)
Description copied from interface: JGEngineInterface
Remove the given state from the game's existing state on the next frame.

Specified by:
removeGameState in interface JGEngineInterface

clearGameState

public void clearGameState()
Description copied from interface: JGEngineInterface
Set the game's main state to none, on the next frame. Only doFrame() and paintFrame() will be called each frame.

Specified by:
clearGameState in interface JGEngineInterface

inGameState

public boolean inGameState(java.lang.String state)
Description copied from interface: JGEngineInterface
Check if game is in given state.

Specified by:
inGameState in interface JGEngineInterface

inGameStateNextFrame

public boolean inGameStateNextFrame(java.lang.String state)
Description copied from interface: JGEngineInterface
Check if game will be in given state the next frame.

Specified by:
inGameStateNextFrame in interface JGEngineInterface

doFrame

public void doFrame()
Description copied from interface: JGEngineInterface
Is called every frame. Override to define frame action. Default is do nothing.

Specified by:
doFrame in interface JGEngineInterface

paintFrame

public void paintFrame()
Description copied from interface: JGEngineInterface
Is called when the engine's default screen painting is finished, and custom painting actions may be carried out. Can be used to display status information or special graphics. Default is do nothing.

Specified by:
paintFrame in interface JGEngineInterface

getBufferGraphics

public java.awt.Graphics getBufferGraphics()
get Graphics used to draw on buffer (JRE, non JOGL only).


setColor

public void setColor(JGColor col)
Description copied from interface: JGEngineInterface
Set current drawing colour.

Specified by:
setColor in interface JGEngineInterface

getAWTColor

public java.awt.Color getAWTColor(JGColor col)
Convert JGColor to AWT color (JRE only).


setFont

public void setFont(JGFont font)
Description copied from interface: JGEngineInterface
Set current font, scale the font to screen size.

Specified by:
setFont in interface JGEngineInterface

setFont

public void setFont(java.awt.Graphics g,
                    JGFont jgfont)

setStroke

public void setStroke(double thickness)
Description copied from interface: JGEngineInterface
Set the line thickness

Specified by:
setStroke in interface JGEngineInterface

setBlendMode

public void setBlendMode(int src_func,
                         int dst_func)
Description copied from interface: JGEngineInterface
Set blend mode, for platforms that support blending. Blend functions supported are based on the alpha of the object being drawn (the drawing source). Source and destination alpha multiplier are specified separately. These are one of: always 1 (encoded as 0), alpha (encoded as 1), and 1-alpha (encoded as -1). Default is (1,-1).

Specified by:
setBlendMode in interface JGEngineInterface
Parameters:
src_func - source multiply factor, 0=one, 1=alpha, -1 = one - alpha
dst_func - destination multiply factor, 0=one, 1=alpha, -1 = one - alpha

getFontHeight

public double getFontHeight(JGFont jgfont)
Description copied from interface: JGEngineInterface
Get height of given font in pixels.

Specified by:
getFontHeight in interface JGEngineInterface

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2,
                     double thickness,
                     JGColor color)
Description copied from interface: JGEngineInterface
DrawLine combined with thickness/colour setting. The line is drawn relative to the playfield coordinates.

Specified by:
drawLine in interface JGEngineInterface

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Description copied from interface: JGEngineInterface
Draw a line with current thickness and colour. The line is drawn relative to the playfield coordinates.

Specified by:
drawLine in interface JGEngineInterface

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2,
                     boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw a line with current thickness and colour.

Specified by:
drawLine in interface JGEngineInterface
pf_relative - coordinates are relative to playfield, otherwise view

drawPolygon

public void drawPolygon(double[] x,
                        double[] y,
                        JGColor[] col,
                        int len,
                        boolean filled,
                        boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw convex polygon. For filled polygons, it is possible to draw a colour gradient, namely a "fan" of colours (specified by col), spreading from the first point to each successive point in the polygon. For line polygons, a gradient is drawn between successive line segments. On non-OpenGL platforms, the fill gradient is drawn as a fan of plain colours, with colour 0 and 1 ignored, the line gradient as plain coloured lines.

Specified by:
drawPolygon in interface JGEngineInterface
Parameters:
x - x coordinates of the points
y - y coordinates of the points
col - colour of each point, null means use default colour
len - number of points
pf_relative - coordinates are relative to playfield, otherwise view

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     double thickness,
                     JGColor color)
Description copied from interface: JGEngineInterface
Set colour/thickness and draw rectangle. Coordinates are relative to playfield.

Specified by:
drawRect in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered)
Description copied from interface: JGEngineInterface
Draw rectangle in default colour and thickness. Coordinates are relative to playfield.

Specified by:
drawRect in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw rectangle in default colour and thickness.

Specified by:
drawRect in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.
pf_relative - coordinates are relative to playfield, otherwise view

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     boolean pf_relative,
                     JGColor[] shadecol)
Description copied from interface: JGEngineInterface
Draw shaded rectangle. On non-opengl platforms, rectangle is drawn in default colour.

Specified by:
drawRect in interface JGEngineInterface
shadecol - colors topleft,topright,botright,botleft corners

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     boolean pf_relative,
                     JGColor[] shadecol,
                     java.lang.String tileimage)
Description copied from interface: JGEngineInterface
Draw shaded or patterned rectangle. On non-opengl platforms, rectangle is drawn in default colour.

Specified by:
drawRect in interface JGEngineInterface
shadecol - colors topleft,topright,botright,botleft corners

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     double thickness,
                     JGColor color)
Description copied from interface: JGEngineInterface
Set thickness/colour and draw oval. Coordinates are relative to playfield.

Specified by:
drawOval in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered)
Description copied from interface: JGEngineInterface
Draw oval with default thickness and colour. Coordinates are relative to playfield.

Specified by:
drawOval in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height,
                     boolean filled,
                     boolean centered,
                     boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw oval with default thickness and colour.

Specified by:
drawOval in interface JGEngineInterface
centered - indicates (x,y) is center instead of topleft.
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

public void drawImage(double x,
                      double y,
                      java.lang.String imgname)
Description copied from interface: JGEngineInterface
Draw image with given ID. Coordinates are relative to playfield.

Specified by:
drawImage in interface JGEngineInterface

drawImage

public void drawImage(double x,
                      double y,
                      java.lang.String imgname,
                      boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw image with given ID.

Specified by:
drawImage in interface JGEngineInterface
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

public void drawImage(double x,
                      double y,
                      java.lang.String imgname,
                      JGColor blend_col,
                      double alpha,
                      double rot,
                      double scale,
                      boolean pf_relative)
Description copied from interface: JGEngineInterface
Extended version of drawImage for OpenGL or Android. On platforms without support for accelerated blending, rotation, scaling, this call is equivalent to drawImage(x,y,imgname,pf_relative). rotation and scaling are centered around the image center.

Specified by:
drawImage in interface JGEngineInterface
blend_col - colour to blend with image, null=(alpha,alpha,alpha)
alpha - alpha (blending) value, 0=transparent, 1=opaque
rot - rotation of object in degrees (radians)
scale - scaling of object (1 = normal size).

drawImage

public void drawImage(java.lang.String imgname,
                      double x,
                      double y)
Description copied from interface: JGEngineInterface
Draw image with given ID, new version. Coordinates are relative to playfield.

Specified by:
drawImage in interface JGEngineInterface

drawImage

public void drawImage(java.lang.String imgname,
                      double x,
                      double y,
                      boolean pf_relative)
Description copied from interface: JGEngineInterface
Draw image with given ID, new version.

Specified by:
drawImage in interface JGEngineInterface
pf_relative - coordinates are relative to playfield, otherwise view

drawImage

public void drawImage(java.lang.String imgname,
                      double x,
                      double y,
                      boolean pf_relative,
                      JGColor blend_col,
                      double alpha,
                      double rot,
                      double scale)
Description copied from interface: JGEngineInterface
Extended version of drawImage for OpenGL or Android, new version. On platforms without support for accelerated blending, rotation, scaling, this call is equivalent to drawImage(x,y,imgname,pf_relative). rotation and scaling are centered around the image center.

Specified by:
drawImage in interface JGEngineInterface
blend_col - colour to blend with image, null=(alpha,alpha,alpha)
alpha - alpha (blending) value, 0=transparent, 1=opaque
rot - rotation of object in degrees (radians)
scale - scaling of object (1 = normal size).

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y,
                       int align,
                       JGFont font,
                       JGColor color)
Description copied from interface: JGEngineInterface
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). Use given font and colour; filling in null for either means ignore. Unlike the other draw functions, for strings, coordinates are relative to view by default. An outline is drawn around the text when defined by setTextOutline.

Specified by:
drawString in interface JGEngineInterface
align - text alignment, -1=left, 0=center, 1=right

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y,
                       int align)
Description copied from interface: JGEngineInterface
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). Use current font and colour. Unlike the other draw functions, for strings, coordinates are relative to view by default. An outline is drawn around the text when defined by setTextOutline.

Specified by:
drawString in interface JGEngineInterface
align - text alignment, -1=left, 0=center, 1=right

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y,
                       int align,
                       boolean pf_relative)
Description copied from interface: JGEngineInterface
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). Use current font and colour. An outline is drawn around the text when defined by setTextOutline.

Specified by:
drawString in interface JGEngineInterface
align - text alignment, -1=left, 0=center, 1=right
pf_relative - coordinates are relative to playfield, otherwise view

drawImageString

public void drawImageString(java.lang.String string,
                            double x,
                            double y,
                            int align,
                            java.lang.String imgmap,
                            int char_offset,
                            int spacing)
Description copied from interface: JGEngineInterface
Draws a single line of text using an image map as font; text alignment is same as drawString. Typically, an image font only defines the ASCII character range 32-96. In this case, set char_offset to 32, and use only the uppercase letters. Coordinates are relative to view.

Specified by:
drawImageString in interface JGEngineInterface
align - text alignment, -1=left, 0=center, 1=right
imgmap - name of image map
char_offset - ASCII code of first image of image map
spacing - number of pixels to skip between letters

drawImageString

public void drawImageString(java.lang.String string,
                            double x,
                            double y,
                            int align,
                            java.lang.String imgmap,
                            int char_offset,
                            int spacing,
                            boolean pf_relative)
Description copied from interface: JGEngineInterface
Draws a single line of text using an image map as font; text alignment is same as drawString. Typically, an image font only defines the ASCII character range 32-96. In this case, set char_offset to 32, and use only the uppercase letters.

Specified by:
drawImageString in interface JGEngineInterface
align - text alignment, -1=left, 0=center, 1=right
imgmap - name of image map
char_offset - ASCII code of first image of image map
spacing - number of pixels to skip between letters
pf_relative - coordinates are relative to playfield, otherwise view

getMousePos

public JGPoint getMousePos()
Description copied from interface: JGEngineInterface
Get current mouse position in logical coordinates, inverse projected through last set view zoom/rotate setting.

Specified by:
getMousePos in interface JGEngineInterface

getMouseX

public int getMouseX()
Description copied from interface: JGEngineInterface
Get current mouse X position

Specified by:
getMouseX in interface JGEngineInterface

getMouseY

public int getMouseY()
Description copied from interface: JGEngineInterface
Get current mouse Y position

Specified by:
getMouseY in interface JGEngineInterface

getMouseButton

public boolean getMouseButton(int nr)
Description copied from interface: JGEngineInterface
Get state of button.

Specified by:
getMouseButton in interface JGEngineInterface
Parameters:
nr - 1=button 1 ... 3 = button 3
Returns:
true=pressed, false=released

clearMouseButton

public void clearMouseButton(int nr)
Description copied from interface: JGEngineInterface
Set state of button to released.

Specified by:
clearMouseButton in interface JGEngineInterface
Parameters:
nr - 1=button 1 ... 3 = button 3

setMouseButton

public void setMouseButton(int nr)
Description copied from interface: JGEngineInterface
Set state of button to pressed.

Specified by:
setMouseButton in interface JGEngineInterface
Parameters:
nr - 1=button 1 ... 3 = button 3

getMouseInside

public boolean getMouseInside()
Description copied from interface: JGEngineInterface
Check if mouse is inside game window

Specified by:
getMouseInside in interface JGEngineInterface

getKey

public boolean getKey(int key)
Description copied from interface: JGEngineInterface
Get the key status of the given key.

Specified by:
getKey in interface JGEngineInterface

clearKey

public void clearKey(int key)
Description copied from interface: JGEngineInterface
Set the key status of a key to released.

Specified by:
clearKey in interface JGEngineInterface

setKey

public void setKey(int key)
Description copied from interface: JGEngineInterface
Set the key status of a key to pressed.

Specified by:
setKey in interface JGEngineInterface

getLastKey

public int getLastKey()
Description copied from interface: JGEngineInterface
Get the keycode of the key that was pressed last, 0=none.

Specified by:
getLastKey in interface JGEngineInterface

getLastKeyChar

public char getLastKeyChar()
Description copied from interface: JGEngineInterface
Get the keycode of the key that was pressed last, 0=none.

Specified by:
getLastKeyChar in interface JGEngineInterface

clearLastKey

public void clearLastKey()
Description copied from interface: JGEngineInterface
Clear the lastkey status.

Specified by:
clearLastKey in interface JGEngineInterface

getKeyDesc

public java.lang.String getKeyDesc(int key)
Non-static version for the sake of the interface.

Specified by:
getKeyDesc in interface JGEngineInterface

getKeyDescStatic

public static java.lang.String getKeyDescStatic(int key)

getKeyCode

public int getKeyCode(java.lang.String keydesc)
Non-static version for the sake of the interface.

Specified by:
getKeyCode in interface JGEngineInterface

getKeyCodeStatic

public static int getKeyCodeStatic(java.lang.String keydesc)

hasAccelerometer

public boolean hasAccelerometer()
Description copied from interface: JGEngineInterface
returns true if device has accelerometer (currently only android)

Specified by:
hasAccelerometer in interface JGEngineInterface

getAccelX

public double getAccelX()
Description copied from interface: JGEngineInterface
get accelerometer vector X coordinate

Specified by:
getAccelX in interface JGEngineInterface

getAccelY

public double getAccelY()
Description copied from interface: JGEngineInterface
get accelerometer vector Y coordinate

Specified by:
getAccelY in interface JGEngineInterface

getAccelZ

public double getAccelZ()
Description copied from interface: JGEngineInterface
get accelerometer vector Z coordinate (positive = towards user)

Specified by:
getAccelZ in interface JGEngineInterface

getAccelVec

public double[] getAccelVec()
Description copied from interface: JGEngineInterface
get double[3] vector representing acceleration

Specified by:
getAccelVec in interface JGEngineInterface

defineAnimation

public void defineAnimation(java.lang.String id,
                            java.lang.String[] frames,
                            double speed)
Description copied from interface: JGEngineInterface
Define new animation sequence. Speed must be >= 0.

Specified by:
defineAnimation in interface JGEngineInterface
Parameters:
id - the name by which the animation is known
frames - an array of image names that should be played in sequence
speed - the sequence speed: the number of animation steps per frame

defineAnimation

public void defineAnimation(java.lang.String id,
                            java.lang.String[] frames,
                            double speed,
                            boolean pingpong)
Description copied from interface: JGEngineInterface
Define new animation sequence. Speed must be >= 0.

Specified by:
defineAnimation in interface JGEngineInterface
Parameters:
id - the name by which the animation is known
frames - an array of image names that should be played in sequence
speed - the sequence speed: the number of animation steps per frame
pingpong - true=play the images in forward order, then in reverse

getAnimation

public Animation getAnimation(java.lang.String id)
Description copied from interface: JGEngineInterface
Get animation definition, don't call directly. This is used by JGObjects to get animations.

Specified by:
getAnimation in interface JGEngineInterface

getConfigPath

public java.lang.String getConfigPath(java.lang.String filename)
Description copied from interface: JGEngineInterface
Returns path to writable location for a file with the given name. Basically it uses [user.home] / .jgame / [filename], with "/" being the system path separator. In case [user.home] / .jgame does not exist, it is created. In case .jgame is not a directory, null is returned. In case the file does not exist yet, an empty file is created.

Specified by:
getConfigPath in interface JGEngineInterface
Returns:
path to writable file, or null if not possible

invokeUrl

public int invokeUrl(java.lang.String url,
                     java.lang.String target)
Description copied from interface: JGEngineInterface
Execute or go to URL (action depends on file type).

Specified by:
invokeUrl in interface JGEngineInterface
Returns:
0 if fail; 1 if success; -1 if the status is unknown

and

public boolean and(int value,
                   int mask)
Description copied from interface: JGEngineInterface
A Boolean AND shorthand to use for collision; returns (value&mask) != 0.

Specified by:
and in interface JGEngineInterface

random

public double random(double min,
                     double max)
Description copied from interface: JGEngineInterface
A floating-point random number between min and max

Specified by:
random in interface JGEngineInterface

random

public double random(double min,
                     double max,
                     double interval)
Description copied from interface: JGEngineInterface
Generates discrete random number between min and max inclusive, with steps of interval. Epsilon is added to max to ensure there are no rounding error problems with the interval. So, random(0.0, 4.2, 2.1) generates either 0.0, 2.1, or 4.2 with uniform probabilities. If max is halfway between interval steps, max is treated as exclusive. So, random(0.0,5.0,2.1) generates 0.0, 2.1, 4.2 with uniform probabilities. If you need integer ranges, be sure to use the integer version to avoid rounding problems.

Specified by:
random in interface JGEngineInterface

random

public int random(int min,
                  int max,
                  int interval)
Description copied from interface: JGEngineInterface
Generates discrete random number between min and max inclusive, with steps of interval, integer version. If max is halfway between two interval steps, it is treated as exclusive.

Specified by:
random in interface JGEngineInterface

atan2

public double atan2(double y,
                    double x)
Description copied from interface: JGEngineInterface
Replacement for Math.atan2 for the sake of MIDP portability. The JRE implementation simply uses Math.atan2, for MIDP a short and fast Math.atan2 replacement is used, with average numerical error less than 0.001 radians, maximum error 0.005 radians.

Specified by:
atan2 in interface JGEngineInterface

getTileIndex

public JGPoint getTileIndex(double x,
                            double y)
Description copied from interface: JGEngineInterface
Get tile index of the tile the coordinate is on.

Specified by:
getTileIndex in interface JGEngineInterface

getTileCoord

public JGPoint getTileCoord(int tilex,
                            int tiley)
Description copied from interface: JGEngineInterface
Get pixel coordinate corresponding to the top left of the tile at the given index

Specified by:
getTileCoord in interface JGEngineInterface

getTileCoord

public JGPoint getTileCoord(JGPoint tileidx)
Description copied from interface: JGEngineInterface
Get pixel coordinate corresponding to the top left of the tile at the given index

Specified by:
getTileCoord in interface JGEngineInterface

snapToGridX

public double snapToGridX(double x,
                          double gridsnapx)
Description copied from interface: JGEngineInterface
Snap to grid, double version. Epsilon is added to the gridsnap value, so that isXAligned(x,margin) always implies that snapToGridX(x,margin) will snap.

Specified by:
snapToGridX in interface JGEngineInterface
Parameters:
x - position to snap
gridsnapx - snap margin, 0.0 means no snap

snapToGridY

public double snapToGridY(double y,
                          double gridsnapy)
Description copied from interface: JGEngineInterface
Snap to grid, double version. Epsilon is added to the gridsnap value, so that isYAligned(y,margin) always implies that snapToGridY(y,margin) will snap.

Specified by:
snapToGridY in interface JGEngineInterface
Parameters:
y - position to snap
gridsnapy - snap margin, 0.0 means no snap

snapToGrid

public void snapToGrid(JGPoint p,
                       int gridsnapx,
                       int gridsnapy)
Description copied from interface: JGEngineInterface
Snap p to grid in case p is close enough to the grid lines. Note: this function only handles integers so it should not be used to snap an object position.

Specified by:
snapToGrid in interface JGEngineInterface

isXAligned

public boolean isXAligned(double x,
                          double margin)
Description copied from interface: JGEngineInterface
Returns true if x falls within margin of the tile snap grid. Epsilon is added to the margin, so that isXAligned(1.0000, 1.0000) always returns true.

Specified by:
isXAligned in interface JGEngineInterface

isYAligned

public boolean isYAligned(double y,
                          double margin)
Description copied from interface: JGEngineInterface
Returns true if y falls within margin of the tile snap grid. Epsilon is added to the margin, so that isYAligned(1.0000, 1.0000) always returns true.

Specified by:
isYAligned in interface JGEngineInterface

getXAlignOfs

public double getXAlignOfs(double x)
Description copied from interface: JGEngineInterface
Returns the difference between position and the closest tile-aligned position.

Specified by:
getXAlignOfs in interface JGEngineInterface

getYAlignOfs

public double getYAlignOfs(double y)
Description copied from interface: JGEngineInterface
Returns the difference between position and the closest tile-aligned position.

Specified by:
getYAlignOfs in interface JGEngineInterface

getXDist

public double getXDist(double x1,
                       double x2)
Description copied from interface: JGEngineInterface
Calculates length of the shortest path between x1 and x2, with x1, x2 being playfield coordinates, taking into account the wrap setting.

Specified by:
getXDist in interface JGEngineInterface

getYDist

public double getYDist(double y1,
                       double y2)
Description copied from interface: JGEngineInterface
Calculates length of the shortest path between y1 and y2, with y1, y2 being playfield coordinates, taking into account the wrap setting.

Specified by:
getYDist in interface JGEngineInterface

enableAudio

public void enableAudio()
Description copied from interface: JGEngineInterface
Enable audio, restart any audio loops.

Specified by:
enableAudio in interface JGEngineInterface

disableAudio

public void disableAudio()
Description copied from interface: JGEngineInterface
Disable audio, stop all currently playing audio. Audio commands will be ignored, except that audio loops (music, ambient sounds) are remembered and will be restarted once audio is enabled again.

Specified by:
disableAudio in interface JGEngineInterface

defineAudioClip

public void defineAudioClip(java.lang.String clipid,
                            java.lang.String filename)
Description copied from interface: JGEngineInterface
Associate given clipid with a filename. Files are loaded from the resource path. Java 1.2+ supports at least: midi and wav files.

Specified by:
defineAudioClip in interface JGEngineInterface

lastPlayedAudio

public java.lang.String lastPlayedAudio(java.lang.String channel)
Description copied from interface: JGEngineInterface
Returns the audioclip that was last played, null if audio was stopped with stopAudio. Note the clip does not actually have to be playing; it might have finished playing already.

Specified by:
lastPlayedAudio in interface JGEngineInterface

playAudio

public void playAudio(java.lang.String clipid)
Description copied from interface: JGEngineInterface
Play audio clip on unnamed channel, which means it will not replace another clip, and cannot be stopped. The clip is not looped. When this method is called multiple times with the same sample within the same frame, it is played only once.

Specified by:
playAudio in interface JGEngineInterface

playAudio

public void playAudio(java.lang.String channel,
                      java.lang.String clipid,
                      boolean loop)
Description copied from interface: JGEngineInterface
Play clip on channel with given name. Will replace any other clip already playing on the channel. Will restart if the clip is already playing and either this call or the already playing one are not specified as looping. If both are looping, the looped sound will continue without restarting. If you want the looping sound to be restarted, call stopAudio first. Note the channel "music" is reserved for enabling/disabling music separately in future versions.

Specified by:
playAudio in interface JGEngineInterface

stopAudio

public void stopAudio(java.lang.String channel)
Description copied from interface: JGEngineInterface
Stop one audio channel.

Specified by:
stopAudio in interface JGEngineInterface

stopAudio

public void stopAudio()
Description copied from interface: JGEngineInterface
Stop all audio channels.

Specified by:
stopAudio in interface JGEngineInterface

storeWriteInt

public void storeWriteInt(java.lang.String id,
                          int value)
Description copied from interface: JGEngineInterface
Writes integer to store under given ID

Specified by:
storeWriteInt in interface JGEngineInterface

storeWriteDouble

public void storeWriteDouble(java.lang.String id,
                             double value)
Description copied from interface: JGEngineInterface
Writes double to store under given ID

Specified by:
storeWriteDouble in interface JGEngineInterface

storeWriteString

public void storeWriteString(java.lang.String id,
                             java.lang.String value)
Description copied from interface: JGEngineInterface
Writes string to store under given ID

Specified by:
storeWriteString in interface JGEngineInterface

storeRemove

public void storeRemove(java.lang.String id)
Description copied from interface: JGEngineInterface
Remove record if it exists

Specified by:
storeRemove in interface JGEngineInterface

storeExists

public boolean storeExists(java.lang.String id)
Description copied from interface: JGEngineInterface
Checks if item exists in store

Specified by:
storeExists in interface JGEngineInterface

storeReadInt

public int storeReadInt(java.lang.String id,
                        int undef)
Description copied from interface: JGEngineInterface
Reads int from store, use undef if ID not found

Specified by:
storeReadInt in interface JGEngineInterface

storeReadDouble

public double storeReadDouble(java.lang.String id,
                              double undef)
Description copied from interface: JGEngineInterface
Reads double from store, use undef if ID not found

Specified by:
storeReadDouble in interface JGEngineInterface

storeReadString

public java.lang.String storeReadString(java.lang.String id,
                                        java.lang.String undef)
Description copied from interface: JGEngineInterface
Reads String from store, use undef if ID not found

Specified by:
storeReadString in interface JGEngineInterface

optsAddTitle

public void optsAddTitle(java.lang.String title)
Description copied from interface: JGEngineInterface
Adds title to be displayed above subsequent items. Default title of initial items is "Preferences". Call this before defining any items to override the default title.

Specified by:
optsAddTitle in interface JGEngineInterface

optsAddNumber

public void optsAddNumber(java.lang.String varname,
                          java.lang.String title,
                          java.lang.String desc,
                          int decimals,
                          double lower,
                          double upper,
                          double step,
                          double initial)
Description copied from interface: JGEngineInterface
adds (int or float) number that can be configured with a slider. Type is double if decimals!=0, int otherwise.

Specified by:
optsAddNumber in interface JGEngineInterface
decimals - number is int if 0

optsAddBoolean

public void optsAddBoolean(java.lang.String varname,
                           java.lang.String title,
                           java.lang.String desc,
                           boolean initial)
Description copied from interface: JGEngineInterface
Adds boolean that can be configured with a checkbox. Actual type is int (0 or 1)

Specified by:
optsAddBoolean in interface JGEngineInterface

optsAddEnum

public void optsAddEnum(java.lang.String varname,
                        java.lang.String title,
                        java.lang.String desc,
                        java.lang.String[] values,
                        int initial)
Description copied from interface: JGEngineInterface
Adds enum that can be configured with radio buttons. Actual type is int, 0 for first item, 1 for second item, etc.

Specified by:
optsAddEnum in interface JGEngineInterface

optsAddKey

public void optsAddKey(java.lang.String varname,
                       java.lang.String title,
                       java.lang.String desc,
                       int initial)
Description copied from interface: JGEngineInterface
Adds "key" option that can be configured by selecting a key or button on the device. Actual type is int.

Specified by:
optsAddKey in interface JGEngineInterface

optsAddString

public void optsAddString(java.lang.String varname,
                          java.lang.String title,
                          java.lang.String desc,
                          int maxlen,
                          boolean isPassword,
                          java.lang.String initial)
Description copied from interface: JGEngineInterface
Adds String that can be configured by typing text.

Specified by:
optsAddString in interface JGEngineInterface

optsClear

public void optsClear()
Description copied from interface: JGEngineInterface
Clear all previous option definitions.

Specified by:
optsClear in interface JGEngineInterface