Game Development Reference
In-Depth Information
* @param lifeUpdateRate
*
*/
public function Monster(attackPower:Number,
maxLife:Number,
respawnRate:Number,
lifeUpdateRate:Number)
{
// Simply initialize the class properties
// with what is passed in
m_attackPower = attackPower;
m_maxLife = maxLife;
m_life = m_maxLife;
m_respawnRate = respawnRate;
m_lifeRestoreRate = lifeUpdateRate;
}
/**
* This method could be called by another place
* in the game code to inflict damage to the monster
* by an avatar
*
* @param damage Amount of damage
* @param avatar The attacking avatar
*
*/
public function causeDamange(damage:Number,
avatar:Avatar):void {
// If alive decrease life, check for death
if ( isAlive() ) {
m_avatar = avatar;
m_life -= damage;
if ( isDead() ) {
death();
}
}
}
/**
* A private method that will reset the
* count down timer to respawn.
*
*/
protected function death():void {
if ( isDead() ) {
m_avatar = null; // forget the attacker
m_timeToRespawn = m_respawnRate;
}
}
/**
* A Handy method to to check if monster is dead
 
Search WWH ::




Custom Search