Sign in to follow this  

Trying to make an "invincible" player state

This topic is 2324 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
[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;
}
}
[/code]

Share this post


Link to post
Share on other sites
Your going to have to put:
[code]

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

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

This topic is 2324 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this