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 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;
            }
        }
    }