public RequestedAction Update(CharacterScript character) { RequestedAction actions = new RequestedAction(); if (Input.GetKeyDown(KeyCode.Z)) { actions.Move = new Vector2Int(0, 1); } else if (Input.GetKeyDown(KeyCode.S)) { actions.Move = new Vector2Int(0, -1); } else if (Input.GetKeyDown(KeyCode.Q)) { actions.Move = new Vector2Int(-1, 0); } else if (Input.GetKeyDown(KeyCode.D)) { actions.Move = new Vector2Int(1, 0); } actions.DropBomb = Input.GetKeyDown(KeyCode.Space); return(actions); }
public RequestedAction Update(CharacterScript character) { _delay += Time.deltaTime; RequestedAction actions = new RequestedAction(); if (_delay <= 0.3f) { return(actions); } _delay = 0; Vector2Int[] possibleDirections = { new Vector2Int(1, 0), new Vector2Int(-1, 0), new Vector2Int(0, 1), new Vector2Int(0, -1) }; List <Vector2Int> validDirections = new List <Vector2Int>(); foreach (Vector2Int direction in possibleDirections) { Vector2Int pos = character.Position + direction; if (GameManagerScript.Instance.Map.CanMoveCharacterToPos(pos.x, pos.y)) { validDirections.Add(direction); } } int randomValue = _random.Next(validDirections.Count + (character.Bomb.IsReady ? 1 : 0)); if (randomValue < validDirections.Count) { actions.Move = validDirections[_random.Next(validDirections.Count)]; actions.DropBomb = false; } else { actions.Move = Vector2Int.zero; actions.DropBomb = true; } return(actions); }