13.4. damage and draw

When a bullet hits a critter, it gets damaged. We have a cCritter method for this.

int cCritter::damage(int hitstrength) 
{ 
        /* If we have our shield on, or were just hit, then don’t 
            allow a hit. */ 
    if ( _shieldflag || recentlyDamaged() ) 
        return 0; 
    _lasthit_age = _age; /* Save age for use by the recentlyDamaged() 
        accessor. */ 
    _health -= hitstrength; 
    if (_health <= 0) 
    { 
        _health = 0; //Do not allow negative health. 
        die(); /* Make a delete_me service request, possibly make 
            noise or more. */ 
        return _value; //The reward for killing this critter. 
    } 
    return 0; //Not killed yet. 
} 

As you can see, damage does nothing if _shieldflag is on, or if you’ve been recently hit. By default _shieldflag is FALSE, and normally only the cCritterArmedPlayer ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.