Added the ability for DelayPath to set a location for the path.
Some whitespace cleanup. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3880 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -22,15 +22,42 @@
|
|||||||
package com.threerings.media.util;
|
package com.threerings.media.util;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience path that waits a specified amount of time.
|
* A convenience path that waits a specified amount of time.
|
||||||
*/
|
*/
|
||||||
public class DelayPath extends TimedPath
|
public class DelayPath extends TimedPath
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Cause the current path to remain unchanged for the duration.
|
||||||
|
*/
|
||||||
public DelayPath (long duration)
|
public DelayPath (long duration)
|
||||||
|
{
|
||||||
|
this(null, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to the sprite to the supplied location then wait for the duration.
|
||||||
|
*/
|
||||||
|
public DelayPath (int x, int y, long duration)
|
||||||
|
{
|
||||||
|
this(new Point(x, y), duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to the sprite to the supplied location then wait for the duration.
|
||||||
|
*/
|
||||||
|
public DelayPath (Point source, long duration)
|
||||||
{
|
{
|
||||||
super(duration);
|
super(duration);
|
||||||
|
_source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public void init (Pathable pable, long timestamp)
|
||||||
|
{
|
||||||
|
super.init(pable, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -42,8 +69,23 @@ public class DelayPath extends TimedPath
|
|||||||
public boolean tick (Pathable pable, long tickstamp)
|
public boolean tick (Pathable pable, long tickstamp)
|
||||||
{
|
{
|
||||||
if (tickstamp >= _startStamp + _duration) {
|
if (tickstamp >= _startStamp + _duration) {
|
||||||
|
if (_source != null) {
|
||||||
|
pable.setLocation(_source.x, _source.y);
|
||||||
|
}
|
||||||
pable.pathCompleted(tickstamp);
|
pable.pathCompleted(tickstamp);
|
||||||
|
return (_source != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If necessary, move the sprite to the supplied location
|
||||||
|
if (_source != null && (pable.getX() != _source.x ||
|
||||||
|
pable.getY() != _source.y)) {
|
||||||
|
pable.setLocation(_source.x, _source.y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Source point. */
|
||||||
|
protected Point _source;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,14 +196,14 @@ public class LineSegmentPath
|
|||||||
pable.setLocation(node.loc.x, node.loc.y);
|
pable.setLocation(node.loc.x, node.loc.y);
|
||||||
}
|
}
|
||||||
// and let the pathable know that we're done
|
// and let the pathable know that we're done
|
||||||
pable.pathCompleted(timestamp);
|
pable.pathCompleted(timestamp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// and an enumeration of the path nodes
|
// and an enumeration of the path nodes
|
||||||
_niter = _nodes.iterator();
|
_niter = _nodes.iterator();
|
||||||
|
|
||||||
// pretend like we were previously heading to our starting position
|
// pretend like we were previously heading to our starting position
|
||||||
_dest = getNextNode();
|
_dest = getNextNode();
|
||||||
|
|
||||||
// begin traversing the path
|
// begin traversing the path
|
||||||
|
|||||||
Reference in New Issue
Block a user