f91f47d73b
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
83 lines
2.1 KiB
Java
83 lines
2.1 KiB
Java
//
|
|
// $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;
|
|
}
|