examples
Class StdDungeonMonster

java.lang.Object
  extended byjgame.JGObject
      extended byexamples.StdDungeonMonster

public class StdDungeonMonster
extends JGObject

A standard monster object that can 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 monster 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.

The object homes in on the specified home_in object, or can be made to avoid it. The object can be made to move randomly instead of homing in/ avoiding, with a specified probability between 0 and 1. Not setting home_in will make the object move randomly.

The object can be made stationary by passing speed=0 or using the short constructor. This can be used for objects that don't move but do occupy space and otherwise act very much like tiles (i.e. "active tiles").

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
 boolean avoid
          true = avoid home_in position
 int block_mask
          cid mask of tiles that block
 boolean continuous_anim
          don't stop animating when monster stops moving
 java.lang.String gfx_prefix
          Prefix to use for directional animation; null indicates non-directional graphic
 JGObject home_in
          object to home in on, null=none (random movement)
 int occupy_mask
          cid mask that object should use to indicate occupation
 double random_proportion
          chance that object moves randomly
 
Fields inherited from class jgame.JGObject
colid, eng, expire_never, expire_off_pf, expire_off_view, expiry, resume_in_view, suspend_off_view, suspend_off_view_expire_off_pf, x, xdir, xspeed, y, ydir, yspeed
 
Constructor Summary
StdDungeonMonster(java.lang.String name, boolean unique_id, double x, double y, int cid, java.lang.String graphic, boolean is_directional, boolean continuous_anim, int block_mask, int occupy_mask, double speed, JGObject home_in, boolean avoid, double random_proportion)
          When initialised, the object will snap to grid to the nearest free position, then it will start moving in the direction specified by home_in, random_proportion.
StdDungeonMonster(java.lang.String name, boolean unique_id, double x, double y, int cid, java.lang.String graphic, int occupy_mask)
          Create static monster that just occupies space.
 
Method Summary
static void checkIfBlocked(JGObject o, int block_mask, int prevxdir, int prevydir)
          Check if we aren't blocked in the xdir,ydir direction we're currently going, and change direction if we're partially blocked.
 void move()
          Moves the object around, and ensures it occupies space.
 void remove()
          Removes object and object's occupation.
 
Methods inherited from class jgame.JGObject
and, checkBGCollision, checkBGCollision, clearAnim, clearBBox, clearTileBBox, dbgPrint, getAnimId, getBBox, getCenterTile, getCenterTiles, getGraphic, getImageBBox, getLastBBox, getLastCenterTiles, getLastTileBBox, getLastTiles, getLastX, getLastY, getName, getTileBBox, getTiles, getTopLeftTile, hit_bg, hit_bg, hit_bg, hit, isAlive, isBottomAligned, isInView, isLeftAligned, isOnPF, isOnScreen, isRightAligned, isSuspended, isTopAligned, isXAligned, isXAligned, isYAligned, isYAligned, paint, resetAnim, resetAnim, resume, setAnim, setAnimPingpong, setAnimSpeed, setBBox, setDir, setDirSpeed, setDirSpeed, setGraphic, setImage, setPos, setResumeMode, setSpeed, setSpeed, setSpeedAbs, setTileBBox, snapBBoxToGrid, snapToGrid, snapToGrid, startAnim, stopAnim, suspend
 
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
Prefix to use for directional animation; null indicates non-directional graphic


continuous_anim

public boolean continuous_anim
don't stop animating when monster 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


home_in

public JGObject home_in
object to home in on, null=none (random movement)


avoid

public boolean avoid
true = avoid home_in position


random_proportion

public double random_proportion
chance that object moves randomly

Constructor Detail

StdDungeonMonster

public StdDungeonMonster(java.lang.String name,
                         boolean unique_id,
                         double x,
                         double y,
                         int cid,
                         java.lang.String graphic,
                         boolean is_directional,
                         boolean continuous_anim,
                         int block_mask,
                         int occupy_mask,
                         double speed,
                         JGObject home_in,
                         boolean avoid,
                         double random_proportion)
When initialised, the object will snap to grid to the nearest free position, then it will start moving in the direction specified by home_in, random_proportion. 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 - graphic, and prefix of directional graphic if directional
is_directional - true = add direction suffix to graphic
continuous_anim - don't stop animating when monster stops moving
block_mask - cid mask of tiles that block
occupy_mask - cid mask that object should use to indicate occupation
speed - 0 = stationary object
home_in - object to home in on, null=none (random movement)
avoid - true = avoid home_in position
random_proportion - chance that object moves randomly

StdDungeonMonster

public StdDungeonMonster(java.lang.String name,
                         boolean unique_id,
                         double x,
                         double y,
                         int cid,
                         java.lang.String graphic,
                         int occupy_mask)
Create static monster that just occupies space.

Parameters:
x - position in pixels
y - position in pixels
graphic - graphic to use
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

remove

public void remove()
Removes object and object's occupation.

Overrides:
remove in class JGObject

checkIfBlocked

public static void checkIfBlocked(JGObject o,
                                  int block_mask,
                                  int prevxdir,
                                  int prevydir)
Check if we aren't blocked in the xdir,ydir direction we're currently going, and change direction if we're partially blocked. This is a static method that can be applied to any JGObject. It modifies the xdir and ydir appropriately.

Parameters:
prevxdir - direction we were going previously (such as, last frame)
prevydir - direction we were going previously (such as, last frame)