Abstracted character-sprite-related activity to the cast package in
preparation for character component compositing and other character-related antics. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@575 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DirtyItemList.java,v 1.3 2001/10/25 16:35:45 shaper Exp $
|
||||
// $Id: DirtyItemList.java,v 1.4 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DirtyItemList extends ArrayList
|
||||
* item list.
|
||||
*/
|
||||
public void appendDirtySprite (
|
||||
Sprite sprite, int x, int y, Rectangle dirtyRect)
|
||||
MisoCharacterSprite sprite, int x, int y, Rectangle dirtyRect)
|
||||
{
|
||||
add(new DirtyItem(sprite, null, x, y, dirtyRect));
|
||||
}
|
||||
@@ -164,13 +164,13 @@ public class DirtyItemList extends ArrayList
|
||||
|
||||
if (da.ox == db.ox &&
|
||||
da.oy == db.oy &&
|
||||
(da.obj instanceof AmbulatorySprite) &&
|
||||
(db.obj instanceof AmbulatorySprite)) {
|
||||
(da.obj instanceof MisoCharacterSprite) &&
|
||||
(db.obj instanceof MisoCharacterSprite)) {
|
||||
// we're comparing two sprites co-existing on the same
|
||||
// tile, so study their fine coordinates to determine
|
||||
// rendering order
|
||||
AmbulatorySprite as = (AmbulatorySprite)da.obj;
|
||||
AmbulatorySprite bs = (AmbulatorySprite)db.obj;
|
||||
MisoCharacterSprite as = (MisoCharacterSprite)da.obj;
|
||||
MisoCharacterSprite bs = (MisoCharacterSprite)db.obj;
|
||||
|
||||
int ahei = as.getFineX() + as.getFineY();
|
||||
int bhei = bs.getFineX() + bs.getFineY();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.69 2001/10/25 16:36:42 shaper Exp $
|
||||
// $Id: IsoSceneView.java,v 1.70 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -543,7 +543,8 @@ public class IsoSceneView implements SceneView
|
||||
|
||||
int size = _dirtySprites.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
AmbulatorySprite sprite = (AmbulatorySprite)_dirtySprites.get(ii);
|
||||
MisoCharacterSprite sprite =
|
||||
(MisoCharacterSprite)_dirtySprites.get(ii);
|
||||
|
||||
// get the dirty portion of the sprite
|
||||
Rectangle drect = sprite.getBounds().intersection(r);
|
||||
@@ -576,7 +577,7 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Path getPath (AmbulatorySprite sprite, int x, int y)
|
||||
public Path getPath (MisoCharacterSprite sprite, int x, int y)
|
||||
{
|
||||
// make sure the destination point is within our bounds
|
||||
if (!_model.bounds.contains(x, y)) {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// $Id: MisoCharacterSprite.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.cast.CharacterSprite;
|
||||
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
|
||||
/**
|
||||
* The miso character sprite extends the basic character sprite to
|
||||
* support the notion of tile passability, and to allow the sprite to
|
||||
* store and make available its tile and fine coordinates within the
|
||||
* scene. Note that the tile and fine coordinates must initially be
|
||||
* set properly by whomever creates the sprite. Thereafter, the
|
||||
* sprite will only be moved about via the {@link TilePath}, which
|
||||
* will itself keep the sprite coordinates properly up to date.
|
||||
*/
|
||||
public class MisoCharacterSprite
|
||||
extends CharacterSprite
|
||||
implements Traverser
|
||||
{
|
||||
// documentation inherited
|
||||
public boolean canTraverse (MisoTile tile)
|
||||
{
|
||||
// by default, passability is solely the province of the tile
|
||||
return tile.passable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's location on the x-axis in tile coordinates.
|
||||
*/
|
||||
public int getTileX ()
|
||||
{
|
||||
return _tilex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's location on the y-axis in tile coordinates.
|
||||
*/
|
||||
public int getTileY ()
|
||||
{
|
||||
return _tiley;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's location on the x-axis within its current
|
||||
* tile in fine coordinates.
|
||||
*/
|
||||
public int getFineX ()
|
||||
{
|
||||
return _finex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite's location on the y-axis within its current
|
||||
* tile in fine coordinates.
|
||||
*/
|
||||
public int getFineY ()
|
||||
{
|
||||
return _finey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sprite's location in tile coordinates; the sprite is
|
||||
* not actually moved in any way. This method is only intended
|
||||
* for use in updating the sprite's stored position which is made
|
||||
* accessible to others that may care to review it.
|
||||
*/
|
||||
public void setTileLocation (int x, int y)
|
||||
{
|
||||
_tilex = x;
|
||||
_tiley = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sprite's location in fine coordinates; the sprite is
|
||||
* not actually moved in any way. This method is only intended
|
||||
* for use in updating the sprite's stored position which is made
|
||||
* accessible to others that may care to review it.
|
||||
*/
|
||||
public void setFineLocation (int x, int y)
|
||||
{
|
||||
_finex = x;
|
||||
_finey = y;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", tilex=").append(_tilex);
|
||||
buf.append(", tiley=").append(_tiley);
|
||||
buf.append(", finex=").append(_finex);
|
||||
buf.append(", finey=").append(_finey);
|
||||
}
|
||||
|
||||
/** The sprite location in tile coordinates. */
|
||||
protected int _tilex, _tiley;
|
||||
|
||||
/** The sprite location in fine coordinates. */
|
||||
protected int _finex, _finey;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneView.java,v 1.17 2001/10/22 18:21:41 shaper Exp $
|
||||
// $Id: SceneView.java,v 1.18 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -49,5 +49,5 @@ public interface SceneView
|
||||
*
|
||||
* @return the sprite's path, or null if no valid path exists.
|
||||
*/
|
||||
public Path getPath (AmbulatorySprite sprite, int x, int y);
|
||||
public Path getPath (MisoCharacterSprite sprite, int x, int y);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TilePath.java,v 1.1 2001/10/24 00:55:08 shaper Exp $
|
||||
// $Id: TilePath.java,v 1.2 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TilePath extends LineSegmentPath
|
||||
* coordinates.
|
||||
*/
|
||||
public TilePath (
|
||||
IsoSceneViewModel model, AmbulatorySprite sprite, List tiles,
|
||||
IsoSceneViewModel model, MisoCharacterSprite sprite, List tiles,
|
||||
int destx, int desty)
|
||||
{
|
||||
_model = model;
|
||||
@@ -46,7 +46,7 @@ public class TilePath extends LineSegmentPath
|
||||
boolean moved = super.updatePosition(sprite, timestamp);
|
||||
|
||||
if (moved) {
|
||||
AmbulatorySprite as = (AmbulatorySprite)sprite;
|
||||
MisoCharacterSprite mcs = (MisoCharacterSprite)sprite;
|
||||
int sx = sprite.getX(), sy = sprite.getY();
|
||||
Point pos = new Point();
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TilePath extends LineSegmentPath
|
||||
// we've arrived
|
||||
int dtx = _dest.getTileX(), dty = _dest.getTileY();
|
||||
if (pos.x == dtx && pos.y == dty) {
|
||||
as.setTileLocation(dtx, dty);
|
||||
mcs.setTileLocation(dtx, dty);
|
||||
// Log.info("Sprite arrived [dtx=" + dtx +
|
||||
// ", dty=" + dty + "].");
|
||||
_arrived = true;
|
||||
@@ -68,14 +68,14 @@ public class TilePath extends LineSegmentPath
|
||||
}
|
||||
|
||||
// get the sprite's latest fine coordinates
|
||||
IsoUtil.tileToScreen(_model, as.getTileX(), as.getTileY(), pos);
|
||||
IsoUtil.tileToScreen(_model, mcs.getTileX(), mcs.getTileY(), pos);
|
||||
Point fpos = new Point();
|
||||
IsoUtil.pixelToFine(_model, sx - pos.x, sy - pos.y, fpos);
|
||||
|
||||
// inform the sprite
|
||||
as.setFineLocation(fpos.x, fpos.y);
|
||||
mcs.setFineLocation(fpos.x, fpos.y);
|
||||
|
||||
// Log.info("Sprite moved [s=" + as + "].");
|
||||
// Log.info("Sprite moved [s=" + mcs + "].");
|
||||
}
|
||||
|
||||
return moved;
|
||||
@@ -99,7 +99,7 @@ public class TilePath extends LineSegmentPath
|
||||
* following the given list of tile coordinates.
|
||||
*/
|
||||
protected void createPath (
|
||||
AmbulatorySprite sprite, List tiles, int destx, int desty)
|
||||
MisoCharacterSprite sprite, List tiles, int destx, int desty)
|
||||
{
|
||||
// constrain destination pixels to fine coordinates
|
||||
Point fpos = new Point();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoUtil.java,v 1.13 2001/10/24 00:55:08 shaper Exp $
|
||||
// $Id: IsoUtil.java,v 1.14 2001/10/26 01:17:21 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -18,6 +18,27 @@ import com.threerings.miso.scene.*;
|
||||
*/
|
||||
public class IsoUtil
|
||||
{
|
||||
/**
|
||||
* Sets the given character sprite's tile and fine coordinate
|
||||
* locations within the scene based on the sprite's current screen
|
||||
* pixel coordinates. This method should be called whenever a
|
||||
* {@link MisoCharacterSprite} is first created, but after its
|
||||
* location has been set via {@link Sprite#setLocation}.
|
||||
*/
|
||||
public static void setSpriteSceneLocation (
|
||||
IsoSceneViewModel model, MisoCharacterSprite sprite)
|
||||
{
|
||||
// get the sprite's position in full coordinates
|
||||
Point fpos = new Point();
|
||||
screenToFull(model, sprite.getX(), sprite.getY(), fpos);
|
||||
|
||||
// set the sprite's tile and fine coordinates
|
||||
sprite.setTileLocation(
|
||||
IsoUtil.fullToTile(fpos.x), IsoUtil.fullToTile(fpos.y));
|
||||
sprite.setFineLocation(
|
||||
IsoUtil.fullToFine(fpos.x), IsoUtil.fullToFine(fpos.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a polygon bounding all footprint tiles of the given
|
||||
* object tile.
|
||||
|
||||
Reference in New Issue
Block a user