Create and have the sprite follow a path rather than explicitly
setting the sprite destination. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@152 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.22 2001/08/02 18:58:59 shaper Exp $
|
||||
// $Id: IsoSceneView.java,v 1.23 2001/08/02 20:43:03 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.sprite.SpriteManager;
|
||||
import com.threerings.miso.sprite.*;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
import com.threerings.miso.tile.TileManager;
|
||||
import com.threerings.miso.util.MathUtil;
|
||||
@@ -69,6 +69,9 @@ public class IsoSceneView implements EditableSceneView
|
||||
// draw lines illustrating tracking of the mouse position
|
||||
//paintMouseLines(gfx);
|
||||
|
||||
gfx.setColor(Color.yellow);
|
||||
gfx.drawRect(0, 0, _model.bounds.width - 1, _model.bounds.height - 1);
|
||||
|
||||
// restore the original clipping region
|
||||
gfx.setClip(oldclip);
|
||||
}
|
||||
@@ -89,12 +92,12 @@ public class IsoSceneView implements EditableSceneView
|
||||
int[] dinfo = (int[])_dirty.remove(0);
|
||||
int tx = dinfo[0], ty = dinfo[1];
|
||||
|
||||
// get the tile's screen position
|
||||
Polygon poly = getTilePolygon(tx, ty);
|
||||
|
||||
// draw all layers at this tile position
|
||||
for (int kk = 0; kk < Scene.NUM_LAYERS; kk++) {
|
||||
|
||||
// get the tile's screen position
|
||||
Polygon poly = getTilePolygon(tx, ty);
|
||||
|
||||
// get the tile at these coordinates and layer
|
||||
Tile tile = _scene.tiles[tx][ty][kk];
|
||||
if (tile == null) continue;
|
||||
@@ -108,7 +111,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
}
|
||||
|
||||
// draw all sprites residing in the current tile
|
||||
_spritemgr.renderSprites(gfx, getTilePolygon(tx, ty));
|
||||
_spritemgr.renderSprites(gfx, poly);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +389,21 @@ public class IsoSceneView implements EditableSceneView
|
||||
_model.calculateXAxis();
|
||||
}
|
||||
|
||||
public Path getPath (Sprite sprite, int x, int y)
|
||||
{
|
||||
// make sure the destination point is within our bounds
|
||||
if (x < 0 || x >= _model.bounds.width ||
|
||||
y < 0 || y >= _model.bounds.height) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// create path from current loc to destination
|
||||
Path path = new Path(sprite.x, sprite.y);
|
||||
path.addNode(x, y, Path.DIR_NORTH);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/** The color to draw the highlighted tile. */
|
||||
protected static final Color HLT_COLOR = Color.green;
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
//
|
||||
// $Id: SceneView.java,v 1.8 2001/08/02 00:42:02 shaper Exp $
|
||||
// $Id: SceneView.java,v 1.9 2001/08/02 20:43:03 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.miso.tile.Tile;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.miso.sprite.Path;
|
||||
import com.threerings.miso.sprite.Sprite;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
|
||||
/**
|
||||
* The SceneView interface provides an interface to be implemented by
|
||||
* classes that provide a view of a given scene by drawing the scene
|
||||
@@ -37,4 +39,17 @@ public interface SceneView
|
||||
* @param rects the list of <code>java.awt.Rectangle</code> objects.
|
||||
*/
|
||||
public void invalidateRects (ArrayList rects);
|
||||
|
||||
/**
|
||||
* Return a Path object detailing a valid path for the given
|
||||
* sprite to take in the scene to get from its current position to
|
||||
* the destination position.
|
||||
*
|
||||
* @param sprite the sprite to move.
|
||||
* @param x the destination x-position in pixel coordinates.
|
||||
* @param y the destination y-position in pixel coordinates.
|
||||
*
|
||||
* @return the sprite's path or null if no valid path exists.
|
||||
*/
|
||||
public Path getPath (Sprite sprite, int x, int y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user