Пример #1
0
 //if player choose a target to attack, proceed the battle
 public void CheckChoosingTarget()
 {
     if (choosingTarget && Input.GetMouseButtonDown(0))
     {
         Lobster attacked = null;
         choosingTarget = false;
         Vector2 mousePos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
         //when attacking lobsters
         if (possibleChoice.Count > 0)
         {
             //reset Color and get attacked lobster
             foreach (Lobster lob in possibleChoice)
             {
                 lob.transform.Find("sprite").gameObject.SetActive(false);
                 //check if touched lobster
                 if (lob.MouseIsOn(mousePos))
                 {
                     attacked = lob;
                 }
             }
             if (attacked)
             {
                 Battle(attackerLobster, attacked);
             }
         }
         else//when attacking opponent directly
         {
             //reset color
             opponent.transform.Find("Arrow").gameObject.SetActive(false);
             // opponent.GetComponent<SpriteRenderer>().color = new Color(GameObject.Find("opponent").GetComponent<SpriteRenderer>().color.r,
             //  GameObject.Find("opponent").GetComponent<SpriteRenderer>().color.g,
             //  GameObject.Find("opponent").GetComponent<SpriteRenderer>().color.b,
             //  1f);
             //check if touched opponent
             RaycastHit2D result = Physics2D.Raycast(mousePos, Vector2.zero);
             //attacking enemy
             if (result && result.collider.gameObject == opponent)
             {
                 hurtSound.Play();
                 attackerLobster.canAttack = false;
                 result.collider.GetComponent <Player>().GetHurt(attackerLobster.GetClaw());
                 //enemy put a rock
                 //GetComponent<EnemyManager>().PlaceRock();
             }
         }
     }
 }
Пример #2
0
 public void Battle(Lobster attacker, Lobster attacked)
 {
     attacked.GetHurt(attacker.GetClaw());
     attacker.canAttack = false;
     if (attacker.transform.position.y < attacked.transform.position.y)
     {
         attacker.GetComponent <Animator>().Play("Attack", -1, 0);
         if (attacked.GetState() == LobsterState.Defence)
         {
             attacked.GetComponent <Animator>().Play("EnemyGetAttackedDefending", -1, 0);
         }
         else
         {
             attacked.GetComponent <Animator>().Play("EnemyGetAttacked", -1, 0);
         }
     }
     else
     {
         attacker.GetComponent <Animator>().Play("EnemyAttack", -1, 0);
         attacked.GetComponent <Animator>().Play("GetAttacked", -1, 0);
     }
 }
Пример #3
0
 //get attacker enemy and player's floor, return which player lobster enemy should attack
 public EnemyMove GetTarget(Lobster attacker, GameObject playerFloor)
 {
     if (attacker.GetClaw() == 0)
     {
         return(EnemyMove.Defend);
     }
     else        //attack is not 0, check if there are anything it can attack
     {
         int            targetIndex  = -1;
         int            targetAttack = 0;
         int            targetLevel  = 0;
         List <Lobster> attackable   = playerFloor.GetComponent <Floor>().GetAttackableLobsters();
         //player has no lobsters, let's attack the poor player
         if (attackable.Count == 0)
         {
             return(EnemyMove.AttackPlayer);
         }
         for (int index = 0; index < attackable.Count; ++index)
         {
             Lobster playerLob   = attackable[index];
             int     playerClaw  = playerLob.GetClaw();
             int     playerShell = playerLob.GetShell();
             int     playerLevel = playerLob.GetLevel();
             //check if able to attack
             if (attacker.GetClaw() >= playerLob.GetShell())
             {
                 //beat lobster with highest level
                 if (playerLevel > targetLevel)
                 {
                     targetIndex = index;
                     targetLevel = playerLevel;
                     //with the same level, beat the one with highest attack
                 }
                 else if (playerLevel == targetLevel && playerClaw > targetAttack)
                 {
                     targetIndex  = index;
                     targetAttack = playerClaw;
                     //if can only attack 1 level card, attack rock first
                 }
                 else if (playerLevel == 1 && playerLob.data.cardName == "Rock")
                 {
                     targetAttack = index;
                 }
             }
         }
         //if has a target to attack
         if (targetIndex >= 0)
         {
             return((EnemyMove)System.Array.IndexOf(playerFloor.GetComponent <Floor>().spots, attackable[targetIndex].floorAssigned));
         }
         else            //have nothing to attack
         {
             if (attacker.GetClaw() >= 2)
             {
                 return(EnemyMove.Idle);
             }
             else
             {
                 return(EnemyMove.Defend);
             }
         }
     }
 }