/* * 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()); } } } }
//左键攻击 void pressLeftMouseButtonToAttack(GameObject enemyObj) { if (Input.GetMouseButtonUp(0)) { if (enemyObj.GetComponent <Unit>() == null || selectedSoldier.GetComponent <Unit>() == null) { return; } SoldierType.Soldiers thisEnemyObj = enemyObj.GetComponent <Unit>().m_pSoldier; SoldierType.Soldiers mySoldier = selectedSoldier.GetComponent <Unit>().m_pSoldier; int attack = mySoldier.getAttack(); Debug.Log("attack: " + attack); int defense = thisEnemyObj.getDefense(); if (defense > 0) { if (attack > defense) { attack -= defense; thisEnemyObj.setDefense(0); } else { attack = 0; thisEnemyObj.modifyDefense(-attack); } } thisEnemyObj.modifyHP(-attack); GameObject floatingTextObj = Instantiate(floatingText, enemyObj.transform.position, Quaternion.identity); floatingTextObj.GetComponent <TextMesh>().text = "-" + attack.ToString(); Instantiate(bloodPS, enemyObj.transform.position, Quaternion.identity); int selectedSoldierType = selectedSoldier.GetComponent <Unit>().entityType; //攻击音效 if (selectedSoldierType == 1 || selectedSoldierType == 2 || selectedSoldierType == 3) { SoundEffectManager.Instance.playAudio(5); } else if (selectedSoldierType == 4) { SoundEffectManager.Instance.playAudio(8); } else if (selectedSoldierType == 5 || selectedSoldierType == 7) { SoundEffectManager.Instance.playAudio(6); } else if (selectedSoldierType == 6) { SoundEffectManager.Instance.playAudio(9); } else if (selectedSoldierType == 8) { SoundEffectManager.Instance.playAudio(10); } selectedSoldier.GetComponent <Unit>().m_pSoldier.modifyCurrentMoveStep(-1); myCamShakeScript.shake(0.15f, 0.3f); //bCancelAttackMode = true; // actionModeName = null; destroyAttackArrow(); attackEndFrame = Time.frameCount; //Reset(); } }
//当士兵到达目的地之后,绿色消失 void whenUnitFirstArriveDestination() { if (thisUnitHasBeenClicked == false) { for (int i = 0; i < greenTiles.Count; i++) { greenTiles[i].GetComponent <SpriteRenderer>().color = Color.white; } greenTiles.Clear(); } //thisUnitHasBeenClicked = false; GameObject pTile = GameObject.Find("Terrain_" + destinationXIndex.ToString() + "_" + destinationYIndex.ToString()); int spriteType = pTile.GetComponent <TileScript>().spriteType; //碰到金矿图,金钱+15 if (spriteType == 4) { if (GameManager.Instance.getTurn() == 0) { m_player1.modifyMoney(15); } else if (GameManager.Instance.getTurn() == 1) { m_player2.modifyMoney(15); } pTile.GetComponent <SpriteRenderer>().sprite = GameManager.Instance.terrainSprites[3]; pTile.GetComponent <TileScript>().spriteType = 3; GameObject popText = Instantiate(floatingText, transform.position, Quaternion.identity); popText.GetComponent <TextMesh>().text = "Money+$15"; popText.GetComponent <TextMesh>().color = Color.yellow; SoundEffectManager.Instance.playAudio(0); } //碰到奶牛图,血量+10 if (spriteType == 5) { m_pSoldier.modifyHP(10); pTile.GetComponent <SpriteRenderer>().sprite = GameManager.Instance.terrainSprites[0]; pTile.GetComponent <TileScript>().spriteType = 0; GameObject popText = Instantiate(floatingText, transform.position, Quaternion.identity); popText.GetComponent <TextMesh>().text = "HP+10"; popText.GetComponent <TextMesh>().color = Color.green; SoundEffectManager.Instance.playAudio(1); } m_pSoldier.setCurrentMoveStep(m_pSoldier.getCurrentMoveStep() - 1); //到达终点 if (GameManager.Instance.getTurn() == 0) { if (destinationXIndex == 7 && destinationYIndex == 11) { UIManager.Instance.endingScenePanel.SetActive(true); UIManager.Instance.endingScenePanel.GetComponent <Image>().sprite = UIManager.Instance.orangeWin; } } else if (GameManager.Instance.getTurn() == 1) { if (destinationXIndex == 7 && destinationYIndex == 0) { UIManager.Instance.endingScenePanel.SetActive(true); UIManager.Instance.endingScenePanel.GetComponent <Image>().sprite = UIManager.Instance.purpleWin; } } }