here is the code
void Player::IsHit( int monsterXPos, Direction mosterdir )
{
if( !hurt && yPos >= (GROUNDYPOS - PLAYER_HEIGHT - 20) )
{
if( mosterdir == LEFT )
{
if( monsterXPos + 10 <= xPos + 30 )
{
invincibleTimer.Start();
health -= 1;
if( health < 0 )
health = 0;
xVel -= 70;
yVel -= 5;
}
}
else
{
if( monsterXPos + 40 >= xPos + 20)
{
invincibleTimer.Start();
health -= 1;
if( health < 0 )
health = 0;
xVel += 70;
yVel -= 5;
}
}
}
if( invincibleTimer.IsStarted() == true )
{
if( invincibleTimer.GetTicks() >= 10000 )
{
invincibleTimer.Stop();
hurt = false;
}
else
hurt = true;
}
}