Renamed MobileSprite to AmbulatorySprite and fixed up to face the
proper direction while following a path. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@153 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
//
|
||||
// $Id: MobileSprite.java,v 1.3 2001/08/02 00:42:02 shaper Exp $
|
||||
|
||||
package com.threerings.miso.sprite;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
import com.threerings.miso.tile.TileManager;
|
||||
|
||||
/**
|
||||
* A MobileSprite is a sprite that can face in one of eight compass
|
||||
* directions and that can be animated moving from one location to
|
||||
* another (e.g., a human's legs move and arms swing.)
|
||||
*/
|
||||
public class MobileSprite extends Sprite
|
||||
{
|
||||
/**
|
||||
* Construct a MobileSprite object, loading the tiles used to
|
||||
* display the sprite from specified tileset via the given tile
|
||||
* manager.
|
||||
*
|
||||
* @param x the sprite x-position in pixels.
|
||||
* @param y the sprite y-position in pixels.
|
||||
* @param tilemgr the tile manager to retrieve tiles from.
|
||||
* @param tsid the tileset id containing the sprite tiles.
|
||||
*/
|
||||
public MobileSprite (SpriteManager spritemgr, int x, int y,
|
||||
TileManager tilemgr, int tsid)
|
||||
{
|
||||
super(spritemgr, x, y);
|
||||
|
||||
_charTiles = getTiles(tilemgr, tsid);
|
||||
_dir = Path.DIR_SOUTH;
|
||||
|
||||
setTiles(_charTiles[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a two-dimensional array of tiles corresponding to the
|
||||
* frames of animation used to render the mobile sprite in each of
|
||||
* the directions it may face. The tileset id referenced must
|
||||
* contain <code>Path.NUM_DIRECTIONS</code> rows of tiles, with each
|
||||
* row containing <code>NUM_DIR_FRAMES</code> tiles.
|
||||
*
|
||||
* @param tilemgr the tile manager to retrieve tiles from.
|
||||
* @param tsid the tileset id containing the sprite tiles.
|
||||
*
|
||||
* @return the two-dimensional array of sprite tiles.
|
||||
*/
|
||||
protected Tile[][] getTiles (TileManager tilemgr, int tsid)
|
||||
{
|
||||
Tile[][] tiles =
|
||||
new Tile[Path.NUM_DIRECTIONS][NUM_DIR_FRAMES];
|
||||
|
||||
for (int ii = 0; ii < Path.NUM_DIRECTIONS; ii++) {
|
||||
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
|
||||
int idx = (ii * NUM_DIR_FRAMES) + jj;
|
||||
tiles[ii][jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the sprite's direction to reflect the direction the
|
||||
* destination point lies in before calling the superclass's
|
||||
* <code>setDestination</code> method.
|
||||
*
|
||||
* @param x the destination x-position.
|
||||
* @param y the destination y-position.
|
||||
*/
|
||||
public void setDestination (int x, int y)
|
||||
{
|
||||
// update the sprite tiles to reflect the direction
|
||||
setTiles(_charTiles[_dir = getDirection(x, y)]);
|
||||
|
||||
// call superclass to effect the beginnings of the move
|
||||
super.setDestination(x, y);
|
||||
|
||||
if (_state == STATE_MOVING) {
|
||||
setAnimationDelay(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the directional constant corresponding to the direction
|
||||
* the specified point is in from the sprite.
|
||||
*/
|
||||
protected int getDirection (int x, int y)
|
||||
{
|
||||
if (x >= this.x - DIR_BUFFER && x <= this.x + DIR_BUFFER) {
|
||||
return (y < this.y) ? Path.DIR_NORTH : Path.DIR_SOUTH;
|
||||
|
||||
} else if (y >= this.y - DIR_BUFFER && y <= this.y + DIR_BUFFER) {
|
||||
return (x >= this.x) ? Path.DIR_EAST : Path.DIR_WEST;
|
||||
|
||||
} else if (x > this.x) {
|
||||
return (y < this.y) ? Path.DIR_NORTHEAST : Path.DIR_SOUTHEAST;
|
||||
|
||||
} else {
|
||||
return (y < this.y) ? Path.DIR_NORTHWEST : Path.DIR_SOUTHWEST;
|
||||
}
|
||||
}
|
||||
|
||||
/** The number of frames of animation for each direction. */
|
||||
protected static final int NUM_DIR_FRAMES = 8;
|
||||
|
||||
/**
|
||||
* The buffer space in pixels allowed for horizontal or vertical
|
||||
* selection of movement north/south or east/west, respectively.
|
||||
*/
|
||||
protected static final int DIR_BUFFER = 20;
|
||||
|
||||
/** The animation frames for the sprite facing each direction. */
|
||||
protected Tile[][] _charTiles;
|
||||
|
||||
/** The direction the sprite is currently facing. */
|
||||
protected int _dir;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LineSegmentPath.java,v 1.2 2001/08/02 20:43:03 shaper Exp $
|
||||
// $Id: LineSegmentPath.java,v 1.3 2001/08/02 21:02:56 shaper Exp $
|
||||
|
||||
package com.threerings.miso.sprite;
|
||||
|
||||
@@ -7,11 +7,11 @@ import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* The Path class represents the path a sprite follows while
|
||||
* meandering about the screen. There must be at least two nodes in
|
||||
* any worthwhile path. The direction of the first node in the path
|
||||
* is meaningless since the sprite begins at that node and will
|
||||
* therefore never be heading towards it.
|
||||
* The <code>Path</code> class represents the path a sprite follows
|
||||
* while meandering about the screen. There must be at least two
|
||||
* nodes in any worthwhile path. The direction of the first node in
|
||||
* the path is meaningless since the sprite begins at that node and
|
||||
* will therefore never be heading towards it.
|
||||
*/
|
||||
public class Path
|
||||
{
|
||||
@@ -29,13 +29,21 @@ public class Path
|
||||
public static final int DIR_SOUTHEAST = 7;
|
||||
|
||||
/**
|
||||
* Construct a Path object.
|
||||
* Construct a <code>Path</code> object.
|
||||
*/
|
||||
public Path ()
|
||||
{
|
||||
_nodes = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>Path</code> object with the specified
|
||||
* starting node coordinates. An arbitrary direction will be
|
||||
* assigned to the starting node.
|
||||
*
|
||||
* @param x the starting node x-position.
|
||||
* @param y the starting node y-position.
|
||||
*/
|
||||
public Path (int x, int y)
|
||||
{
|
||||
_nodes = new ArrayList();
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
//
|
||||
// $Id: PathNode.java,v 1.2 2001/08/02 20:43:03 shaper Exp $
|
||||
// $Id: PathNode.java,v 1.3 2001/08/02 21:02:56 shaper Exp $
|
||||
|
||||
package com.threerings.miso.sprite;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
/**
|
||||
* The PathNode object is a single destination point in a Path.
|
||||
* The <code>PathNode</code> is a single destination point in a
|
||||
* <code>Path</code>.
|
||||
*/
|
||||
public class PathNode
|
||||
{
|
||||
@@ -17,7 +18,7 @@ public class PathNode
|
||||
public int dir;
|
||||
|
||||
/**
|
||||
* Construct a PathNode object.
|
||||
* Construct a <code>PathNode</code> object.
|
||||
*
|
||||
* @param x the node x-position.
|
||||
* @param y the node y-position.
|
||||
|
||||
Reference in New Issue
Block a user