|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
jgame.JGEngine
Contains the main functionality of the game engine. Subclass it to write your own game. The engine can be run as both an applet and an application. To run as an application, have your main() construct an instance of your subclass. Then call initEngine(), which will open a window, and initialise. To run as an applet, ensure that your subclass has a parameterless constructor which enables the applet viewer to create it as an applet. Within this constructor, you call initEngineApplet() to initialise.
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. 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.
The engine manages a list of sprite objects, and a matrix of equal-sized tiles. Its primary way to draw graphics is images. Images may be loaded from Gifs, JPegs, or PNGs (PNGs not in java 1.2), which may contain either single images, or regularly spaced arrays or matrices of images (i.e. sprite sheets, we will call them image maps). An image is identified by a unique name, and is defined by the image file it comes from, the index within that file in case the file is an image map, and any flip and rotate actions that are to be be done on the file image to arrive at the final image. Animations may be defined in terms of sequences of images. Image maps, images, and animations can be defined by calling resp. defineImageMap, defineImage, or defineAnimation, or the definitions can be loaded from a text-file table file using defineImages().
Objects are of the class JGObject; see this class for more information. Objects are identified within the engine by unique String identifiers. Creating a new object with the same identifier as an old object will replace the old one. Objects are drawn on the screen in lexical order. The main methods for handling objects are moveObjects(), checkCollision(), and checkBGCollision().
Tiles can be used to define a background that the sprite objects can interact with, using a set of shorthands for reading, writing, and colliding with tiles. Tiles are uniquely identified by a short string (1-4 characters). Tiles may be transparent; a decorative background image can be displayed behind the tiles.
Collision is done by assigning collision IDs (cids) to both objects and tiles. A cid is basically a bit string (usually, one allocates 1 bit per basic object or tile type). Collision is done by specifying that a certain set of object types should be notified of collision with a certain set of object or tile types. Such a set is specified by a bit mask, which matches a cid when cid&mask != 0. JGObject defines collision methods (hit and hit_bg) which can then be implemented to handle the collisions. Objects have two bounding boxes: one for object-object collision (the sprite bounding box, or simply bounding box), and one for object-tile collision (the tile bounding box). The two bounding boxes may be dependent on the image (typically, you want these bounding boxes to approximate the shape of each individual image). For this purpose, you can define a collision bounding box with each image definition. This image bounding box is the default bounding box used by the object, but both sprite bbox and tile bbox can be overridden separately. Often, you want to set the tile bbox to a constant value, such as equal to the size of 1 tile.
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. The scale factor will in no way affect the behaviour of the game (except performance-wise), but the graphics may look a bit blocky or jaggy, as 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.
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.
Field Summary | |
static int |
KeyAlt
|
static int |
KeyCtrl
|
static int |
KeyDown
Keycode of cursor key. |
static int |
KeyLeft
Keycode of cursor key. |
static int |
KeyMouse1
Keymap equivalent of mouse button. |
static int |
KeyMouse2
Keymap equivalent of mouse button. |
static int |
KeyMouse3
Keymap equivalent of mouse button. |
static int |
KeyRight
Keycode of cursor key. |
static int |
KeyShift
|
static int |
KeyUp
Keycode of cursor key. |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
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 |
andBGTileCid(int x,
int y,
int and_mask)
Modify the cid of a single tile by ORing a bit mask, leaving the actual tile. |
void |
checkBGCollision(int tilecid,
int objcid)
Calls all bg colliders of objects that match objid that collide with tiles that match tileid. |
int |
checkBGCollision(java.awt.Rectangle 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 dstid that collide with objects that match srcid. |
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 |
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 |
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. |
static void |
dbgSetBoundingBox(boolean enabled)
Show bounding boxes around the objects: the image bounding box (getBBox) , the tile span (getTiles), and the center tiles (getCenterTiles). |
void |
dbgSetDebugColor1(java.awt.Color col)
Set debug color 1, used for printing debug information. |
void |
dbgSetDebugColor2(java.awt.Color col)
Set debug color 2, used for printing debug information. |
static void |
dbgSetFullStackTrace(boolean enabled)
Indicates whether to show full exception stack traces or just the first lines. |
static void |
dbgSetGameStateDisplay(boolean enabled)
Show the game state in the bottom right corner of the screen. |
void |
dbgSetMessageExpiry(int ticks)
Set the number of frames a debug message of a removed object should remain on the playfield. |
void |
dbgSetMessageFont(java.awt.Font font)
Set the font for displaying debug messages. |
void |
dbgSetMessagesInPf(boolean enabled)
Output messages on playfield instead of console. |
void |
dbgShowException(java.lang.String source,
java.lang.Throwable e)
Print the relevant information of an exception as a debug message. |
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 |
defineGraphics(java.lang.String filename)
Load a set of imagemap, image, and animation definitions from a file. |
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 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 imgfile,
java.lang.String img_op,
int top,
int left,
int width,
int height)
Define new sprite/tile image. |
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 |
destroy()
Destroy function for deinitialising the engine properly. |
void |
doFrame()
Is called every frame. |
void |
drawImage(int x,
int y,
java.lang.String imgname)
Draw image with given ID. |
void |
drawImageString(java.lang.String string,
int x,
int 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 |
drawLine(int x1,
int y1,
int x2,
int y2)
|
void |
drawLine(int x1,
int y1,
int x2,
int y2,
double thickness,
java.awt.Color color)
|
void |
drawOval(int x,
int y,
int width,
int height,
boolean filled,
boolean centered)
|
void |
drawOval(int x,
int y,
int width,
int height,
boolean filled,
boolean centered,
double thickness,
java.awt.Color color)
|
void |
drawRect(int x,
int y,
int width,
int height,
boolean filled,
boolean centered)
|
void |
drawRect(int x,
int y,
int width,
int height,
boolean filled,
boolean centered,
double thickness,
java.awt.Color color)
|
void |
drawString(java.lang.String str,
int x,
int 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,
int x,
int y,
int align,
java.awt.Font font,
java.awt.Color 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). |
boolean |
existsObject(java.lang.String index)
Check if object exists. |
void |
exitEngine(java.lang.String msg)
Report an exit message and exit; use for fatal errors. |
void |
fillBG(java.lang.String filltilename)
Fill the background with the given tile. |
int |
getBGTileCid(int xidx,
int yidx)
Get collision id of tile at given tile index position. |
int |
getBGTileCid(java.awt.Point center,
int xofs,
int yofs)
Get the tile cid of the point that is (xofs,yofs) from the tile index coordinate center. |
int |
getBGTileCid(java.awt.Rectangle tiler)
Get the OR of the cids at the tile indexes given by tiler |
int |
getBGTileCidAtCoord(double x,
double y)
Get collision id of the tile at given pixel coordinates. |
java.lang.String |
getBGTileStr(int xidx,
int yidx)
get string id of tile at given index position |
java.lang.String |
getBGTileStr(java.awt.Point 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 |
getBGTileStrAtCoord(double x,
double y)
Get collision Id of the tile at given pixel coordinates. |
java.awt.Graphics |
getBufferGraphics()
Get the graphics context for drawing on the buffer during a paintFrame(). |
double |
getFontHeight(java.awt.Font font)
Get height of given font in pixels. |
java.awt.Image |
getImage(java.lang.String imgname)
Gets (scaled) image directly. |
java.awt.Rectangle |
getImageBBox(java.lang.String imgname)
Gets the collision bounding box of an image. |
java.awt.Dimension |
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. |
java.lang.String |
getKeyDesc(int key)
Get a printable string describing the key. |
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 |
java.awt.Point |
getMousePos()
Get current mouse position |
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.awt.Point |
getTileCoord(int tilex,
int tiley)
Get pixel coordinate corresponding to the top left of the tile at the given index |
java.awt.Point |
getTileCoord(java.awt.Point tileidx)
Get pixel coordinate corresponding to the top left of the tile at the given index |
java.awt.Point |
getTileIndex(double x,
double y)
Get tile index of the tile the coordinate is on. |
java.awt.Rectangle |
getTiles(java.awt.Rectangle r)
Get tile index range of all tiles overlapping given rectangle of pixel coordinates. |
double |
getXAlignOfs(double x)
Returns the difference between position and the closest tile-aligned position. |
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 |
getYScaleFactor()
Get scale factor of real screen height wrt virtual screen height |
boolean |
inGameState(java.lang.String state)
Check if game is in given state. |
boolean |
inGameStateNextFrame(java.lang.String state)
Check if game will be in given state the next frame. |
void |
init()
Initialise engine; don't call directly. |
void |
initEngine(int nrtilesx,
int nrtilesy,
int tilex,
int tiley,
java.awt.Color fgcolor,
java.awt.Color bgcolor,
java.awt.Font msgfont,
int width,
int height)
Init engine as application. |
void |
initEngineApplet(int nrtilesx,
int nrtilesy,
int tilex,
int tiley,
java.awt.Color fgcolor,
java.awt.Color bgcolor,
java.awt.Font msgfont)
Init engine as applet; call this in your engine constructor. |
abstract void |
initGame()
Override to define your own initialisations. |
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. |
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 |
orBGTileCid(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. |
int |
pfHeight()
Get the virtual height in pixels (not the scaled screen height) |
int |
pfTileHeight()
Get the tile height in (virtual) pixels. |
int |
pfTilesX()
Get the number of tiles in X direction |
int |
pfTilesY()
Get the number of tiles in Y direction |
int |
pfTileWidth()
Get the tile width in (virtual) pixels. |
int |
pfWidth()
Get the virtual width in pixels (not the scaled screen width) |
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 |
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 |
removeObjects(java.lang.String prefix,
int cidmask)
Remove all objects which have the given name prefix and/or match the given cidmask. |
void |
setBGColor(java.awt.Color bgcolor)
Set global background colour, which is displayed in borders, and behind transparent tiles if no BGImage is defined. |
void |
setBGImage(java.lang.String bgimg)
Set image to display behind transparent tiles. |
void |
setBGTile(int x,
int y,
java.lang.String tilename)
Set a single tile. |
void |
setBGTile(java.awt.Point tileidx,
java.lang.String tilename)
Set a single tile. |
void |
setBGTileCid(int x,
int y,
int value)
Set the cid of a single tile to the given value, leaving the actual tile. |
void |
setBGTiles(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 |
setBGTileSettings(java.lang.String out_of_bounds_tile,
int out_of_bounds_cid,
int preserve_cids)
Define background tile settings. |
void |
setBGTilesMulti(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 |
setColor(java.awt.Color col)
Set current drawing colour. |
void |
setColorsFont(java.awt.Color fgcolor,
java.awt.Color bgcolor,
java.awt.Font msgfont)
Set foreground and background colour, and message font in one go; passing a null means ignore that argument. |
void |
setCursor(java.awt.Cursor cursor)
Set mouse cursor, null means hide cursor |
void |
setFGColor(java.awt.Color fgcolor)
Set global foreground colour, used for printing text and status messages. |
void |
setFont(java.awt.Font font)
Set current font, scale the font to screen size. |
void |
setFont(java.awt.Graphics g,
java.awt.Font 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 |
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 |
setMsgFont(java.awt.Font msgfont)
Set the (unscaled) message font, used for displaying status messages. |
void |
setRenderSettings(int alpha_thresh,
java.awt.Color render_bg_col)
Configure image rendering. |
void |
setStroke(double thickness)
Set the line thickness |
void |
snapToGrid(java.awt.Point 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 |
startAllAnim()
Start automatic animation in case it was stopped. |
void |
stop()
signal that the engine should stop running and wait. |
void |
stopAllAnim()
Stop automatic animation of all objects. |
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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int KeyUp
public static final int KeyDown
public static final int KeyLeft
public static final int KeyRight
public static final int KeyShift
public static final int KeyCtrl
public static final int KeyAlt
public static final int KeyMouse1
public static final int KeyMouse2
public static final int KeyMouse3
Constructor Detail |
public JGEngine()
Method Detail |
public static void dbgSetBoundingBox(boolean enabled)
public static void dbgSetGameStateDisplay(boolean enabled)
public static void dbgSetFullStackTrace(boolean enabled)
public void dbgSetMessagesInPf(boolean enabled)
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.
public void dbgSetMessageExpiry(int ticks)
public void dbgSetMessageFont(java.awt.Font font)
public void dbgSetDebugColor1(java.awt.Color col)
public void dbgSetDebugColor2(java.awt.Color col)
public void dbgPrint(java.lang.String msg)
public void dbgPrint(java.lang.String source, java.lang.String msg)
source
- may be object ID or "MAIN" for the main program.public void dbgShowException(java.lang.String source, java.lang.Throwable e)
source
- may be object ID or "MAIN" for the main program.public java.lang.String dbgExceptionToString(java.lang.Throwable e)
public void exitEngine(java.lang.String msg)
public void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed)
id
- the name by which the animation is knownframes
- an array of image names that should be played in sequencespeed
- the sequence speed: the number of animation steps per framepublic void defineAnimation(java.lang.String id, java.lang.String[] frames, double speed, boolean pingpong)
id
- the name by which the animation is knownframes
- an array of image names that should be played in sequencespeed
- the sequence speed: the number of animation steps per framepingpong
- true=play the images in forward order, then in reversepublic void initEngineApplet(int nrtilesx, int nrtilesy, int tilex, int tiley, java.awt.Color fgcolor, java.awt.Color bgcolor, java.awt.Font msgfont)
nrtilesx
- nr of tiles horizontallynrtilesy
- nr of tiles verticallytilex
- width of one tiletiley
- height of one tilefgcolor
- pen/text colour, null for default whitebgcolor
- background colour, null for default blackmsgfont
- font for messages and text drawing, null for defaultpublic void initEngine(int nrtilesx, int nrtilesy, int tilex, int tiley, java.awt.Color fgcolor, java.awt.Color bgcolor, java.awt.Font msgfont, int width, int height)
nrtilesx
- nr of tiles horizontallynrtilesy
- nr of tiles verticallytilex
- width of one tiletiley
- height of one tilefgcolor
- pen/text colour, null for default whitebgcolor
- background colour, null for default blackmsgfont
- font for messages and text drawing, null for defaultwidth
- real screen width, 0 = use screen sizeheight
- real screen height, 0 = use screen sizepublic int pfWidth()
public int pfHeight()
public int pfTilesX()
public int pfTilesY()
public int pfTileWidth()
public int pfTileHeight()
public void init()
public abstract void initGame()
public void start()
public void stop()
public void wakeUpOnKey(int key)
key
- keycode to wake up on, -1=any key or mouse, 0=nonepublic void destroy()
public void setFrameRate(double fps, double maxframeskip)
fps
- frames per second, useful range 2...80maxframeskip
- max successive frames to skip, useful range 0..10public void setRenderSettings(int alpha_thresh, java.awt.Color render_bg_col)
alpha_thresh
- bitmask threshold, 0...255, default=128render_bg_col
- bg colour for render, null=use background colourpublic void setBGColor(java.awt.Color bgcolor)
public void setBGImage(java.lang.String bgimg)
bgimg
- image name, null=turn off background imagepublic void setFGColor(java.awt.Color fgcolor)
public void setMsgFont(java.awt.Font msgfont)
public void setColorsFont(java.awt.Color fgcolor, java.awt.Color bgcolor, java.awt.Font msgfont)
public void setCursor(java.awt.Cursor cursor)
public void removeAllTimers()
public void setGameState(java.lang.String state)
public void addGameState(java.lang.String state)
public void removeGameState(java.lang.String state)
public void clearGameState()
public boolean inGameState(java.lang.String state)
public boolean inGameStateNextFrame(java.lang.String state)
public void doFrame()
public void paintFrame()
public java.awt.Graphics getBufferGraphics()
public double getXScaleFactor()
public double getYScaleFactor()
public double getMinScaleFactor()
public void setColor(java.awt.Color col)
public void setFont(java.awt.Font font)
public void setFont(java.awt.Graphics g, java.awt.Font font)
public void setStroke(double thickness)
public void drawLine(int x1, int y1, int x2, int y2, double thickness, java.awt.Color color)
public void drawLine(int x1, int y1, int x2, int y2)
public void drawRect(int x, int y, int width, int height, boolean filled, boolean centered, double thickness, java.awt.Color color)
centered
- indicates (x,y) is center instead of topleft.public void drawRect(int x, int y, int width, int height, boolean filled, boolean centered)
centered
- indicates (x,y) is center instead of topleft.public void drawOval(int x, int y, int width, int height, boolean filled, boolean centered, double thickness, java.awt.Color color)
centered
- indicates (x,y) is center instead of topleft.public void drawOval(int x, int y, int width, int height, boolean filled, boolean centered)
centered
- indicates (x,y) is center instead of topleft.public void drawImage(int x, int y, java.lang.String imgname)
public void drawString(java.lang.String str, int x, int y, int align)
align
- text alignment, -1=left, 0=center, 1=rightpublic void drawString(java.lang.String str, int x, int y, int align, java.awt.Font font, java.awt.Color color)
align
- text alignment, -1=left, 0=center, 1=rightpublic double getFontHeight(java.awt.Font font)
public void drawImageString(java.lang.String string, int x, int y, int align, java.lang.String imgmap, int char_offset, int spacing)
align
- text alignment, -1=left, 0=center, 1=rightimgmap
- name of image mapchar_offset
- ASCII code of first image of image mapspacing
- number of pixels to skip between letterspublic java.awt.Point getMousePos()
public int getMouseX()
public int getMouseY()
public boolean getMouseButton(int nr)
nr
- 1=button 1 ... 3 = button 3
public void clearMouseButton(int nr)
nr
- 1=button 1 ... 3 = button 3public void setMouseButton(int nr)
nr
- 1=button 1 ... 3 = button 3public boolean getMouseInside()
public boolean getKey(int key)
public void clearKey(int key)
public void setKey(int key)
public java.lang.String getKeyDesc(int key)
public void defineImageMap(java.lang.String mapname, java.lang.String imgfile, int xofs, int yofs, int tilex, int tiley, int skipx, int skipy)
mapname
- id of image mapimgfile
- filespec relative to baseurlxofs
- x offset of first imageyofs
- y offset of first imagetilex
- width of an imagetiley
- height of an imageskipx
- nr of pixels to skip between successive imagesskipy
- nr of pixels to skip between successive images vertically.public void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op, int top, int left, int width, int height)
imgname
- image idtilename
- tile id (1-4 characters)collisionid
- cid to use for tile collision matchingimgfile
- filespec relative to baseurl; "null" means no filetop
- collision bounding box dimensionsleft
- collision bounding box dimensionswidth
- collision bounding box dimensionsheight
- collision bounding box dimensionspublic void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgfile, java.lang.String img_op)
imgname
- image idtilename
- tile id (1-4 characters)collisionid
- cid to use for tile collision matchingimgfile
- filespec relative to baseurl; "null" means no filepublic 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)
imgname
- image idtilename
- tile id (1-4 characters)collisionid
- cid to use for tile collision matchingimgmap
- id of image mapmapidx
- index of image in map, 0=firsttop
- collision bounding box dimensionsleft
- collision bounding box dimensionswidth
- collision bounding box dimensionsheight
- collision bounding box dimensionspublic void defineImage(java.lang.String imgname, java.lang.String tilename, int collisionid, java.lang.String imgmap, int mapidx, java.lang.String img_op)
imgname
- image idtilename
- tile id (1-4 characters)collisionid
- cid to use for tile collision matchingimgmap
- id of image mapmapidx
- index of image in map, 0=firstpublic void defineGraphics(java.lang.String filename)
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
public java.awt.Image getImage(java.lang.String imgname)
public java.awt.Dimension getImageSize(java.lang.String imgname)
public java.awt.Rectangle getImageBBox(java.lang.String imgname)
public void setBGTileSettings(java.lang.String out_of_bounds_tile, int out_of_bounds_cid, int preserve_cids)
out_of_bounds_tile
- tile string to use outside of screen boundsout_of_bounds_cid
- cid to use outside of screen boundariespreserve_cids
- cid mask to preserve when setting tilespublic void fillBG(java.lang.String filltilename)
filltilename
- null means use background colourpublic void setBGTileCid(int x, int y, int value)
public void orBGTileCid(int x, int y, int or_mask)
public void andBGTileCid(int x, int y, int and_mask)
public void setBGTile(int x, int y, java.lang.String tilename)
public void setBGTile(java.awt.Point tileidx, java.lang.String tilename)
public void setBGTiles(int xofs, int yofs, java.lang.String[] tilemap)
public void setBGTilesMulti(int xofs, int yofs, java.lang.String[] tilemap)
"x aa ab abc"
stands for a sequence of four tiles, "x",
"aa", "ab", and "abc".
public int getBGTileCidAtCoord(double x, double y)
public int getBGTileCid(int xidx, int yidx)
public int getBGTileCid(java.awt.Point center, int xofs, int yofs)
public java.lang.String getBGTileStrAtCoord(double x, double y)
public java.lang.String getBGTileStr(int xidx, int yidx)
public java.lang.String getBGTileStr(java.awt.Point center, int xofs, int yofs)
public int getBGTileCid(java.awt.Rectangle tiler)
public int countTiles(int tilecidmask)
public boolean existsObject(java.lang.String index)
public JGObject getObject(java.lang.String index)
public void removeObjects(java.lang.String prefix, int cidmask)
cidmask
- collision id mask, 0 means ignoreprefix
- ID prefix, null means ignorepublic int countObjects(java.lang.String prefix, int cidmask)
cidmask
- collision id mask, 0 means ignoreprefix
- ID prefix, null means ignorepublic void moveObjects(java.lang.String prefix, int cidmask)
cidmask
- collision id mask, 0 means ignoreprefix
- ID prefix, null means ignorepublic void moveObjects()
public void startAllAnim()
public void stopAllAnim()
public void checkCollision(int srccid, int dstcid)
public int checkBGCollision(java.awt.Rectangle r)
public void checkBGCollision(int tilecid, int objcid)
public boolean and(int value, int mask)
public double random(double min, double max)
public double random(double min, double max, double interval)
public int random(int min, int max, int interval)
public java.awt.Rectangle getTiles(java.awt.Rectangle r)
public java.awt.Point getTileIndex(double x, double y)
public java.awt.Point getTileCoord(int tilex, int tiley)
public java.awt.Point getTileCoord(java.awt.Point tileidx)
public double snapToGridX(double x, double gridsnapx)
x
- position to snapgridsnapx
- snap margin, 0.0 means no snappublic double snapToGridY(double y, double gridsnapy)
public void snapToGrid(java.awt.Point p, int gridsnapx, int gridsnapy)
public boolean isXAligned(double x, double margin)
public boolean isYAligned(double y, double margin)
public double getXAlignOfs(double x)
public double getYAlignOfs(double y)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |