示例#1
0
    /*
     * public void setAttackDistanceIndex() {
     *  int a = GameManager.Instance.getUnitPosXIndex(selectedSoldier.name);
     *  int b = GameManager.Instance.getUnitPosYIndex(selectedSoldier.name);
     *  SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent<Unit>().m_pSoldier;
     *  if (mySoldier.getAttackDistance() == 1) {
     *      if (b % 2 == 1)
     *      {
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *      }
     *      else
     *      {
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b + 1);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *      }
     *  } else if (mySoldier.getAttackDistance() == 2) {
     *      if (b % 2 == 1)
     *      {
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a + 2, b);
     *          checkEnemyWithinAttackDistance(a + 2,b - 1);
     *          checkEnemyWithinAttackDistance(a + 1, b - 2 );
     *          checkEnemyWithinAttackDistance(a,b-2);
     *          checkEnemyWithinAttackDistance(a-1,b-2 );
     *          checkEnemyWithinAttackDistance(a-1,b-1 );
     *          checkEnemyWithinAttackDistance(a-2,b );
     *          checkEnemyWithinAttackDistance(a-1,b+1 );
     *          checkEnemyWithinAttackDistance(a - 1,b+2 );
     *          checkEnemyWithinAttackDistance(a,b+2 );
     *          checkEnemyWithinAttackDistance(a + 1,b + 2);
     *          checkEnemyWithinAttackDistance(a + 2, b + 1);
     *
     *      }
     *      else
     *      {
     *          checkEnemyWithinAttackDistance(a, b + 1);
     *          checkEnemyWithinAttackDistance(a + 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b + 1);
     *          checkEnemyWithinAttackDistance(a - 1, b);
     *          checkEnemyWithinAttackDistance(a - 1, b - 1);
     *          checkEnemyWithinAttackDistance(a, b - 1);
     *          checkEnemyWithinAttackDistance(a, b);
     *          checkEnemyWithinAttackDistance(a+2, b);
     *          checkEnemyWithinAttackDistance(a+1,b-1 );
     *          checkEnemyWithinAttackDistance(a+1,b-2 );
     *          checkEnemyWithinAttackDistance(a,b-2 );
     *          checkEnemyWithinAttackDistance(a-1,b-2 );
     *          checkEnemyWithinAttackDistance(a-2,b-1 );
     *          checkEnemyWithinAttackDistance(a-2, b);
     *          checkEnemyWithinAttackDistance(a-2,b+1 );
     *          checkEnemyWithinAttackDistance(a-1,b+2 );
     *          checkEnemyWithinAttackDistance(a,b+2 );
     *          checkEnemyWithinAttackDistance(a+1, b+2);
     *          checkEnemyWithinAttackDistance(a+1, b+1);
     *      }
     *  }
     * }
     *
     *
     * void checkEnemyWithinAttackDistance(int x, int y) {
     *  int enemyXindex = GameManager.Instance.getUnitPosXIndex(preEnemyObject.name);
     *  int enemyYindex = GameManager.Instance.getUnitPosYIndex(preEnemyObject.name);
     * }
     */

    //升级,最大血量和当前血量各加5
    public void addHealth()
    {
        if (selectedSoldier.GetComponent <Unit>() == null || selectedSoldier == null)
        {
            return;
        }
        if (selectedSoldier.GetComponent <Unit>().beenUpgraded == false)
        {
            if (GameManager.Instance.getTurn() == 0)
            {
                if (selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp() > m_player1.getXP())
                {
                    return;
                }
                else
                {
                    SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent <Unit>().m_pSoldier;
                    mySoldier.modifyMaxHP(5);
                    mySoldier.modifyHP(5);
                    selectedSoldier.GetComponent <Unit>().beenUpgraded = true;
                    GameObject popText = Instantiate(floatingText, selectedSoldier.transform.position, Quaternion.identity);
                    popText.GetComponent <TextMesh>().text  = "Max HP + 5";
                    popText.GetComponent <TextMesh>().color = Color.green;
                    SoundEffectManager.Instance.playAudio(2);
                    m_player1.modifyXP(-selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp());
                }
            }
            else if (GameManager.Instance.getTurn() == 1)
            {
                if (selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp() > m_player2.getXP())
                {
                    return;
                }
                else
                {
                    SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent <Unit>().m_pSoldier;
                    mySoldier.modifyMaxHP(5);
                    mySoldier.modifyHP(5);
                    selectedSoldier.GetComponent <Unit>().beenUpgraded = true;
                    GameObject popText = Instantiate(floatingText, selectedSoldier.transform.position, Quaternion.identity);
                    popText.GetComponent <TextMesh>().text  = "Max HP + 5";
                    popText.GetComponent <TextMesh>().color = Color.green;
                    SoundEffectManager.Instance.playAudio(2);
                    m_player2.modifyXP(-selectedSoldier.GetComponent <Unit>().m_pSoldier.getXPToLevelUp());
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x == destination.x && transform.position.y == destination.y)
        {
            if (bMoving)
            {
                bMoving = false;
                whenUnitFirstArriveDestination();
            }
        }
        else
        {
            bMoving = true;
        }


        Vector2 dir      = new Vector2(destination.x - transform.position.x, destination.y - transform.position.y);
        Vector2 velocity = dir.normalized * speed * Time.deltaTime;

        velocity = Vector2.ClampMagnitude(velocity, dir.magnitude);

        transform.Translate(velocity);

        gameObject.GetComponent <SpriteRenderer>().sprite = UIManager.Instance.unitSprites[spriteIndex];

        thisUnitHasBeenClicked = false;

        if (m_pSoldier != null && m_pSoldier.getCurrentHP() <= 0)
        {
            int money = m_pSoldier.getMoneyByKillingEnemy();
            int xp    = m_pSoldier.getXPByKillingEnemy();
            if (unitAlign == 0)
            {
                m_player2.setMoney(money + m_player2.getMoney());
                m_player2.setXP(xp + m_player2.getXP());
            }
            else if (unitAlign == 1)
            {
                m_player1.setMoney(money + m_player1.getMoney());
                m_player1.setXP(xp + m_player1.getXP());
            }
            GameManager.Instance.modifyUnitDic(unitAlign, gameObject.name);
            Destroy(gameObject);
        }
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (GameManager.Instance == null)
        {
            return;
        }
        int currentAlign = GameManager.Instance.getTurn();

        if (currentAlign == 0)
        {
            if (m_Player1 == null)
            {
                return;
            }
            UIManager.Instance.alignImage.sprite = m_Player1.getAlignImage();
            UIManager.Instance.money.text        = m_Player1.getMoney().ToString();
            UIManager.Instance.level.text        = m_Player1.getLevel().ToString();
            UIManager.Instance.xp.text           = m_Player1.getXP().ToString();
            m_Player1.checkLevel();
            m_Player1.unlockSoldierTypes();
        }
        else if (currentAlign == 1)
        {
            if (m_Player2 == null)
            {
                return;
            }
            UIManager.Instance.alignImage.sprite = m_Player2.getAlignImage();
            UIManager.Instance.money.text        = m_Player2.getMoney().ToString();
            UIManager.Instance.level.text        = m_Player2.getLevel().ToString();
            UIManager.Instance.xp.text           = m_Player2.getXP().ToString();

            m_Player2.checkLevel();
            m_Player2.unlockSoldierTypes();
        }
    }