diff --git a/src/java/com/threerings/media/sprite/MobileSprite.java b/src/java/com/threerings/cast/CharacterSprite.java
similarity index 58%
rename from src/java/com/threerings/media/sprite/MobileSprite.java
rename to src/java/com/threerings/cast/CharacterSprite.java
index 90a164b36..96c8c7c3c 100644
--- a/src/java/com/threerings/media/sprite/MobileSprite.java
+++ b/src/java/com/threerings/cast/CharacterSprite.java
@@ -1,5 +1,5 @@
//
-// $Id: MobileSprite.java,v 1.3 2001/08/02 00:42:02 shaper Exp $
+// $Id: CharacterSprite.java,v 1.1 2001/08/02 21:02:56 shaper Exp $
package com.threerings.miso.sprite;
@@ -8,31 +8,31 @@ 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.)
+ * A AmbulatorySprite is a sprite that can face in one of
+ * eight compass directions and animate itself walking along any
+ * chosen path.
*/
-public class MobileSprite extends Sprite
+public class AmbulatorySprite extends Sprite
{
/**
- * Construct a MobileSprite object, loading the tiles used to
- * display the sprite from specified tileset via the given tile
- * manager.
+ * Construct a AmbulatorySprite, loading the tiles
+ * used to display the sprite from the given 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)
+ public AmbulatorySprite (SpriteManager spritemgr, int x, int y,
+ TileManager tilemgr, int tsid)
{
super(spritemgr, x, y);
- _charTiles = getTiles(tilemgr, tsid);
+ _dirTiles = getTiles(tilemgr, tsid);
_dir = Path.DIR_SOUTH;
- setTiles(_charTiles[0]);
+ setTiles(_dirTiles[0]);
}
/**
@@ -70,37 +70,23 @@ public class MobileSprite extends Sprite
* @param x the destination x-position.
* @param y the destination y-position.
*/
- public void setDestination (int x, int y)
+ protected void moveAlongPath ()
{
+ // select the new path node
+ super.moveAlongPath();
+
+ // bail if we're at the end of the path
+ if (_dest == null) {
+ // stop any walking animation
+ setAnimationDelay(ANIM_NONE);
+ return;
+ }
+
// update the sprite tiles to reflect the direction
- setTiles(_charTiles[_dir = getDirection(x, y)]);
+ setTiles(_dirTiles[_dir = _dest.dir]);
- // 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;
- }
+ // start tile animation to show movement
+ setAnimationDelay(0);
}
/** The number of frames of animation for each direction. */
@@ -113,7 +99,7 @@ public class MobileSprite extends Sprite
protected static final int DIR_BUFFER = 20;
/** The animation frames for the sprite facing each direction. */
- protected Tile[][] _charTiles;
+ protected Tile[][] _dirTiles;
/** The direction the sprite is currently facing. */
protected int _dir;
diff --git a/src/java/com/threerings/media/util/LineSegmentPath.java b/src/java/com/threerings/media/util/LineSegmentPath.java
index f1c169708..f1d15d972 100644
--- a/src/java/com/threerings/media/util/LineSegmentPath.java
+++ b/src/java/com/threerings/media/util/LineSegmentPath.java
@@ -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 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.
*/
public class Path
{
@@ -29,13 +29,21 @@ public class Path
public static final int DIR_SOUTHEAST = 7;
/**
- * Construct a Path object.
+ * Construct a Path object.
*/
public Path ()
{
_nodes = new ArrayList();
}
+ /**
+ * Construct a Path 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();
diff --git a/src/java/com/threerings/media/util/PathNode.java b/src/java/com/threerings/media/util/PathNode.java
index a59e2d19a..2c73049bb 100644
--- a/src/java/com/threerings/media/util/PathNode.java
+++ b/src/java/com/threerings/media/util/PathNode.java
@@ -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 PathNode is a single destination point in a
+ * Path.
*/
public class PathNode
{
@@ -17,7 +18,7 @@ public class PathNode
public int dir;
/**
- * Construct a PathNode object.
+ * Construct a PathNode object.
*
* @param x the node x-position.
* @param y the node y-position.
diff --git a/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java b/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java
index b28cee9d0..7a9da02da 100644
--- a/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java
+++ b/tests/src/java/com/threerings/miso/viewer/ViewerFrame.java
@@ -1,5 +1,5 @@
//
-// $Id: ViewerFrame.java,v 1.5 2001/08/02 00:42:02 shaper Exp $
+// $Id: ViewerFrame.java,v 1.6 2001/08/02 21:02:57 shaper Exp $
package com.threerings.miso.viewer;
@@ -41,12 +41,12 @@ class ViewerFrame extends JFrame implements WindowListener
TileManager tilemgr = _ctx.getTileManager();
// add the test character sprite to the sprite manager
- MobileSprite ms =
- new MobileSprite(spritemgr, 300, 300, tilemgr, TSID_CHAR);
- spritemgr.addSprite(ms);
+ AmbulatorySprite sprite =
+ new AmbulatorySprite(spritemgr, 300, 300, tilemgr, TSID_CHAR);
+ spritemgr.addSprite(sprite);
// set up the scene view panel with a default scene
- SceneViewPanel svpanel = new SceneViewPanel(_ctx, spritemgr, ms);
+ SceneViewPanel svpanel = new SceneViewPanel(_ctx, spritemgr, sprite);
// add the scene view panel
getContentPane().add(svpanel, BorderLayout.CENTER);