Ejemplo n.º 1
0
    private Vector3 GetMoveDirection(Vector3 TargetTile)
    {
        GameField.TileType exclude = GameField.TileType.Wall | GameField.TileType.CageDoor;
        if (this._isReturning || this._leavingCage)
        {
            // We need to be able to pass through the Cage-Door when Returning/Leaving
            exclude ^= GameField.TileType.CageDoor;
        }
        // Where are we?
        float   shortestDistance = float.MaxValue;
        Vector3 nextDirection    = Vector3.zero;
        Tile    currentTile      = this._map.GetTileAt(transform.position);

        foreach (KeyValuePair <Vector3, Tile> direction in currentTile.Around())
        {
            if (direction.Key != -this._currentDirection)
            {
                // It's not the opposite direction
                if ((exclude & direction.Value.Type) != direction.Value.Type)
                {
                    // The tile is a valid option:
                    float distance = Vector3.Distance(direction.Value.Position, TargetTile);
                    if (distance < shortestDistance)
                    {
                        nextDirection    = direction.Key;
                        shortestDistance = distance;
                        _inTeleporter    = (direction.Value.Type == GameField.TileType.Teleporter);
                    }
                }
            }
        }
        // Only turn if we're around the middle of the hallway
        if (transform.position.IsCenteredOn(currentTile, this._currentDirection))
        {
            // Check if we moved to the next field:
            if (this._currentTile == this._map.GetTileAt(transform.position))
            {
                // A change of direction is only allowed once per field!
                return(_currentDirection);
            }
            else
            {
                this._currentTile      = this._map.GetTileAt(transform.position);
                this._currentDirection = nextDirection;
            }
        }
        return(this._currentDirection);
    }
Ejemplo n.º 2
0
 private void Init(int row, int col)
 {
     this.Row = row;
     this.Column = col;
     this.Type = this._map.Map[row][col];
     this.Position = new Vector3(
         col * this._map.TileSize + (this._map.TileSize / 2),
         0,
         -(row * this._map.TileSize + (this._map.TileSize / 2))
     );
 }