|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjgame.JGObject
examples.StdDungeonMonster
public class StdDungeonMonster
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 |
---|
public java.lang.String gfx_prefix
public boolean continuous_anim
public int block_mask
public int occupy_mask
public JGObject home_in
public boolean avoid
public double random_proportion
Constructor Detail |
---|
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)
x
- position in pixelsy
- position in pixelsgraphic
- graphic, and prefix of directional graphic if directionalis_directional
- true = add direction suffix to graphiccontinuous_anim
- don't stop animating when monster stops movingblock_mask
- cid mask of tiles that blockoccupy_mask
- cid mask that object should use to indicate occupationspeed
- 0 = stationary objecthome_in
- object to home in on, null=none (random movement)avoid
- true = avoid home_in positionrandom_proportion
- chance that object moves randomlypublic StdDungeonMonster(java.lang.String name, boolean unique_id, double x, double y, int cid, java.lang.String graphic, int occupy_mask)
x
- position in pixelsy
- position in pixelsgraphic
- graphic to useoccupy_mask
- cid mask that object should use to indicate occupationMethod Detail |
---|
public void move()
move
in class JGObject
public void remove()
remove
in class JGObject
public static void checkIfBlocked(JGObject o, int block_mask, int prevxdir, int prevydir)
prevxdir
- direction we were going previously (such as, last frame)prevydir
- direction we were going previously (such as, last frame)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |