private void Push(Vector2Int position, Vector2Int positionDirection, Direction direction) { Vector2Int vectorDirection = (direction == Direction.Right) ? Vector2Int.right : Vector2Int.left; _gridController.GetObject(positionDirection).transform.position += VectorTransformer.Vector2IntToVector3Int(vectorDirection); _gridController.MoveObject(positionDirection, positionDirection + vectorDirection); }
public bool HasTileAt(Vector2Int position) { foreach (Tilemap tilemap in _tilemapList) { if (tilemap.HasTile(VectorTransformer.Vector2IntToVector3Int(position))) { return(true); } } return(false); }
private void Fall(Vector2Int fromPosition, Vector2Int toPosition) { if (_gridController.CellIsEmpty(toPosition)) { if (!_startFallFrom.Equals(VectorTransformer.NullPoint)) { _startFallFrom = VectorTransformer.Vector3ToVector2Int(transform.position); } _gridController.MoveObject(fromPosition, toPosition); transform.position = VectorTransformer.Vector2IntToVector3Int(toPosition); } }
public void DestroyObjectAt(Vector2Int position) { if (HasGridObjectAt(position)) { RemoveObject(position); } Vector3Int positionVector3Int = VectorTransformer.Vector2IntToVector3Int(position); foreach (Tilemap tilemap in _tilemapList) { if (tilemap.HasTile(positionVector3Int)) { tilemap.SetTile(positionVector3Int, null); } } }
public bool CellIsEmptyWithoutCharacter(Vector2Int position) { //Verify on Objects if (_gridObjects.ContainsKey(position)) { return(false); } //Verify on Tilemaps foreach (Tilemap tilemap in _tilemapList) { if (tilemap.HasTile(VectorTransformer.Vector2IntToVector3Int(position))) { return(false); } } return(true); }
IEnumerator Walk() { Vector2Int position = VectorTransformer.Vector3ToVector2Int(transform.position); //Direction newLeft = TurnLeft(_direction); newLeft = TurnLeft(_direction); Vector2Int leftPosition = VectorTransformer.DirectionToVector2Int(position, newLeft); Vector2Int frontPosition = VectorTransformer.DirectionToVector2Int(position, _direction); Debug.Log("Iniciou: " + _direction + '-' + newLeft); //Verificar se pode ir para esquerda. Se sim vira e anda if (_gridController.CellIsEmpty(leftPosition)) { _direction = newLeft; _gridController.MoveObject(position, leftPosition); transform.position = VectorTransformer.Vector2IntToVector3Int(leftPosition); Debug.Log("Go Left: " + _direction + "-" + newLeft); } //Se não anda para frente else if (_gridController.CellIsEmpty(frontPosition)) { _gridController.MoveObject(position, frontPosition); transform.position = VectorTransformer.Vector2IntToVector3Int(frontPosition); Debug.Log("Go Ahead: " + _direction + "-" + newLeft); } //Senão puder andar para esquerda nem para frente apenas vira a direita else { _direction = TurnRight(_direction); Debug.Log("Turn Right: " + _direction + "-" + newLeft); } yield return(new WaitForSeconds(0.5f)); _coroutineControl = true; }
private void Slide(Vector2Int fromPosition, Vector2Int toPosition) { _audioSourceFall.Play(); transform.position = VectorTransformer.Vector2IntToVector3Int(toPosition); _gridController.MoveObject(fromPosition, toPosition); }
IEnumerator Walk() { Vector2Int position = VectorTransformer.Vector3ToVector2Int(transform.position); IsCharacterNeighbor(position); Direction nextDirection = Direction.None; int nextNeighborPoints = -200; int actualNeighborPoints; List <Vector2Int> isGluedAt = VerifyWhereIsGlued(position); Vector2Int actualNeighborPosition = position + Vector2Int.left; if (_gridController.CellIsEmptyWithoutCharacter(actualNeighborPosition)) { actualNeighborPoints = _gridController.VerifyNeighbor(actualNeighborPosition); if (_directionFrom == Direction.Right) { actualNeighborPoints = actualNeighborPoints - 100; } int isGluedAtPoints = IsInSameWall(actualNeighborPosition, isGluedAt); int wasGluedAtPoints = IsInSameWall(actualNeighborPosition, _wasGluedAt); actualNeighborPoints = actualNeighborPoints + isGluedAtPoints + wasGluedAtPoints; if (actualNeighborPoints > nextNeighborPoints) { nextNeighborPoints = actualNeighborPoints; nextDirection = Direction.Left; } } actualNeighborPosition = position + Vector2Int.up; if (_gridController.CellIsEmptyWithoutCharacter(actualNeighborPosition)) { actualNeighborPoints = _gridController.VerifyNeighbor(actualNeighborPosition); if (_directionFrom == Direction.Down) { actualNeighborPoints = actualNeighborPoints - 100; } int isGluedAtPoints = IsInSameWall(actualNeighborPosition, isGluedAt); int wasGluedAtPoints = IsInSameWall(actualNeighborPosition, _wasGluedAt); actualNeighborPoints = actualNeighborPoints + isGluedAtPoints + wasGluedAtPoints; if (actualNeighborPoints > nextNeighborPoints) { nextNeighborPoints = actualNeighborPoints; nextDirection = Direction.Up; } } actualNeighborPosition = position + Vector2Int.right; if (_gridController.CellIsEmptyWithoutCharacter(actualNeighborPosition)) { actualNeighborPoints = _gridController.VerifyNeighbor(actualNeighborPosition); if (_directionFrom == Direction.Left) { actualNeighborPoints = actualNeighborPoints - 100; } int isGluedAtPoints = IsInSameWall(actualNeighborPosition, isGluedAt); int wasGluedAtPoints = IsInSameWall(actualNeighborPosition, _wasGluedAt); actualNeighborPoints = actualNeighborPoints + isGluedAtPoints + wasGluedAtPoints; if (actualNeighborPoints > nextNeighborPoints) { nextNeighborPoints = actualNeighborPoints; nextDirection = Direction.Right; } } actualNeighborPosition = position + Vector2Int.down; if (_gridController.CellIsEmptyWithoutCharacter(actualNeighborPosition)) { actualNeighborPoints = _gridController.VerifyNeighbor(actualNeighborPosition); if (_directionFrom == Direction.Up) { actualNeighborPoints = actualNeighborPoints - 100; } int isGluedAtPoints = IsInSameWall(actualNeighborPosition, isGluedAt); int wasGluedAtPoints = IsInSameWall(actualNeighborPosition, _wasGluedAt); actualNeighborPoints = actualNeighborPoints + isGluedAtPoints + wasGluedAtPoints; if (actualNeighborPoints > nextNeighborPoints) { nextNeighborPoints = actualNeighborPoints; nextDirection = Direction.Down; } } Vector2Int toPosition = VectorTransformer.DirectionToVector2Int(position, nextDirection); _gridController.MoveObject(position, toPosition); transform.position = VectorTransformer.Vector2IntToVector3Int(toPosition); _directionFrom = nextDirection; _wasGluedAt = isGluedAt; yield return(new WaitForSeconds(0.5f)); _coroutineControl = true; }
private void Slide(Vector2Int fromPosition, Vector2Int toPosition) { transform.position = VectorTransformer.Vector2IntToVector3Int(toPosition); _gridController.MoveObject(fromPosition, toPosition); }