public void DetectMap(int moveAmount, Point p) { if (moveAmount == 0) { return; } Point[] directions = { Point.up, Point.right, Point.down, Point.left }; foreach (Point dir in directions) { Point next = Point.add(p, dir); if (next.x >= Map.Instance.width || next.y >= Map.Instance.height || next.x < 0 || next.y < 0) { continue; } if (Map.Instance.getNodeAtPoint(next).value == 0) { MapNodePiece piece = Map.Instance.getNodeAtPoint(next).getPiece(); Color tmp = piece.sprite.color; piece.sprite.color = new Color(tmp.r, tmp.g, tmp.b, 1); DetectMap(moveAmount - 1, next); continue; } else if (Map.Instance.getNodeAtPoint(next).value == 1) { MapNodePiece piece = Map.Instance.getNodeAtPoint(next).getPiece(); Color tmp = piece.sprite.color; piece.sprite.color = new Color(tmp.r, tmp.g, tmp.b, 1); continue; } else if (Map.Instance.getNodeAtPoint(next).value == 2) { MapNodePiece piece = Map.Instance.getNodeAtPoint(next).getPiece(); Color tmp = piece.sprite.color; piece.sprite.color = new Color(tmp.r, tmp.g, tmp.b, 1); NormalEnemy enemy = piece.GetComponentInParent <NormalEnemy>(); if (enemy != null) { SpriteRenderer sprite = enemy.GetComponent <SpriteRenderer>(); Color tmp2 = sprite.color; sprite.color = new Color(tmp2.r, tmp2.g, tmp2.b, 1); } else { TreasureChestEnemy treasureChestEnemy = piece.GetComponentInParent <TreasureChestEnemy>(); if (treasureChestEnemy != null) { SpriteRenderer sprite = treasureChestEnemy.GetComponent <SpriteRenderer>(); Color tmp2 = sprite.color; sprite.color = new Color(tmp2.r, tmp2.g, tmp2.b, 1); } } continue; } } }
void StateAttackNeedToDo() { if (!attackReady) { uiState.ChangeState("攻擊選択"); UpdateIndex(); Point[] directions = { Point.up, Point.right, Point.down, Point.left }; foreach (Point dir in directions) { Point next = Point.add(index, dir); if (next.x >= Map.Instance.width || next.y >= Map.Instance.height || next.x < 0 || next.y < 0) { continue; } if (/*Map.Instance.getNodeAtPoint(next).value == 0 ||*/ Map.Instance.getNodeAtPoint(next).value == 2) { canAttackList.Add(next); } } ChangeGridColor(canAttackList, Color.green); attackReady = true; } else { if (canAttackList.Count == 0) { hasAttacked = true; } if (Input.GetMouseButton(0) && !clickOnce) { clickOnce = true; var hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0f); MapNodePiece piece = null; if (hit.transform != null) { piece = hit.transform.GetComponent <MapNodePiece>(); } if (piece == null) { return; } if (!Map.Instance.isContainPointInPointList(canAttackList, piece.index)) { return; } var boss = piece.GetComponentInParent <Boss>(); if (boss != null && boss.currentWeakPoint == piece) { var damageText = ObjectPool.TakeFromPool("Damage"); damageText.position = boss.transform.position; var ui = damageText.GetComponent <UINumberPopUp>(); ui.amount = ProcessedData.Instance.atk * 2; ui.ShowDamage(); boss.currentHP -= ProcessedData.Instance.atk * 2; boss.Dead(); } else { Enemy enemy = piece.GetComponentInParent <Enemy>(); var damageText = ObjectPool.TakeFromPool("Damage"); damageText.position = enemy.transform.position; var ui = damageText.GetComponent <UINumberPopUp>(); ui.amount = ProcessedData.Instance.atk; ui.ShowDamage(); enemy.currentHP -= ProcessedData.Instance.atk; enemy.Dead(); } hasAttacked = true; } else if (!Input.GetMouseButton(0) && clickOnce) { clickOnce = false; } } }