com.threerings.puzzle.drop.client
Class DropSprite

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.sprite.Sprite
          extended by com.threerings.puzzle.drop.client.DropSprite
All Implemented Interfaces:
com.threerings.media.util.Pathable, DirectionCodes, Shape
Direct Known Subclasses:
DropBlockSprite

public class DropSprite
extends com.threerings.media.sprite.Sprite

The drop sprite is a sprite that displays one or more pieces falling toward the bottom of the board.


Nested Class Summary
protected static class DropSprite.PieceMovedOp
          Used to dispatch DropSpriteObserver.pieceMoved(com.threerings.puzzle.drop.client.DropSprite, long, int, int).
 
Nested classes/interfaces inherited from class com.threerings.media.sprite.Sprite
com.threerings.media.sprite.Sprite.CancelledOp, com.threerings.media.sprite.Sprite.CompletedOp
 
Field Summary
protected  boolean _bouncing
          Indicates that the drop sprite is bouncing; see setBouncing(boolean).
protected  int _col
          The current piece location in the board.
protected  Point _destPos
          The screen coordinates of the top-left of the row toward which the sprite is falling.
protected  int _dist
          The number of rows remaining to drop.
protected  long _endstamp
          The time at which we reached the end of the previous row.
protected  int _offx
          The offsets in columns or rows at which the piece is rendered.
protected  int _offy
          The offsets in columns or rows at which the piece is rendered.
protected  int[] _pieces
          The pieces this sprite is displaying.
protected  Point _renderPos
          The piece render position; used as working data when determining where to render each piece in the sprite.
protected  int _row
          The current piece location in the board.
protected  long _rowstamp
          The time at which we started the current row.
protected  Point _srcPos
          The screen coordinates of the top-left of the row currently occupied by the sprite.
protected  long _stopstamp
          The time at which we were stopped en route to our next row.
protected  int _unit
          The unit distance the sprite moves to reach the next row.
protected  float _vel
          The piece velocity.
protected  DropBoardView _view
          The board view upon which this sprite is displayed.
protected static float DEFAULT_VELOCITY
          The default piece velocity.
protected static int[] ORIENT_DX
           
protected static int[] ORIENT_DY
           
 
Fields inherited from class com.threerings.media.sprite.Sprite
_orient, _ox, _oxoff, _oy, _oyoff, _path, _pathStamp
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Fields inherited from interface com.threerings.util.DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST
 
Constructor Summary
DropSprite(DropBoardView view, int col, int row, int[] pieces, int dist)
          Constructs a drop sprite and starts it dropping.
DropSprite(DropBoardView view, int col, int row, int[] pieces, int dist, int renderOrder)
          Constructs a drop sprite and starts it dropping.
 
Method Summary
protected  void advancePosition()
          Called when the sprite has finished traversing its current row to advance its board coordinates to the next row.
 void drop()
          Starts the piece dropping toward the next row.
 void fastForward(long timeDelta)
           
 int getColumn()
          Returns the column the piece is located in.
 int getDistance()
          Returns the remaining number of columns to drop.
 float getPercentDone(long timestamp)
          Returns a value between 0.0 and 1.0 representing how far the piece has moved toward the next row as of the given time stamp.
 int[] getPieces()
          Returns the pieces the sprite is displaying.
 int getRow()
          Returns the row the piece is located in.
 float getVelocity()
          Returns the velocity of this sprite.
protected  void init()
           
 boolean inside(Shape shape)
           
 boolean isBouncing()
          Returns true if this sprite is bouncing.
 boolean isDropping()
          Returns true if this drop sprite is dropping, false if it has been stop()ped or has not yet been drop()ped.
 void paint(Graphics2D gfx)
           
protected  void paintPieceImage(Graphics2D gfx, int pieceidx, int col, int row, int orient, int x, int y)
          Paints the specified piece with the supplied parameters.
 void setBoardLocation(int row, int col)
          Sets the row and column the piece is located in.
 void setBouncing(boolean bouncing)
          Puts the drop sprite into (or takes it out of) bouncing mode.
 void setColumn(int col)
          Sets the column the piece is located in.
 void setColumnOffset(int count)
          Sets the column offset of the sprite image.
 void setOrientation(int orient)
           
 void setPieces(int[] pieces)
          Sets the pieces the sprite is displaying.
 void setRow(int row)
          Set the row the piece is located in.
 void setRowOffset(int count)
          Sets the row offset of the sprite image.
 void setVelocity(float velocity)
          Sets the velocity of this sprite.
protected  void shiftForBounce()
          Updates the sprite's location to illustrate that it is currently in the "bouncing" state.
 void stop()
          Stops the piece from dropping.
 void tick(long timestamp)
           
 void toString(StringBuilder buf)
           
protected  void updateBounds()
          Updates the bounds for this sprite based on the sprite display dimensions in the view.
protected  void updatePosition()
          Updates internal pixel coordinates used when the piece is moving.
protected  void updateRenderOffset()
          Adjusts our render origin such that our location is not in the upper left of the sprite's rendered image but is in fact offset by some number of rows and columns.
 
Methods inherited from class com.threerings.media.sprite.Sprite
addSpriteObserver, cancelMove, contains, getHeight, getOrientation, getPath, getWidth, getX, getXOffset, getY, getYOffset, hitTest, intersects, isMoving, move, paintPath, pathBeginning, pathCompleted, removeSpriteObserver, setLocation, shutdown, tickPath, updateRenderOrigin, viewLocationDidChange
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, toString, willStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.threerings.media.util.Pathable
getBounds
 

Field Detail

DEFAULT_VELOCITY

protected static final float DEFAULT_VELOCITY
The default piece velocity.

See Also:
Constant Field Values

_rowstamp

protected long _rowstamp
The time at which we started the current row.


_endstamp

protected long _endstamp
The time at which we reached the end of the previous row.


_stopstamp

protected long _stopstamp
The time at which we were stopped en route to our next row.


_view

protected DropBoardView _view
The board view upon which this sprite is displayed.


_unit

protected int _unit
The unit distance the sprite moves to reach the next row.


_srcPos

protected Point _srcPos
The screen coordinates of the top-left of the row currently occupied by the sprite.


_destPos

protected Point _destPos
The screen coordinates of the top-left of the row toward which the sprite is falling.


_renderPos

protected Point _renderPos
The piece render position; used as working data when determining where to render each piece in the sprite.


_dist

protected int _dist
The number of rows remaining to drop.


_vel

protected float _vel
The piece velocity.


_offx

protected int _offx
The offsets in columns or rows at which the piece is rendered.


_offy

protected int _offy
The offsets in columns or rows at which the piece is rendered.


_row

protected int _row
The current piece location in the board.


_col

protected int _col
The current piece location in the board.


_pieces

protected int[] _pieces
The pieces this sprite is displaying.


_bouncing

protected boolean _bouncing
Indicates that the drop sprite is bouncing; see setBouncing(boolean).


ORIENT_DX

protected static final int[] ORIENT_DX

ORIENT_DY

protected static final int[] ORIENT_DY
Constructor Detail

DropSprite

public DropSprite(DropBoardView view,
                  int col,
                  int row,
                  int[] pieces,
                  int dist)
Constructs a drop sprite and starts it dropping.

Parameters:
view - the board view upon which this sprite will be displayed.
col - the column of the sprite.
row - the row of the bottom-most piece.
pieces - the pieces displayed by the sprite.
dist - the distance the sprite is to drop in rows.

DropSprite

public DropSprite(DropBoardView view,
                  int col,
                  int row,
                  int[] pieces,
                  int dist,
                  int renderOrder)
Constructs a drop sprite and starts it dropping.

Parameters:
view - the board view upon which this sprite will be displayed.
col - the column of the sprite.
row - the row of the bottom-most piece.
pieces - the pieces displayed by the sprite.
dist - the distance the sprite is to drop in rows.
renderOrder - the render order.
Method Detail

init

protected void init()
Overrides:
init in class com.threerings.media.AbstractMedia

getDistance

public int getDistance()
Returns the remaining number of columns to drop.


getColumn

public int getColumn()
Returns the column the piece is located in.


getRow

public int getRow()
Returns the row the piece is located in.


getPieces

public int[] getPieces()
Returns the pieces the sprite is displaying.


getVelocity

public float getVelocity()
Returns the velocity of this sprite.


setBoardLocation

public void setBoardLocation(int row,
                             int col)
Sets the row and column the piece is located in.


setColumn

public void setColumn(int col)
Sets the column the piece is located in.


setRow

public void setRow(int row)
Set the row the piece is located in.


setColumnOffset

public void setColumnOffset(int count)
Sets the column offset of the sprite image.


setRowOffset

public void setRowOffset(int count)
Sets the row offset of the sprite image.


setPieces

public void setPieces(int[] pieces)
Sets the pieces the sprite is displaying.


setVelocity

public void setVelocity(float velocity)
Sets the velocity of this sprite. The time at which the current row was entered is modified so that the sprite position will remain the same when calculated using the new velocity since the piece sprite may have its velocity modified in the middle of a row traversal.


drop

public void drop()
Starts the piece dropping toward the next row.


isDropping

public boolean isDropping()
Returns true if this drop sprite is dropping, false if it has been stop()ped or has not yet been drop()ped.


stop

public void stop()
Stops the piece from dropping.


setBouncing

public void setBouncing(boolean bouncing)
Puts the drop sprite into (or takes it out of) bouncing mode. Bouncing mode is used to put the sprite into limbo after it lands but before we commit the landing, giving the user a last moment change move or rotate the piece. While the sprite is "bouncing" it will be rendered one pixel below its at rest state.


isBouncing

public boolean isBouncing()
Returns true if this sprite is bouncing.


shiftForBounce

protected void shiftForBounce()
Updates the sprite's location to illustrate that it is currently in the "bouncing" state.


inside

public boolean inside(Shape shape)
Overrides:
inside in class com.threerings.media.sprite.Sprite

getPercentDone

public float getPercentDone(long timestamp)
Returns a value between 0.0 and 1.0 representing how far the piece has moved toward the next row as of the given time stamp.


paint

public void paint(Graphics2D gfx)
Overrides:
paint in class com.threerings.media.sprite.Sprite

paintPieceImage

protected void paintPieceImage(Graphics2D gfx,
                               int pieceidx,
                               int col,
                               int row,
                               int orient,
                               int x,
                               int y)
Paints the specified piece with the supplied parameters.


tick

public void tick(long timestamp)
Overrides:
tick in class com.threerings.media.sprite.Sprite

advancePosition

protected void advancePosition()
Called when the sprite has finished traversing its current row to advance its board coordinates to the next row.


fastForward

public void fastForward(long timeDelta)
Overrides:
fastForward in class com.threerings.media.sprite.Sprite

toString

public void toString(StringBuilder buf)
Overrides:
toString in class com.threerings.media.sprite.Sprite

updatePosition

protected void updatePosition()
Updates internal pixel coordinates used when the piece is moving.


setOrientation

public void setOrientation(int orient)
Specified by:
setOrientation in interface com.threerings.media.util.Pathable
Overrides:
setOrientation in class com.threerings.media.sprite.Sprite

updateBounds

protected void updateBounds()
Updates the bounds for this sprite based on the sprite display dimensions in the view.


updateRenderOffset

protected void updateRenderOffset()
Adjusts our render origin such that our location is not in the upper left of the sprite's rendered image but is in fact offset by some number of rows and columns.