Jump to content
  • Advertisement
Sign in to follow this  
nano511

Trying to make an "invincible" player state

This topic is 2539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want the player to be invincible for a short time after he is hit. Right now, after he is hit he becomes invinsible forever.

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;
}
}

Share this post


Link to post
Share on other sites
Advertisement
Your going to have to put:


if( invincibleTimer.IsStarted() == true )
{
if( invincibleTimer.GetTicks() >= 10000 )
{
invincibleTimer.Stop();
hurt = false;
}
else
hurt = true;
}


in an update function or something. The reason why is that no time will pass (maybe half a millisecond or less), from where you start the timer to where that code above is called, since they are in the same function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!