Trying to make my character invulnerable after taking damage

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 3199 Views - Last Post: 25 May 2012 - 04:02 AM

#1 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:03 AM

Well, it is as simple as that, I'm really new at coding and it's probably an easy problem :>

Sorry for doublepost, but also wanting him to blink for like 3 seconds and also being invulnerable for said time.
Is This A Good Question/Topic? 0
  • +

Replies To: Trying to make my character invulnerable after taking damage

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:03 AM

That pretty much doesn't tell anyone what is going on. Is this a program you built? Are you trying to mod someone else's program? If it's the former what does the setup look like for the class? How is the class defined to deal with damage? Etc.. DETAILS!
Was This Post Helpful? 0
  • +
  • -

#3 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:07 AM

It's a little game I'm trying to make for fun, and the damage thingy is just 3 lifes, and when the player hits a deadly tile/sprite then "life--1;".
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:10 AM

Okay.. that moves us.. sort of? forward.. I still don't know how you are tracking health, determining death, or operating with your character's class.

That still needs to be seen.. preferably with your code.
Was This Post Helpful? 0
  • +
  • -

#5 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:17 AM

Well, I'll just write everything that has the word"life" in it, that should be enough
 

In LoadContent

Ugg.life = 3;





void Die()
        {
            Ugg.life--;
            Ugg.velocity.Y -= 50;
            Ugg.velocity.X -= 50;
            
            if (Ugg.life == 0)
            {
                status = GameState.GameOver;
            }

            
        }

In Draw
if (status == GameState.Running)
            {
                testMap.Draw();
                Ugg.Draw();
                dino.Draw();
                for (int i = 0; i < Ugg.life; i++)
                {
                    Heart.position.X = 10 + i * Heart.bounds.Width;
                    Heart.position.Y = 5;
                    Heart.Draw();
                }

            }  




Ugg is the name of the character, and Heart is obviously the heart :>

Life**, not heart
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:27 AM

Another shuffle forward.. ah.. hmmm... mmmmmmmmmmm... Okay I am not sure what's going on in there.

How about this I'll just spout off my idea and you go implement it.

It starts with a global boolean as a flag.. something like "_bInvincible".

Now hunt the code down that says "when user touches a bad cell take off life". Inside that method have it check to see if "_bInvincible = true". If the variable is true then do *NOT* do the code to take off the life..
Was This Post Helpful? 0
  • +
  • -

#7 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:35 AM

Something like this?
void Die()
        {
            if (invincible == true )
            {
                
            }
            else 
            {
                Ugg.life--;
            }
            Ugg.velocity.Y -= 50;
            Ugg.velocity.X -= 50;
            
            if (Ugg.life == 0)
            {
                status = GameState.GameOver;
            }

            
        }


I have "hits" code like this
  if (Ugg.Hits(enemy))
                {
                    
                    Die();
                }




Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:37 AM

This might be the simple way to look at it but...

If you want it to be invincible, then don't count any damage. Just stop counting down the health, and damage: It would then be immortal.
Was This Post Helpful? 0
  • +
  • -

#9 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:41 AM

Sounds easy, but since I'm new at coding I have no idea how to do that, and I don't know how to do it for three seconds either.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:42 AM

Quote

Something like this?

Sure... what happens when you test that code out?
Was This Post Helpful? 0
  • +
  • -

#11 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:44 AM

I die instantly.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:50 AM

Bwahahaha.. okay. Well slap a break point in your code and step through it. Perhaps you need something else besides the "Ugg.life--;" in the 'else' part.
Was This Post Helpful? 0
  • +
  • -

#13 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 11:56 AM

I have no idea how a breakpoint works, but do you have a suggestion what to use instead of "ugg.life--;"?
Just have in mind that I'm really new at coding.:>
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,744
  • Joined: 12-June 08

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 12:02 PM

I have no idea.. the code you showed me was incomprehensible as a whole.

Debugging
Was This Post Helpful? 0
  • +
  • -

#15 TheEvilKiwi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 12

Re: Trying to make my character invulnerable after taking damage

Posted 24 May 2012 - 12:03 PM

It would be easier if you could explain what part of the code you needed:<
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3