Game Development Reference
In-Depth Information
if ( m_timeToRespawn < 0 ) {
m_life = m_maxLife;
}
}
}
/**
* A private method to heal the monster
* Called from within the update method
*
* @param delta Time difference
* between this and the previous
* update call
*
*/
protected function heal(delta:Number):void {
// If monster has already full life, do nothing
// else, if the countdown has reached zero
// award a life point.
if ( m_life < m_maxLife ) {
m_lifeRestore -= delta;
if ( m_lifeRestore < 0 ) {
m_life++; // Assume a life unit is 1 !!
// avoid going over the max life.
if ( m_life > m_maxLife )
m_life = m_maxLife;
m_lifeRestore = m_lifeRestoreRate;
}
}
}
}
}
We see that in the properties section, we define all the needed properties and
they are initialized in the class constructor. Note that when you create your army of
monsters, you are creating a number of objects of this class similar to the next code:
var m:Monster = new Monster(10, 10, 10, 10);
Each of the objects has its own copy of properties and any modification that happens
to these properties is independent of other monster objects, so each monster can be at
different levels of life, attacker, etc.
 
Search WWH ::




Custom Search