|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjgame.JGObject
examples.StdMazeMonster
public class StdMazeMonster
A standard object that moves around a maze. Typical application: pac-man. This class only defines the move() method; hit() and hit_bg() are not used. Subclass it to customize. To customize move(), simply call super.move() somewhere inside your move method. Note that this class's move() works by determining the appropriate xdir and ydir. You can do some limited operations on xdir and ydir before calling super.move(). In particular, reversing direction can be done without problems. 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 tries to keep moving forward, and never make u-turns (like pac-man ghosts) to help get it around cul de sacs. There is no AI for finding complex routes through the maze.
Field Summary | |
---|---|
boolean |
avoid
true = avoid home_in position |
int |
block_mask
cid mask of tiles that block |
java.lang.String |
gfx_prefix
null indicates non-directional graphic |
JGObject |
home_in
object to home in on, null=none (random movement) |
double |
random_proportion
chance that object moves randomly |
double |
speed
object's speed, overrides xspeed, yspeed. |
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 | |
---|---|
StdMazeMonster(java.lang.String name,
boolean unique_id,
double x,
double y,
int cid,
java.lang.String graphic,
boolean is_directional,
int block_mask,
int xdir,
int ydir,
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 xdir, ydir. |
Method Summary | |
---|---|
void |
move()
Moves the object around. |
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, remove, 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 int block_mask
public double speed
public JGObject home_in
public boolean avoid
public double random_proportion
Constructor Detail |
---|
public StdMazeMonster(java.lang.String name, boolean unique_id, double x, double y, int cid, java.lang.String graphic, boolean is_directional, int block_mask, int xdir, int ydir, double speed, JGObject home_in, boolean avoid, double random_proportion)
x
- position in pixelsy
- position in pixelsgraphic
- prefix of graphicis_directional
- add direction suffix to graphichome_in
- object to home in on, null=none (random movement)avoid
- true = avoid home_in positionrandom_proportion
- chance that object moves randomlyblock_mask
- cid mask of tiles that blockMethod Detail |
---|
public void move()
move
in class JGObject
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |