Enemy









How do I use Enemy
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: BishopMovement.cs Copy
11  public override void ComputeBound() {
12   Node currNode = piece.Node;
13   int origRow = currNode.row;
14   int origCol = currNode.col;
15
16   Grid grid = GameManager.Instance.Grid;
17
18   //right-up
19   for (int ru = 1; ru + origRow < grid.Rows && ru + origCol < grid.Cols; ru++) {
20    int newRow = ru + origRow;
21    int newCol = ru + origCol;
22    Node newNode = grid.GetNodeAt(newRow, newCol);
23    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
24   }
25
26   //left-up
27   for (int lu = -1; origRow - lu < grid.Rows && lu + origCol >= 0; lu--) {
28    int newRow = origRow - lu;
29    int newCol = lu + origCol;
30    Node newNode = grid.GetNodeAt(newRow, newCol);
31    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
32   }
33
34   //right-bot
35   for (int rb = 1; origRow - rb >= 0 && rb + origCol < grid.Cols; rb++) {
36    int newRow = origRow - rb;
37    int newCol = rb + origCol;
38    Node newNode = grid.GetNodeAt(newRow, newCol);
39    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
40   }
41
42   //left-bot
43   for (int lb = -1; lb + origRow >= 0 && lb + origCol >= 0; lb--) {
44    int newRow = lb + origRow;
45    int newCol = lb + origCol;
46    Node newNode = grid.GetNodeAt(newRow, newCol);
47    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
48   }
49  }
File name: Movement.cs Copy
64  public bool ComputeEatPiece(Node toCheckNode) {
65   if (toCheckNode == null) return false;
66   if (!toCheckNode.EmptySpace && Rules.IsEnemy(piece, toCheckNode.Piece)) {
67    AddToCheckOrEat(toCheckNode);
68    return true;
69   }
70
71   return false;
72  }
File name: Movement.cs Copy
74  public bool ComputeMoveOrEatPiece(Node toCheckNode) {
75   if (toCheckNode == null) return false;
76   if (toCheckNode.EmptySpace) {
77    piece.AddPossibleMoves(toCheckNode);
78    return true;
79   } else if (Rules.IsEnemy(piece, toCheckNode.Piece)) {
80    AddToCheckOrEat(toCheckNode);
81    return true;
82   }
83
84   return false;
85  }
File name: Movement.cs Copy
93  public bool ComputeMoveOrEatPieceEnemyAlly(Node toCheckNode) {
94   if (toCheckNode == null) return false;
95   if (toCheckNode.EmptySpace) {
96    piece.AddPossibleMoves(toCheckNode);
97   } else if (Rules.IsEnemy(piece, toCheckNode.Piece)) {
98    AddToCheckOrEat(toCheckNode);
99    if (toCheckNode != toCheckNode.Piece.Node) {
100     return false;
101    } else {
102     return true;
103    }
104   } else {
105    return true;
106   }
107
108   return false;
109  }
File name: RookMovement.cs Copy
11  public override void ComputeBound() {
12   Node currNode = piece.Node;
13   int origRow = currNode.row;
14   int origCol = currNode.col;
15
16   Grid grid = GameManager.Instance.Grid;
17   //up
18   for (int up = 1; up + origRow < grid.Rows; up++) {
19    int newRow = up + origRow;
20    Node newNode = grid.GetNodeAt(newRow, origCol);
21    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
22   }
23
24   //left
25   for (int left = -1; left + origCol >= 0; left--) {
26    int newCol = left + origCol;
27    Node newNode = grid.GetNodeAt(origRow, newCol);
28    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
29   }
30
31   //right
32   for (int right = 1; right + origCol < grid.Cols; right++) {
33    int newCol = right + origCol;
34    Node newNode = grid.GetNodeAt(origRow, newCol);
35    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
36   }
37
38   //down
39   for (int bot = -1; bot + origRow >= 0; bot--) {
40    int newRow = bot + origRow;
41    Node newNode = grid.GetNodeAt(newRow, origCol);
42    if (ComputeMoveOrEatPieceEnemyAlly(newNode)) break;
43   }
44  }
File name: Rules.cs Copy
17  public static bool IsEnemy(Piece piece1, Piece piece2) {
18   GCPlayer p1 = GameManager.Instance.P1;
19   if (p1.Has(piece1) && !p1.Has(piece2)) return true;
20   if (p1.Has(piece2) && !p1.Has(piece1)) return true;
21   return false;
22  }
File name: GameCtrl.cs Copy
22     public void BulletHitEnemy(Transform enemy)
23     {
24         // destroy the enemy
25         Destroy(enemy.gameObject);
26     }
File name: PlayerBulletCtrl.cs Copy
20     private void OnCollisionEnter2D(Collision2D collision)
21     {
22         if (collision.gameObject.CompareTag("Enemy"))
23         {
24             GameCtrl.instance.BulletHitEnemy(collision.gameObject.transform);
25             Destroy(gameObject);
26         }
27         else if (collision.gameObject.CompareTag("Player"))
28         {
29             Destroy(gameObject);
30         }
31     }
File name: PlayerCtrl.cs Copy
168     void OnCollisionEnter2D(Collision2D other)
169     {
170         if (other.gameObject.CompareTag("Ground"))
171         {
172             isJumping = false;
173         }
174
175         if (other.gameObject.CompareTag("Enemy"))
176         {
177             Destroy(gameObject);
178         }
179     }
File name: BossHealth.cs Copy
44  void BossDestroyed(){
45   Destroy (gameObject);
46   GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent ().active = true;
47   GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent ().isBossReady = false;
48   if(GameController.instance != null && MusicController.instance != null){
49    if(GameController.instance.isMusicOn){
50     MusicController.instance.audioSource.PlayOneShot (MusicController.instance.bossExplode);
51    }
52   }
53   Instantiate (explode, transform.position, Quaternion.identity);
54   for (int i = 0; i < 5; i++) {
55    Instantiate (coin, transform.position, Quaternion.identity);
56   }
57  }

Download file with original file name:Enemy

Enemy 201 lượt xem

Gõ tìm kiếm nhanh...