Added ScreenTilePath, which does everything in screen coordinates,
but after each movement it updates the sprite that it's moving to tell it the latest tile coordinates. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1472 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.110 2002/05/31 03:38:03 mdb Exp $
|
// $Id: IsoSceneView.java,v 1.111 2002/06/18 21:22:34 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -651,6 +651,18 @@ public class IsoSceneView implements SceneView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a path between the two points (in screen coordinates)
|
||||||
|
* that will update a MisoCharacterSprite as it walks the path.
|
||||||
|
*/
|
||||||
|
public Path getScreenTilePath (Point start, Point dest, int direction)
|
||||||
|
{
|
||||||
|
ScreenTilePath path = new ScreenTilePath(_model);
|
||||||
|
path.addNode(start.x, start.y, 0); // first direction matters not
|
||||||
|
path.addNode(dest.x, dest.y, direction);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public Path getPath (MisoCharacterSprite sprite, int x, int y)
|
public Path getPath (MisoCharacterSprite sprite, int x, int y)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// $Id: ScreenTilePath.java,v 1.1 2002/06/18 21:22:34 ray Exp $
|
||||||
|
|
||||||
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.threerings.media.util.LineSegmentPath;
|
||||||
|
import com.threerings.media.util.Pathable;
|
||||||
|
|
||||||
|
import com.threerings.miso.Log;
|
||||||
|
import com.threerings.miso.scene.util.IsoUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A line segment path that attempts to update the sprite's tile coordinates
|
||||||
|
* as it walks it along.
|
||||||
|
*/
|
||||||
|
public class ScreenTilePath extends LineSegmentPath
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a screen tile path.
|
||||||
|
*
|
||||||
|
* @param model the iso scene view model the path is associated with.
|
||||||
|
*/
|
||||||
|
public ScreenTilePath (IsoSceneViewModel model)
|
||||||
|
{
|
||||||
|
_model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public boolean tick (Pathable pable, long timestamp)
|
||||||
|
{
|
||||||
|
boolean moved = super.tick(pable, timestamp);
|
||||||
|
|
||||||
|
if (moved) {
|
||||||
|
MisoCharacterSprite mcs = (MisoCharacterSprite)pable;
|
||||||
|
int sx = mcs.getX(), sy = mcs.getY();
|
||||||
|
Point pos = new Point();
|
||||||
|
|
||||||
|
// check whether we've arrived at the destination tile
|
||||||
|
if (shouldComputeTileCoords()) {
|
||||||
|
// get the sprite's latest tile coordinates
|
||||||
|
IsoUtil.screenToTile(_model, sx, sy, pos);
|
||||||
|
|
||||||
|
setTileCoords(mcs, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the sprite's latest fine coordinates
|
||||||
|
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
|
||||||
|
mcs.setFineLocation(fpos.x, fpos.y);
|
||||||
|
|
||||||
|
// Log.info("Sprite moved [s=" + mcs + "].");
|
||||||
|
}
|
||||||
|
|
||||||
|
return moved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should we compute and attempt to set the tile coordinates during
|
||||||
|
* this tick?
|
||||||
|
*/
|
||||||
|
protected boolean shouldComputeTileCoords ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the tile coordinates.
|
||||||
|
*/
|
||||||
|
protected void setTileCoords (MisoCharacterSprite mcs, Point pos)
|
||||||
|
{
|
||||||
|
mcs.setTileLocation(pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The iso scene view model. */
|
||||||
|
protected IsoSceneViewModel _model;
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
//
|
//
|
||||||
// $Id: TilePath.java,v 1.7 2002/06/12 23:31:42 ray Exp $
|
// $Id: TilePath.java,v 1.8 2002/06/18 21:22:34 ray Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Point;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.threerings.util.DirectionCodes;
|
import com.threerings.util.DirectionCodes;
|
||||||
@@ -21,7 +21,7 @@ import com.threerings.miso.scene.util.IsoUtil;
|
|||||||
* Only ambulatory sprites can follow a tile path, and their tile
|
* Only ambulatory sprites can follow a tile path, and their tile
|
||||||
* coordinates are updated as the path is traversed.
|
* coordinates are updated as the path is traversed.
|
||||||
*/
|
*/
|
||||||
public class TilePath extends LineSegmentPath
|
public class TilePath extends ScreenTilePath
|
||||||
implements DirectionCodes
|
implements DirectionCodes
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -39,51 +39,29 @@ public class TilePath extends LineSegmentPath
|
|||||||
IsoSceneViewModel model, MisoCharacterSprite sprite, List tiles,
|
IsoSceneViewModel model, MisoCharacterSprite sprite, List tiles,
|
||||||
int destx, int desty)
|
int destx, int desty)
|
||||||
{
|
{
|
||||||
_model = model;
|
super(model); // I won't make any jokes if you don't.
|
||||||
|
|
||||||
// set up the path nodes
|
// set up the path nodes
|
||||||
createPath(sprite, tiles, destx, desty);
|
createPath(sprite, tiles, destx, desty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public boolean tick (Pathable pable, long timestamp)
|
protected boolean shouldComputeTileCoords ()
|
||||||
{
|
{
|
||||||
boolean moved = super.tick(pable, timestamp);
|
return !_arrived;
|
||||||
|
}
|
||||||
|
|
||||||
if (moved) {
|
// documentation inherited
|
||||||
MisoCharacterSprite mcs = (MisoCharacterSprite)pable;
|
protected void setTileCoords (MisoCharacterSprite mcs, Point pos)
|
||||||
int sx = mcs.getX(), sy = mcs.getY();
|
{
|
||||||
Point pos = new Point();
|
// if the sprite has reached the destination tile,
|
||||||
|
// update the sprite's tile location and remember
|
||||||
// check whether we've arrived at the destination tile
|
// we've arrived
|
||||||
if (!_arrived) {
|
if (pos.x == _dest.getTileX() &&
|
||||||
// get the sprite's latest tile coordinates
|
pos.y == _dest.getTileY()) {
|
||||||
IsoUtil.screenToTile(_model, sx, sy, pos);
|
super.setTileCoords(mcs, pos);
|
||||||
|
_arrived = true;
|
||||||
// if the sprite has reached the destination tile,
|
|
||||||
// update the sprite's tile location and remember
|
|
||||||
// we've arrived
|
|
||||||
int dtx = _dest.getTileX(), dty = _dest.getTileY();
|
|
||||||
if (pos.x == dtx && pos.y == dty) {
|
|
||||||
mcs.setTileLocation(dtx, dty);
|
|
||||||
// Log.info("Sprite arrived [dtx=" + dtx +
|
|
||||||
// ", dty=" + dty + "].");
|
|
||||||
_arrived = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the sprite's latest fine coordinates
|
|
||||||
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
|
|
||||||
mcs.setFineLocation(fpos.x, fpos.y);
|
|
||||||
|
|
||||||
// Log.info("Sprite moved [s=" + mcs + "].");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return moved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -184,7 +162,4 @@ public class TilePath extends LineSegmentPath
|
|||||||
|
|
||||||
/** The destination tile path node. */
|
/** The destination tile path node. */
|
||||||
protected TilePathNode _dest;
|
protected TilePathNode _dest;
|
||||||
|
|
||||||
/** The iso scene view model. */
|
|
||||||
protected IsoSceneViewModel _model;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user