Beispiel #1
0
 /// <summary>
 /// Init this instance.
 /// </summary>
 protected override void Init()
 {
     base.Init();
     damageInfo = new DamageInfo(1, DamageType.HEAD_STOMP, Vector3.zero);
     enemy = transform.parent.gameObject.GetComponent<Enemy>();
     if (enemy == null) enemy = GetComponent<Enemy>();
     if (enemy == null) Debug.LogWarning ("Unable to find the Enemy that this StompOnHead is attached to. Make sure your StompOnHead is a direct child of the enemy.");
 }
 /// <summary>
 /// Pass damage from the given hazard to the CharacterHealth script.
 /// </summary>
 /// <param name="info">Information about the damage such as the hazard causing the damage.</param>
 public virtual void Damage(DamageInfo info)
 {
     if (enabled)
     {
         if (info.DamageType == DamageType.AUTO_KILL)
         {
             health.Kill();
         }
         else
         {
             health.Damage(info);
         }
     }
 }
 /// <summary>
 /// Init this instance, used for projectiles or hit boxes which are not children of a character.
 /// </summary>
 public virtual void Init(DamageInfo info, IMob character, Projectile projectile,  bool destroyOnEnemyHit, bool destroyOnSceneryHit)
 {
     this.character = character;
     if (character == null)
     {
         Debug.LogError ("A ProjectileHitBox (CharacterHitBox) must have a character");
     }
     myCollider = GetComponent<Collider2D>();
     if (myCollider == null)
     {
         Debug.LogError("A ProjectileHitBox (CharacterHitBox) must be on the same GameObject as a Collider2D");
     }
     myCollider.enabled = true;
     this.damageInfo = info;
     this.projectile = projectile;
     this.destroyOnSceneryHit = destroyOnSceneryHit;
     this.destroyOnEnemyHit = destroyOnEnemyHit;
 }
Beispiel #4
0
 /// <summary>
 /// Pass damage from the given hazard to the Enemy script.
 /// </summary>
 /// <param name="info">Information about the damage such as the hazard causing the damage.</param>
 virtual public void Damage(DamageInfo info)
 {
     enemy.Damage(info);
 }
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 override public Movement Init(Character character)
 {
     this.character = character;
     damageInfo     = new DamageInfo(damageAmount, DamageType.PHYSICAL, Vector2.zero, character);
     return(this);
 }
 /// <summary>
 /// A simple damage implementation.
 /// </summary>
 virtual protected void DoDamage(DamageInfo info)
 {
     OnDamaged(info);
 }
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 public override void DoDamage(DamageInfo info)
 {
     isDeath = false;
 }
 /// <summary>
 /// Do the damage movement
 /// </summary>
 public virtual void DoDamage(DamageInfo info)
 {
 }
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public virtual void HitCharacter(Character character, DamageInfo info)
 {
 }
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
     for (int i = 0; i < statesToMovements.Length; i++)
     {
         if (statesToMovements[i].state == EnemyState.HITTING) currentMovement = statesToMovements[i].movement;
     }
     currentMovement.HitCharacter(character, info);
 }
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
     if (bounceOnHit) speed *= -1;
 }
Beispiel #12
0
 /// <summary>
 /// Init this instance, this should be called by the attack system during Start();
 /// </summary>
 override public void Init(DamageInfo info)
 {
     base.Init(info);
     hitMobs = new List <IMob>();
 }
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     for (int i = 0; i < statesToMovements.Length; i++)
     {
         if (statesToMovements[i].state == EnemyState.DEAD) currentMovement = statesToMovements[i].movement;
     }
     currentMovement.DoDeath(info);
 }
Beispiel #14
0
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     originalHeight = enemy.Transform.position.y;
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
 }
Beispiel #15
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 override public void HitCharacter(Character character, DamageInfo info)
 {
 }
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     isDeath = false;
 }
Beispiel #17
0
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 override public Movement Init(Character character)
 {
     AssignReferences(character);
     damageInfo = new DamageInfo(damageAmount, DamageType.HEAD_STOMP, Vector2.zero, character);
     return(this);
 }
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     SetUpExplosionForce(info);
     this.isDeath = false;
 }
Beispiel #19
0
 /// <summary>
 /// Start the damage movement.
 /// </summary>
 /// <param name="info">Info.</param>
 override public void Damage(DamageInfo info, bool isDeath)
 {
     DoBobble();
     this.isDeath = isDeath;
 }
Beispiel #20
0
 /// <summary>
 /// Do the damage movement
 /// </summary>
 virtual public void DoDamage(DamageInfo info)
 {
 }
Beispiel #21
0
 /// <summary>
 /// Called when the character hits an enemy.
 /// </summary>
 /// <param name="enemy">Enemy that was hit.</param>
 /// <param name="info">Damage info.</param>
 virtual public void HitEnemy(IMob enemy, DamageInfo info)
 {
     // We don't do anything here, but other attacks might
 }
Beispiel #22
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 virtual public void DoDeath(DamageInfo info)
 {
 }
Beispiel #23
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 public virtual void DoDeath(DamageInfo info)
 {
 }
Beispiel #24
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 virtual public void HitCharacter(Character character, DamageInfo info)
 {
 }
Beispiel #25
0
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 protected virtual void Init()
 {
     damageInfo = new DamageInfo(damageAmount, damageType, transform.position);
     #if UNITY_EDITOR
     if (!damageCharacters && !damageEnemies) Debug.LogWarning("Hazard does not damage enemies or characters.");
     #endif
 }
Beispiel #26
0
 /// <summary>
 /// Start the damage movement.
 /// </summary>
 /// <param name="info">Info.</param>
 override public void Damage(DamageInfo info, bool isDeath)
 {
     animationTimer = animationLength;
     this.isDeath   = isDeath;
 }
        /// <summary>
        /// Coroutine to destory this object. You could override if you didn't want to destory
        /// for example if you have a pooling system.
        /// </summary>
        /// <param name="info">Damage info.</param>
        virtual protected IEnumerator DestroyAfterDelay(DamageInfo info)
        {
            yield return(new WaitForSeconds(destroyDelay));

            GameObject.Destroy(gameObject);
        }
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
 }
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     isDeath = true;
     if (destroyDelay > 0) StartCoroutine(DestroyAfterDelay());
 }
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
     enemy.characterCanFall = false;
     if (destroyDelay > 0) StartCoroutine(DestroyAfterDelay());
 }
 /// <summary>
 /// Kills all characters.
 /// </summary>
 protected void KillAllCharacters()
 {
     DamageInfo info = new DamageInfo(0, DamageType.TIME_EXPIRED, Vector2.zero);
     foreach (CharacterHealth c in FindObjectsOfType<CharacterHealth>())
     {
         c.Kill(info);
     }
     killSent = true;
 }
Beispiel #32
0
        /// <summary>
        /// Start the damage movement.
        /// </summary>
        /// <param name="info">Info.</param>
        override public void Damage(DamageInfo info, bool isDeath)
        {
            int tmpAnimationIndex = -1;

            this.isDeath = isDeath;
            if (isDeath)
            {
                // Find a match
                for (int i = 0; i < deathAnimations.Count; i++)
                {
                    if (deathAnimations[i].damageType == info.DamageType)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = deathAnimations[i].animationTime;
                        break;
                    }
                }
                // No match try to find type == NONE
                for (int i = 0; i < deathAnimations.Count; i++)
                {
                    if (deathAnimations[i].damageType == DamageType.NONE)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = deathAnimations[i].animationTime;
                        break;
                    }
                }
            }
            else
            {
                // Find a match
                for (int i = 0; i < damageAnimations.Count; i++)
                {
                    if (damageAnimations[i].damageType == info.DamageType)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = damageAnimations[i].animationTime;
                        break;
                    }
                }
                // No match try to find type == NONE
                for (int i = 0; i < damageAnimations.Count; i++)
                {
                    if (damageAnimations[i].damageType == DamageType.NONE)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = damageAnimations[i].animationTime;
                        break;
                    }
                }
            }
            if (tmpAnimationIndex != -1)
            {
                currentAnimation = tmpAnimationIndex;
            }
            else
            {
#if UNITY_EDITOR
                Debug.LogWarning(string.Format("Couldn't find a damage/death animation for the given damage type ({0}). Use DamageType.NONE to specify a default.", info.DamageType));
#endif
                currentAnimation = 0;
            }
        }
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 public override void DoDamage(DamageInfo info)
 {
     originalHeight = enemy.Transform.position.y;
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
 }
 /// <summary>
 /// Kills the character.
 /// </summary>
 virtual public void Kill(DamageInfo info)
 {
     health = 0;
     DoDeath(info);
 }
        /// <summary>
        /// Does a death action.
        /// </summary>
        /// <param name="action">Action.</param>
        virtual protected IEnumerator DoDeathAction(DeathAction action, DamageInfo info)
        {
            // Wait...
            if (action.delay > 0)
            {
                yield return(new WaitForSeconds(action.delay));
            }
            // Then act
            switch (action.actionType)
            {
            case DeathActionType.DESTROY_CHARACTER:
                Destroy(character.gameObject);
                break;

            case DeathActionType.RESPAWN:
                health = startingHealth;
                dying  = false;
                LevelManager.Instance.Respawn(character);
                break;

            case DeathActionType.RELOAD_SCENE:
                                        #if !UNITY_4_6 && !UNITY_4_7 && !UNITY_5_1 && !UNITY_5_2
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                                        #else
                Application.LoadLevel(Application.loadedLevel);
                                        #endif
                break;

            case DeathActionType.LOAD_ANOTHER_SCENE:
                                        #if !UNITY_4_6 && !UNITY_4_7 && !UNITY_5_1 && !UNITY_5_2
                LevelManager.PreviousLevel = SceneManager.GetActiveScene().name;
                SceneManager.LoadScene(action.supportingData);
                                        #else
                LevelManager.PreviousLevel = Application.loadedLevelName;
                Application.LoadLevel(action.supportingData);
                                        #endif
                break;

            case DeathActionType.SEND_MESSAGE:
                action.supportingGameObject.SendMessage(action.supportingData, SendMessageOptions.DontRequireReceiver);
                break;

            case DeathActionType.CLEAR_RESPAWN_POINTS:
                if (LevelManager.Instance != null)
                {
                    LevelManager.Instance.ClearRespawns();
                }
                break;

            case DeathActionType.RESET_DATA:
                foreach (Persistable persistable in action.supportingGameObject.GetComponents <Persistable>())
                {
                    persistable.ResetSaveData();
                }
                break;

            case DeathActionType.RESET_SCORE:
                ScoreManager.GetInstanceForType(action.supportingData).ResetScore();
                break;
            }
        }
Beispiel #36
0
 /// <summary>
 /// A simple destroy implementation.
 /// </summary>
 virtual protected void DoDestroy(DamageInfo info)
 {
     GetComponent <Collider2D>().enabled = false;
     OnDestroyed(info);
     StartCoroutine(DestroyAfterDelay(info));
 }