Moved sprite stuff into media package, removed coupling between miso stuff

and sprite stuff by added some interfaces in the sprite stuff and
implementing them with the miso stuff.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@245 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-14 23:35:22 +00:00
parent 0d0cb7f8ec
commit 3eea4dcaad
13 changed files with 221 additions and 134 deletions
@@ -1,64 +1,37 @@
//
// $Id: CharacterSprite.java,v 1.3 2001/08/14 22:54:45 mdb Exp $
// $Id: CharacterSprite.java,v 1.4 2001/08/14 23:35:22 mdb Exp $
package com.threerings.media.sprite;
import com.threerings.media.Log;
import com.threerings.miso.tile.Tile;
import com.threerings.miso.tile.TileManager;
/**
* An <code>AmbulatorySprite</code> is a sprite that can face in one
* of the various compass directions and that can animate itself
* walking along some chosen path.
* An <code>AmbulatorySprite</code> is a sprite that can face in one of
* the various compass directions and that can animate itself walking
* along some chosen path.
*/
public class AmbulatorySprite extends Sprite
{
/**
* Construct an <code>AmbulatorySprite</code>, loading the tiles
* used to display the sprite from the given tileset.
* Construct an <code>AmbulatorySprite</code>, with a multi-frame
* image associated with each of the eight compass directions. The
* array should be in the order defined by the <code>Path</code>
* direction constants (SW, W, NW, N, NE, E, SE, S).
*
* @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.
* @param anims the set of multi-frame images to use when animating
* the sprite in each of the compass directions.
*/
public AmbulatorySprite (SpriteManager spritemgr, int x, int y,
TileManager tilemgr, int tsid)
MultiFrameImage[] anims)
{
super(spritemgr, x, y);
_dirTiles = getTiles(tilemgr, tsid);
_anims = anims;
_dir = Path.DIR_SOUTH;
setTiles(_dirTiles[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;
setFrames(_anims[Path.DIR_NORTH]);
}
/**
@@ -81,18 +54,15 @@ public class AmbulatorySprite extends Sprite
return;
}
// update the sprite tiles to reflect the direction
setTiles(_dirTiles[_dir = _dest.dir]);
// update the sprite frames to reflect the direction
setFrames(_anims[_dir = _dest.dir]);
// start tile animation to show movement
setAnimationDelay(0);
}
/** The number of frames of animation for each direction. */
protected static final int NUM_DIR_FRAMES = 8;
/** The animation frames for the sprite facing each direction. */
protected Tile[][] _dirTiles;
protected MultiFrameImage[] _anims;
/** The direction the sprite is currently facing. */
protected int _dir;