📄 playerimpl.java
字号:
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player's away message.
*
* @param playerAwayMessage msg
*/
public void setPlayerAwayMessage( String playerAwayMessage ){
this.playerAwayMessage = playerAwayMessage;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*** SpriteDataSupplier implementation ***/
/** To get the X image position.
*
* @return x image coordinate
*/
public int getX() {
synchronized( xLock ) {
return (int) movementComposer.getXPosition();
}
}
/** To get the Y image position.
*
* @return y image cordinate
*/
public int getY() {
synchronized( yLock ) {
return (int) movementComposer.getYPosition();
}
}
/** To get the image identifier to use.
*
* @return image identifier.
*/
public ImageIdentifier getImageIdentifier() {
synchronized( imageLock ) {
return animation.getCurrentImage();
}
}
/** To get the eventual rotation angle. 0 means no rotation.
*
* @return angle in radians.
*/
public double getAngle() {
synchronized( angleLock ) {
return movementComposer.getOrientationAngle();
}
}
/** To get the X factor for scaling... 1.0 means no X scaling
*
* @return X scale factor
*/
public double getScaleX() {
return 1.0;
}
/** To get the Y factor for scaling... 1.0 means no Y scaling
*
* @return Y scale factor
*/
public double getScaleY() {
return 1.0;
}
/** To get the image's transparency ( 0.0 means invisible, 1.0 means fully visible ).
*
* @return alpha
*/
public float getAlpha() {
if( isConnectedToGame )
return 1.0f;
else
return 0.5f;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set X.
* @param x cordinate
*/
public void setX( int x ){
synchronized( xLock ) {
movementComposer.setXPosition( (float)x );
}
}
/** To set Y.
* @param y cordinate
*/
public void setY( int y ){
synchronized( yLock ) {
movementComposer.setYPosition( (float)y );
}
}
/** To set the angle.
*/
public void setAngle( double angleRad ) {
synchronized( angleLock ) {
movementComposer.setOrientationAngle( angleRad );
}
}
/** To set the position.
*/
public void setPosition(ScreenPoint p) {
setX( p.x );
setY( p.y );
}
/** To set player's speed
*/
public void setSpeed( float speed ) {
movementComposer.setSpeed( (float)speed );
}
/** To get player's speed
*/
public float getSpeed() {
return movementComposer.getSpeed();
}
/** To set player's angular speed
*/
public void setAngularSpeed(float angularSpeed) {
movementComposer.setAngularSpeed( angularSpeed );
}
/** To get player's angular speed
*/
public float getAngularSpeed() {
return movementComposer.getAngularSpeed();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get destination of trajectory
*/
public Point getEndPosition() {
return movementComposer.getTargetPosition();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player's movement.
*/
public void moveTo( Point endPoint, WorldManager worldManager ) {
synchronized( trajectoryLock ) {
movementComposer.moveTo( endPoint, worldManager );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Returns true if the player is moving
*/
public boolean isMoving() {
return movementComposer.isMoving();
}
/** To stop the player's movement
*/
public void stopMovement() {
movementComposer.stopMovement();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's drawable
* @return player sprite
*/
public Drawable getDrawable() {
return wotCharacter.getDrawable(this);
}
/** To get player's rectangle (to test intersection)
* it's used in world/town/interior/rooms/tilemaps sprites
*/
public Rectangle getCurrentRectangle() {
return wotCharacter.getDrawable(this).getRectangle();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Tick
*/
public void tick() {
// 1 - Movement Update
synchronized( trajectoryLock ) {
movementComposer.tick();
}
// 2 - Dynamic Filter Update
if (brightnessFilter!=null)
if (myRoom!=null)
brightnessFilter.setBrightness(movementComposer.getXPosition(), movementComposer.getYPosition());
// 3 - Animation Update
if(animation==null)
return;
if(!movementComposer.isMoving())
animation.reset();
else
animation.tick();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Is this player a Master player ? ( directly controlled by the client )
* @return true if this is a Master player, false otherwise.
*/
public boolean isMaster() {
return isMaster;
}
/** To set if this player is controlled by the client.
* @param isMaster true means controlled by the client.
*/
public void setIsMaster( boolean isMaster ) {
this.isMaster = isMaster;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's movement Composer.
*
* @return player MovementComposer
*/
public MovementComposer getMovementComposer() {
return movementComposer;
}
/** To set the player's movement Composer.
*
* @param movement MovementComposer.
*/
public void setMovementComposer( MovementComposer movementComposer ) {
this.movementComposer = movementComposer;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Use this method to send a NetMessage to the server.
*
* @param message message to send to the player.
*/
public void sendMessage( NetMessage message ) {
ClientDirector.getDataManager().sendMessage( message );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's current Room ( if we are in a Room ).
* @return current Room, null if we are not in a room.
*/
public Room getMyRoom() {
return myRoom;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's current TileMap ( if we are in a TileMap ).
* @return current TileMap, null if we are not in a tileMap.
*/
public TileMap getMyTileMap() {
return myTileMap;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get a text drawable representing the name of this player.
*/
public Drawable getTextDrawable() {
if( textDrawable!=null ) {
if( textDrawable.isLive() )
return null;
//textDrawable.resetTimeLimit();
//return textDrawable;
}
if (isConnectedToGame) {
textDrawable = new TextDrawable( fullPlayerName, getDrawable(), wotCharacter.getColor(),
13.0f, "Lucida Blackletter", ImageLibRef.TEXT_PRIORITY, 5000 );
} else {
textDrawable = new TextDrawable( fullPlayerName + " (away)", getDrawable(), wotCharacter.getColor(),
13.0f, "Lucida Blackletter", ImageLibRef.TEXT_PRIORITY, 5000 );
}
return textDrawable;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get a wave drawable on this player.
*/
public Drawable getWaveArcDrawable() {
if( waveDrawable!=null ) {
if( waveDrawable.isLive() ) {
waveDrawable.reset();
return null;
}
waveDrawable.reset();
return waveDrawable;
}
if(sprite==null) return null;
waveDrawable = new WaveArcDrawable( sprite, 40, Color.white,
ImageLibRef.WAVE_PRIORITY, 1.0f, (byte)3 );
return waveDrawable;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player name to display on the left of the screen
*/
public MultiLineText getGameScreenFullPlayerName() {
if(gameScreenFullPlayerName==null) {
String[] strTemp = { fullPlayerName };
gameScreenFullPlayerName = new MultiLineText(strTemp, 10, 10, Color.black, 15.0f, "Lucida Blackletter", ImageLibRef.TEXT_PRIORITY, MultiLineText.LEFT_ALIGNMENT);
}
return gameScreenFullPlayerName;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the primary key of the chat the player is now using.
* @return currentChatPrimaryKey
*/
public String getCurrentChatPrimaryKey() {
return currentChatPrimaryKey;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the current chat used
* @param currentChatPrimaryKey
*/
public void setCurrentChatPrimaryKey( String currentChatPrimaryKey ) {
this.currentChatPrimaryKey = currentChatPrimaryKey;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Is this player connected to the game ? ( not synchronized )
* @return true if the player is in the game, false if the client is not connected.
*/
public boolean isConnectedToGame() {
return isConnectedToGame;
}
/** To get the player's state (disconnected/connected/away)
*
* @return player state
*/
public PlayerState getPlayerState() {
return playerState;
}
/** To set the player's state (disconnected/connected/away)
*
* @param playerState player state
*/
public void setPlayerState(PlayerState playerState) {
this.playerState = playerState;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set if this player is connected to the game.
* @param true if the player is in the game, false if the client is not connected.
*/
public void setIsConnectedToGame( boolean isConnectedToGame ) {
this.isConnectedToGame = isConnectedToGame;
playerState.value = PlayerState.CONNECTED;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the synchronization ID. This ID is used to synchronize this player on the
* client & server side. The ID is incremented only when the player changes its map.
* Movement messages that have a bad syncID are discarded.
* @return sync ID
*/
public byte getSyncID(){
synchronized( syncID ) {
return syncID[0];
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the synchronization ID. See the getter for an explanation on this ID.
* @param syncID new syncID
*/
public void setSyncID(byte syncID){
synchronized( this.syncID ) {
this.syncID[0] = syncID;
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
public PlayerOnTheScreen getScreenObject() {
return new PlayerOnTheScreen( this );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -