Game Development Reference
In-Depth Information
*
* @return true if dead, false otherwise
*
*/
public function isDead():Boolean {
return ( m_life <= 0);
}
/**
* A Handy method to to check if monster is alive
*
* @return true if alive, false otherwise
*
*/
public function isAlive():Boolean {
return ( m_life > 0);
}
/**
* Must be called from within the main game loop
*
*/
public function update():void {
var now:Number = new Date().getMilliseconds();
var delta:Number = (now - m_lastUpdate);
respawn(delta);
heal(delta);
if ( m_life > 0 ) {
if ( m_avatar != null ) {
if ( m_avatar.isAlive() ) {
m_avatar.causeDamage(m_attackPower);
}
}
}
m_lastUpdate = now;
}
/**
* A private method to update the respawn
* called from within the update method
*
* @param delta Time difference
* between this and the previous
* update call
*
*/
protected function respawn(delta:Number):void {
// If alive, do nothing
// if the count down goes to zero or below
// restore the life
if ( isDead() ) {
m_timeToRespawn -= delta;
 
Search WWH ::




Custom Search