Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## examples
Class StdDungeonPlayer

    java.lang.Object
      jgame.JGObject
          examples.StdDungeonPlayer

    public class StdDungeonPlayer

extends JGObject

A standard object that allows the player to move in 8 directions around a tile-based dungeon, which may be maze-like or contain open spaces. Typical application: gauntlet, and a variety of others. The player moves in 8 directions along tile-aligned positions. It can be made to occupy a space on the tile map, blocking other objects. The occupation is automatically removed if the object is removed. It is assumed the object is 1x1 tile in size, and the tileBBox is set to this.

The public fields are the configuration fields which can be changed at will during the object's lifetime.

You can make movement stop by setting the stop_moving flag. The player will move on to the next aligned position, then halt until the flag is cleared. In some games, the player should stop when the movement keys are used for firing or doing actions.

This class only defines the move() method; hit() and hit_bg() are not used. Subclass it to customize. To customize move(), call super.move() somewhere inside your move method. While in general you shouldn't touch the object's position, direction, or speed in order to ensure correct behaviour, you can set any of the configuration variables in the move() method or somewhere else.

Field Summary
`int` | `block_mask` cid mask of tiles that block
`boolean` | `continuous_anim` don't stop animating when player stops moving
`java.lang.String` | `gfx_prefix` null indicates non-directional graphic
`int` | `key_down` Movement keys.
`int` | `key_left` Movement keys.
`int` | `key_right` Movement keys.
`int` | `key_up` Movement keys.
`int` | `occupy_mask` cid mask that object should use to indicate occupation
`boolean` | `stop_moving` Set to true to disable movement (for example, for firing).

Fields inherited from class jgame.JGObject
`colid, eng, expire_never, expire_off_pf, expire_off_view, expiry, gamespeed, is_suspended, pfheight, pfwidth, pfwrapx, pfwrapy, resume_in_view, suspend_off_view, suspend_off_view_expire_off_pf, tileheight, tilewidth, viewheight, viewwidth, viewxofs, viewyofs, x, xdir, xspeed, y, ydir, yspeed`

Constructor Summary
`StdDungeonPlayer(java.lang.String name, double x, double y, int cid, java.lang.String graphic, boolean is_directional, boolean continuous_anim, int block_mask, int occupy_mask, double speed, int key_up, int key_down, int key_left, int key_right)` When initialised, the object will snap to grid to the nearest free position.

Method Summary
`void` | `destroy()` Removes object and object's occupation.
`void` | `move()` Moves the object around, and ensures it occupies space.

Methods inherited from class jgame.JGObject
`and, checkBGCollision, checkBGCollision, checkCollision, clearAnim, clearBBox, clearTileBBox, dbgPrint, frameFinished, getAnimId, getBBox, getBBox, getCenterTile, getCenterTiles, getGraphic, getImageBBox, getImageBBoxConst, getImageName, getLastX, getLastY, getName, getTileBBox, getTileBBox, getTiles, getTopLeftTile, hit_bg, hit_bg, hit_bg, hit, isAligned, isAlive, isBottomAligned, isInView, isLeftAligned, isOnPF, isOnScreen, isRightAligned, isSuspended, isTopAligned, isXAligned, isXAligned, isYAligned, isYAligned, moduloPos, paint, remove, removeDone, resetAnim, resetAnim, resume, setAnim, setAnimPingpong, setAnimSpeed, setBBox, setDir, setDirSpeed, setDirSpeed, setEngine, setGraphic, setImage, setPos, setResumeMode, setSpeed, setSpeed, setSpeedAbs, setTileBBox, snapBBoxToGrid, snapToGrid, snapToGrid, startAnim, stopAnim, suspend, updateAnimation, updateEngineSettings`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### gfx_prefix

    public java.lang.String gfx_prefix

  null indicates non-directional graphic

### continuous_anim

    public boolean continuous_anim

  don't stop animating when player stops moving

### block_mask

    public int block_mask

  cid mask of tiles that block

### occupy_mask

    public int occupy_mask

  cid mask that object should use to indicate occupation

### key_up

    public int key_up

  Movement keys.

### key_down

    public int key_down

  Movement keys.

### key_left

    public int key_left

  Movement keys.

### key_right

    public int key_right

  Movement keys.

### stop_moving

    public boolean stop_moving

  Set to true to disable movement (for example, for firing).

Constructor Detail

### StdDungeonPlayer

    public StdDungeonPlayer(java.lang.String name,
                            double x,
                            double y,
                            int cid,
                            java.lang.String graphic,
                            boolean is_directional,
                            boolean continuous_anim,
                            int block_mask,
                            int occupy_mask,
                            double speed,
                            int key_up,
                            int key_down,
                            int key_left,
                            int key_right)

  When initialised, the object will snap to grid to the nearest free position. The object's graphic can be made directional by setting is_directional. This will add the suffix "ul", "u", "ur", "dl", "d", "dr", "l", or "r" to the graphic string to indicate the direction of movement. It is possible to define keys for the diagonal directions, but you can pass 0 as keycode if you don't want this.

  Parameters:
    `x` - position in pixels
    `y` - position in pixels
    `graphic` - prefix of graphic
    `is_directional` - true = add direction suffix to graphic
    `continuous_anim` - don't stop animating when player stops moving
    `block_mask` - cid mask of tiles that block
    `occupy_mask` - cid mask that object should use to indicate occupation

Method Detail

### move

    public void move()

  Moves the object around, and ensures it occupies space. If you override this, be sure to call super.move() and don't touch x, y, xspeed, yspeed, xdir, ydir.

  Overrides:
    `move` in class `JGObject`

### destroy

    public void destroy()

  Removes object and object's occupation.

  Overrides:
    `destroy` in class `JGObject`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD