title: How do I make an enemy damage me instead of killing me?
body: <p>I'm using OpenGl and C.
  I want the player to lose some health, when he gets in the vicinity of the enemy, but only lose the health once. Then if the player leaves that vicinity and comes back he loses the rest of the health. There is a global variable <code>pHealth =100;</code></p>
  <pre class="lang-c prettyprint-override"><code>void damage()
  {
      int dmg =50;
      pHealth-=dmg;
      if(pHealth ==0)
          {
              gameState=4;
          }       
  }
  
  
  void drawSprite()
  {
      int x;
      int y;
      int s;
      if(px&lt;sp[0].x+30 &amp;&amp; px&gt;sp[0].x-30&amp;&amp; py&lt;sp[0].y+30&amp;&amp;py&gt;sp[0].y-30) // pick up key
          {
              sp[0].state=0;
          }
          if(px&lt;sp[1].x+30 &amp;&amp; px&gt;sp[1].x-30&amp;&amp; py&lt;sp[1].y+30&amp;&amp;py&gt;sp[1].y-30) // enemy damage
          {
              damage();
                          
          }
  </code></pre>
  <p>This just kills me instantly please help</p>