Ejemplo n.º 1
0
    public void AttackTree()
    {
        if (m_Character.m_currentWeapon.m_item != ItemType.AXE)
        {
            return;
        }

        MusicHandler.PlaySound(SoundType.AXE_SOUND);
        m_health--;
        Debug.Log("tree is attacked");
        if (m_health < 0)
        {
            gameObject.SetActive(false);
            Debug.Log("Tree is destroyed");
            SpriteManage.DESTROY_SPRITE(gameObject);
            // generate tree log after tree is cut down
            for (int i = 0; i < NUMBER_OF_TREE_LOG; i++)

            {
                GameObject temp = SpriteManage.CREATE_SPRITE(SpriteType.TREE_LOG);
                Debug.Assert(temp);
                Vector2 newPos = SpriteManage.randomAroundPoint(transform.position, 16);
                temp.transform.position = newPos;
            }
        }
    }
Ejemplo n.º 2
0
 public override void Attack()
 {
     if (!m_IsPlaced)
     {
         return;
     }
     if (m_AttackDelay <= 0)
     {
         if (m_EnemyTarget != null)
         {
             if (!m_EnemyTarget.active || m_EnemyTarget.GetComponent <AI>().getHealth() <= 0)
             {
                 m_EnemyTarget = null;
                 return;
             }
             MusicHandler.PlaySound(SoundType.SPEAR_THROW);
             m_AttackDelay = DEFAULT_ATTACK_DELAY;
             float      angle = Mathf.Atan2(m_EnemyTarget.transform.position.y - transform.position.y, m_EnemyTarget.transform.position.x - transform.position.x);
             GameObject obj   = SpriteManage.CREATE_SPRITE(SpriteType.SPEAR);
             Debug.Assert(obj);
             obj.transform.position = transform.position;
             Spear spear = obj.GetComponent <Spear>();
             spear.Init(angle, ObjectSide.OUR_SIDE);
         }
         else
         {
             m_AttackDelay = 0;
         }
     }
 }
    // angle in radian
    public void throwSpear(float angle)
    {
        if (m_Health <= 0)
        {
            return;
        }
        if (m_currentWeapon != null)
        {
            if (m_weaponDelay > 0)
            {
                return;
            }
            if (m_currentWeapon.m_Quantity <= 0)
            {
                return;
            }
            if (m_currentWeapon.m_item == ItemType.SPEAR)
            {
                m_currentWeapon.m_Quantity--;
                m_Weapons.setQuantity(m_currentWeapon);

                GameObject temp  = SpriteManage.CREATE_SPRITE(SpriteType.SPEAR);
                Spear      spear = temp.GetComponent <Spear>();
                spear.transform.position = transform.position;
                spear.Init(angle, ObjectSide.OUR_SIDE);
                MusicHandler.PlaySound(SoundType.SPEAR_THROW);
                m_weaponDelay = AXE_DELAY;
                if (m_currentWeapon.m_Quantity <= 0)
                {
                    changeWeapon(0);
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void AttackRock()
    {
        // set the selection square is show
        // if characters holding axe and clicked on  the tree in range, then tree health is -1
        if (m_Character.m_currentWeapon.m_item != ItemType.AXE)
        {
            return;
        }
        const float OFFSET   = 16;
        float       distance = Vector2.Distance(Camera.main.WorldToScreenPoint(m_Character.transform.position), Camera.main.WorldToScreenPoint(transform.position));

        MusicHandler.PlaySound(SoundType.AXE_SOUND);
        m_health--;
        Debug.Log("rock is attacked");
        if (m_health < 0)
        {
            gameObject.SetActive(false);
            Debug.Log("rock is destroyed");
            SpriteManage.DESTROY_SPRITE(gameObject);
            // generate tree log after tree is cut down
            for (int i = 0; i < NUMBER_OF_STONE; i++)

            {
                GameObject temp = SpriteManage.CREATE_SPRITE(SpriteType.STONE);
                Debug.Assert(temp);
                Vector2 newPos = SpriteManage.randomAroundPoint(transform.position, 16);
                temp.transform.position = newPos;
            }
        }
    }
Ejemplo n.º 5
0
    public override void Attack()
    {
        float distance = Vector2.Distance(transform.position, m_EnemyTarget.transform.position);

        calculateAttackDistance();
        if (transform.position.x > m_EnemyTarget.transform.position.x)
        {
            m_Facing = FACING_LEFT;
        }
        else
        {
            m_Facing = FACING_RIGHT;
        }
        // if in attack range then attack
        if (distance < m_AttackDistance)
        {
            if (m_AttackDelay <= 0)
            {
                MusicHandler.PlaySound(SoundType.RED_ENEMY_ATTACK);
                m_AttackDelay = DEFAULT_ATTACK_SPEED;
                AI ai = m_EnemyTarget.GetComponent <AI>();
                ai.setHealth(ai.getHealth() - m_Damage);
                if (ai.getHealth() <= 0)
                {
                    m_EnemyTarget = null;
                }
            }
        }
        else
        {
            float   angle  = Mathf.Atan2(m_EnemyTarget.transform.position.y - transform.position.y, m_EnemyTarget.transform.position.x - transform.position.x);
            Vector2 newPos = transform.position;
            newPos.x          += Mathf.Cos(angle) * MOVING_SPEED * Time.fixedDeltaTime;
            newPos.y          += Mathf.Sin(angle) * MOVING_SPEED * Time.fixedDeltaTime;
            transform.position = newPos;
        }
        if (m_Health <= 0)
        {
            // generate heart for player to gain health
            float ran = Random.Range(0, 101);
            if (Debug.isDebugBuild)
            {
                ran = 80;
            }
            if (ran >= 70)
            {
                var heart = SpriteManage.CREATE_SPRITE(SpriteType.HEART);
                heart.transform.position = transform.position;
            }
        }
        checkHealth();
    }
 public override void Attack()
 {
     if (m_EnemyTarget != null)
     {
         if (!m_EnemyTarget.active)
         {
             m_EnemyTarget = null;
             return;
         }
         float distance = Vector2.Distance(transform.position, m_EnemyTarget.transform.position);
         calculateAttackDistance();
         if (distance < m_AttackDistance)
         {
             if (m_AttackDelay <= 0)
             {
                 MusicHandler.PlaySound(SoundType.RED_ENEMY_ATTACK);
                 m_AttackDelay = DEFAULT_ATTACK_DELAY;
                 if (m_EnemyTarget.tag == "tree")
                 {
                     m_EnemyTarget.GetComponent <Tree>().m_health--;
                     if (m_EnemyTarget.GetComponent <Tree>().m_health <= 0)
                     {
                         SpriteManage.DESTROY_SPRITE(m_EnemyTarget);
                         m_EnemyTarget = null;
                     }
                 }
                 else if (m_EnemyTarget.tag == "stone")
                 {
                     m_EnemyTarget.GetComponent <Rock>().m_health--;
                     if (m_EnemyTarget.GetComponent <Rock>().m_health <= 0)
                     {
                         SpriteManage.DESTROY_SPRITE(m_EnemyTarget);
                         m_EnemyTarget = null;
                     }
                 }
             }
         }
         // moving to the target
         else
         {
             float   angle = Mathf.Atan2(m_EnemyTarget.transform.position.y - transform.position.y, m_EnemyTarget.transform.position.x - transform.position.x);
             Vector2 pos   = transform.position;
             pos.x += Mathf.Cos(angle) * MOVE_SPEED * Time.fixedDeltaTime;
             pos.y += Mathf.Sin(angle) * MOVE_SPEED * Time.fixedDeltaTime;
             transform.position = pos;
         }
     }
 }
Ejemplo n.º 7
0
 public void AttackByCharacter()
 {
     if (m_Character.m_currentWeapon.m_item != ItemType.SWORD && m_Character.m_currentWeapon.m_item != ItemType.AXE)
     {
         return;
     }
     {
         MusicHandler.PlaySound(SoundType.AXE_SOUND);
         if (m_Character.m_currentWeapon.m_item == ItemType.SWORD)
         {
             m_Character.setDelayWeapon(Character.SWORD_DELAY);
         }
         else
         {
             m_Character.setDelayWeapon(Character.AXE_DELAY);
         }
         m_Health -= Weapon.getWeaponDamage(m_Character.m_currentWeapon.m_item);
         Debug.Log("enemy is attacked");
     }
 }
    public void AttackByCharacter()
    {
        Character character = GameObject.Find("character").GetComponent <Character>();

        if (character.m_currentWeapon.m_item != ItemType.SWORD && character.m_currentWeapon.m_item != ItemType.AXE)
        {
            return;
        }
        {
            MusicHandler.PlaySound(SoundType.AXE_SOUND);
            if (character.m_currentWeapon.m_item == ItemType.SWORD)
            {
                character.setDelayWeapon(Character.SWORD_DELAY);
            }
            else
            {
                character.setDelayWeapon(Character.AXE_DELAY);
            }
            m_Health -= Weapon.getWeaponDamage(character.m_currentWeapon.m_item);
            Debug.Log("enemy is attacked");
        }
    }
Ejemplo n.º 9
0
    public override void Attack()
    {
        Vector2 newPos = transform.position;
        Vector2 origin = m_Castle.transform.position;
        float   radius = Vector2.Distance(transform.position, origin);

        m_CurrentAngle    += ANGLE_MOVE * Time.fixedDeltaTime;
        newPos.x           = origin.x + Mathf.Cos(m_CurrentAngle) * radius;
        newPos.y           = origin.y + Mathf.Sin(m_CurrentAngle) * radius;
        transform.position = newPos;
        if (m_AttackDelay <= 0)
        {
            m_AttackDelay = DEFAULT_ATTACK_DELAY;
            if (m_EnemyTarget != null)
            {
                var   s           = SpriteManage.CREATE_SPRITE(SpriteType.SPEAR);
                var   spear       = s.GetComponent <Spear>();
                float attackAngle = Mathf.Atan2(m_EnemyTarget.transform.position.y - newPos.y, m_EnemyTarget.transform.position.x - newPos.x);
                spear.transform.position = transform.position;
                spear.Init(attackAngle, ObjectSide.ENEMY_SIDE);
                MusicHandler.PlaySound(SoundType.SPEAR_THROW);
            }
        }
    }
Ejemplo n.º 10
0
    public override void Attack()
    {
        if (m_EnemyTarget == null)
        {
            if (m_Character.m_Health > 0)
            {
                m_EnemyTarget = m_Character.gameObject;
            }
            else
            {
                m_EnemyTarget = m_Castle.gameObject;
            }
        }

        if (m_EnemyTarget != null)
        {
            if (!m_EnemyTarget.active)
            {
                m_EnemyTarget = null;
                return;
            }
            float distance = Vector2.Distance(m_EnemyTarget.transform.position, transform.position);
            // attack
            if (distance <= ATTACK_RANGE)
            {
                if (m_UltimateAttack <= 0)
                {
                    for (int i = 0; i < MAX_SPEAR; i++)
                    {
                        GameObject spear = SpriteManage.CREATE_SPRITE(SpriteType.SPEAR);

                        float angle = i * 45 * Mathf.Deg2Rad;
                        Spear s     = spear.GetComponent <Spear>();
                        s.Init(angle, ObjectSide.ENEMY_SIDE);
                        s.m_speed = 9;

                        spear.transform.position = transform.position;
                    }
                    m_UltimateAttack = DEFAULT_ULTIMATE;
                    return;
                }
                if (m_AttackDelay <= 0)
                {
                    MusicHandler.PlaySound(SoundType.SPEAR_THROW);
                    if (m_Health < DEFAULT_HEALTH / 2)
                    {
                        m_AttackDelay = ATTACK_DELAY_PERIOD_2;
                    }
                    else
                    {
                        m_AttackDelay = ATTACK_DELAY_PERIOD_1;
                    }
                    GameObject spear = SpriteManage.CREATE_SPRITE(SpriteType.SPEAR);

                    float angle = Mathf.Atan2(m_EnemyTarget.transform.position.y - transform.position.y, m_EnemyTarget.transform.position.x - transform.position.x);
                    Spear s     = spear.GetComponent <Spear>();
                    s.Init(angle, ObjectSide.ENEMY_SIDE);
                    s.m_speed = 9;

                    spear.transform.position = transform.position;
                }
            }
            else
            {
                // update position
                float   angle  = Mathf.Atan2(m_EnemyTarget.transform.position.y - transform.position.y, m_EnemyTarget.transform.position.x - transform.position.x);
                Vector2 newPos = transform.position;
                newPos.x          += Mathf.Cos(angle) * DEFAULT_MOVE_SPEED * Time.fixedDeltaTime;
                newPos.y          += Mathf.Sin(angle) * DEFAULT_MOVE_SPEED * Time.fixedDeltaTime;
                transform.position = newPos;
            }
        }
    }