@ -44,13 +44,8 @@ const float DamageNumber::MOVE_UP_TIME=0.4f;
using enum DamageNumberType : : DamageNumberType ;
using enum DamageNumberType : : DamageNumberType ;
DamageNumber : : DamageNumber ( )
: damage ( 0 ) {
}
DamageNumber : : DamageNumber ( vf2d pos , int damage , bool friendly , DamageNumberType : : DamageNumberType type ) :
DamageNumber : : DamageNumber ( vf2d pos , int damage , bool friendly , DamageNumberType : : DamageNumberType type ) :
pos ( pos ) , damage ( damage ) , friendly ( friendly ) , type ( type ) , invertedDirection ( type = = INTERRUPT ) , riseSpd ( 20.f ) {
pos ( pos ) , damage ( damage ) , friendly ( friendly ) , type ( type ) , invertedDirection ( type = = INTERRUPT ) , riseSpd ( GetOriginalRiseSpd ( ) ) {
if ( type = = INTERRUPT | | type = = MANA_GAIN ) riseSpd = 40.f ;
RecalculateSize ( ) ;
RecalculateSize ( ) ;
}
}
@ -59,12 +54,30 @@ void DamageNumber::RecalculateSize(){
if ( ! friendly ) {
if ( ! friendly ) {
float newSize = std : : clamp ( roundf ( damageMultRatio ) , 1.0f , 4.0f ) ;
float newSize = std : : clamp ( roundf ( damageMultRatio ) , 1.0f , 4.0f ) ;
if ( type = = HEALTH_LOSS | | type = = CRIT ) riseSpd * = newSize ;
float riseSpd { GetOriginalRiseSpd ( ) } ;
if ( type = = HEALTH_LOSS | | type = = CRIT | | type = = DOT ) riseSpd * = newSize ;
size = vf2d { newSize , newSize } ;
size = vf2d { newSize , newSize } ;
}
}
}
}
void DamageNumber : : Update ( ) {
if ( pauseTime > 0 ) {
pauseTime - = game - > GetElapsedTime ( ) ;
} else {
lifetime + = game - > GetElapsedTime ( ) ;
if ( lifetime < = 1 ) {
if ( lifetime < DamageNumber : : MOVE_UP_TIME ) {
if ( invertedDirection ) {
pos . y + = riseSpd * game - > GetElapsedTime ( ) ;
} else {
pos . y - = riseSpd * game - > GetElapsedTime ( ) ;
}
}
}
}
}
void DamageNumber : : Draw ( ) {
void DamageNumber : : Draw ( ) {
# define NumberScalesWithDamage true
# define NumberScalesWithDamage true
# define NormalNumber false
# define NormalNumber false
@ -123,3 +136,31 @@ void DamageNumber::Draw(){
default : ERR ( std : : format ( " Damage Number Type {} is not implemented! THIS SHOULD NOT BE HAPPENING! " , int ( type ) ) ) ;
default : ERR ( std : : format ( " Damage Number Type {} is not implemented! THIS SHOULD NOT BE HAPPENING! " , int ( type ) ) ) ;
}
}
}
}
float DamageNumber : : GetOriginalRiseSpd ( ) {
float riseSpd { 20.f } ;
if ( type = = INTERRUPT | | type = = MANA_GAIN ) riseSpd = 40.f ;
if ( type = = DOT ) riseSpd = - 10.f ;
return riseSpd ;
}
void DamageNumber : : AddDamage ( int damageAmt ) {
if ( damageAmt < 0 ) ERR ( std : : format ( " WARNING! Trying to apply a negative damage amount to a damage counter: {}! THIS SHOULD NOT BE HAPPENING! " , damageAmt ) ) ;
damage + = damageAmt ;
}
const bool DamageNumber : : IsDead ( ) const {
return lifetime > 1.f ;
}
void DamageNumber : : SetPauseTimer ( const float pauseTime ) {
this - > pauseTime = pauseTime ;
}
void DamageNumber : : SetType ( const DamageNumberType : : DamageNumberType type ) {
this - > type = type ;
}
const DamageNumberType : : DamageNumberType DamageNumber : : GetType ( ) const {
return type ;
}