Game Development Reference
In-Depth Information
This will generate our PassiveMonster and the listing looks like the following after
inserting its own version of the causeDamage method:
package world
{
public class PassiveMonster extends Monster
{
public function PassiveMonster(
attackPower:Number,
attackRate:Number,
maxLife:Number,
respawnRate:Number,
lifeUpdateRate:Number)
{
super(attackPower,
attackRate,
maxLife,
respawnRate,
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 override function causeDamange(
damage:Number,
avatar:Avatar):void {
// If alive decrease life, check for death
if ( isAlive() ) {
// If we don't have an attacker set
// then set the attacker
// If the avatar is dead or ran away
// or left the game, the logic to reset the
// avatar is handled in the attack method
if ( m_avatar != null ) {
m_avatar = avatar;
}
m_life -= damage;
 
Search WWH ::




Custom Search