src/entities/Player.js
/**
	* Holds the implementation for the message handling of this game entity.
	*
	* @param {Telegram} telegram - The telegram with the message data.
	* @return {Boolean} Whether the message was processed or not.
	*/
Holds the implementation for the message handling of this game entity.
@param {Telegram} telegram - The telegram with the message data.
@return {Boolean} Whether the message was processed or not.
Holds the implementation for the message handling of this game entity . @param { Telegram } telegram - The telegram with the message data . @return { Boolean } Whether the message was processed or not .
handleMessage( telegram ) {
		switch ( telegram.message ) {
			case MESSAGE_HIT:
				const audio = this.audios.get( 'impact' + MathUtils.randInt( 1, 7 ) );
				if ( audio.isPlaying === true ) audio.stop();
				audio.play();
				this.health -= telegram.data.damage;
				this.world.uiManager.updateHealthStatus();
				if ( this.world.debug ) {
					console.log( 'DIVE.Player: Player hit by Game Entity with ID %s receiving %i damage.', telegram.sender.uuid, telegram.data.damage );
				}
				if ( this.health <= 0 && this.status === STATUS_ALIVE ) {
					this.initDeath();
					const competitors = this.world.competitors;
					for ( let i = 0, l = competitors.length; i < l; i ++ ) {
						const competitor = competitors[ i ];
						if ( this !== competitor ) this.sendMessage( competitor, MESSAGE_DEAD );
					}
					this.world.uiManager.addFragMessage( telegram.sender, this );
				} else {
					const angle = this.computeAngleToAttacker( telegram.data.direction );
					this.world.uiManager.showDamageIndication( angle );
				}
				break;
		}
		return true;
	}
handleMessage ( telegram ) { switch ( telegram . message ) { case MESSAGE_HIT : const audio = this . audios . get ( 'impact' + MathUtils . randInt ( 1 , 7 ) ) ; if ( audio . isPlaying === true ) audio . stop ( ) ; audio . play ( ) ; this . health -= telegram . data . damage ; this . world . uiManager . updateHealthStatus ( ) ; if ( this . world . debug ) { console . log ( 'DIVE.Player: Player hit by Game Entity with ID %s receiving %i damage.' , telegram . sender . uuid , telegram . data . damage ) ; } if ( this . health <= 0 && this . status === STATUS_ALIVE ) { this . initDeath ( ) ; const competitors = this . world . competitors ; for ( let i = 0 , l = competitors . length ; i < l ; i ++ ) { const competitor = competitors [ i ] ; if ( this !== competitor ) this . sendMessage ( competitor , MESSAGE_DEAD ) ; } this . world . uiManager . addFragMessage ( telegram . sender , this ) ; } else { const angle = this . computeAngleToAttacker ( telegram . data . direction ) ; this . world . uiManager . showDamageIndication ( angle ) ; } break ; } return true ; }
Holds the implementation for the message handling of this game entity.
Holds the implementation for the message handling of this game entity .
// play audio // reduce health // update UI // logging // check if the player is dead // inform all other competitors about its death // update UI