Ejemplo n.º 1
0
    /// <summary>
    /// Returns the corresponding direction of the rotation of a tile
    /// </summary>
    /// <param name="_tile">The input tile</param>
    /// <returns>The direction that tile is facing</returns>
    public static btTile.DIRECTION TileRotationToDirection(btTile _tile)
    {
        float zrot = _tile.transform.rotation.eulerAngles.z;

        /// Clamp the rotation
        while (zrot >= 360.0f)
        {
            zrot -= 360.0f;
        }
        while (zrot < 0.0f)
        {
            zrot += 360.0f;
        }

        if (zrot >= 45.0f && zrot < 135.0f)
        {
            return(btTile.DIRECTION.WEST);
        }
        else if (zrot >= 135.0f && zrot < 225.0f)
        {
            return(btTile.DIRECTION.SOUTH);
        }
        else if (zrot >= 225.0f && zrot < 315.0f)
        {
            return(btTile.DIRECTION.EAST);
        }
        else
        {
            return(btTile.DIRECTION.NORTH);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Resets all tiles back to their original positions and states
    /// </summary>
    public void ResetTiles()
    {
        for (int y = 0; y < instance.tilesVertical; ++y)
        {
            for (int x = 0; x < instance.tilesHorizontal; ++x)
            {
                btBoardSpace space = instance.tileGrid[y][x];

                for (int i = 0; i < space.tiles.Count; ++i)
                {
                    btTile tile = space.tiles[i];

                    if (tile.initialSpace != space)
                    //if ( tile.xInitial != x || tile.yInitial != y )
                    {
                        this.MoveTileToSpace(tile, tile.initialSpace, false, btTile.DIRECTION.NORTH);
                    }

                    tile.direction = tile.initialDirection;
                    tile.tileState = btTile.TILESTATE.NONE;
                    tile.ResetUpdateValues();
                    this.ResetTilePosition(tile);
                }
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Moves "tile" to "space" in the input direction
    /// </summary>
    /// <param name="_tile">The tile to be moved</param>
    /// <param name="_space">The space to move the tile to</param>
    /// <param name="_runCallbacks">Should callbacks be run on the tiles (false when resetting tiles, true during normal gameplay)</param>
    /// <param name="_movementDirection">The direction that the tile is moving in (used for callbacks)</param>
    private void MoveTileToSpace(btTile _tile, btBoardSpace _space, bool _runCallbacks, btTile.DIRECTION _movementDirection)
    {
        btBoardSpace oldSpace = _tile.currentSpace;        //this.GetSpace( _tile.xIndex, _tile.yIndex );

        _tile.currentSpace.tiles.Remove(_tile);
        //_tile.xIndex = _space.x;
        //_tile.yIndex = _space.y;
        _tile.currentSpace = _space;
        _space.tiles.Add(_tile);

        if (_runCallbacks == true)
        {
            if (oldSpace != null)
            {
                foreach (btTile oldTile in oldSpace.tiles)
                {
                    if (oldTile != _tile)
                    {
                        oldTile.OnMoveableTileExit(_tile, _movementDirection);
                    }
                }
            }

            foreach (btTile newTile in _space.tiles)
            {
                if (newTile != _tile)
                {
                    newTile.OnMoveableTileEnter(_tile, _movementDirection);
                }
            }
        }

        this.ResetTilePosition(_tile);
    }
Ejemplo n.º 4
0
 public btTileMovement(btTile _tile, int _newX, int _newY, btTile.DIRECTION _movementDirection)
 {
     this.tile      = _tile;
     this.newX      = _newX;
     this.newY      = _newY;
     this.direction = _movementDirection;
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Adds a movement for "tile" in "direction", "steps" number of spaces (default of one)
    /// </summary>
    /// <param name="_tile">The tile to be moved</param>
    /// <param name="_direction">The direction to move the tile</param>
    /// <param name="_steps">The number of steps that the tile is being moved (default: 1)</param>
    public void AddTileMovementInDirection(btTile _tile, btTile.DIRECTION _direction, int _steps = 1)
    {
        Vector2 directionVector = DirectionAsVector(_direction) * _steps;
        int     newX            = _tile.currentSpace.x + (int)directionVector.x;
        int     newY            = _tile.currentSpace.y + (int)directionVector.y;

        this.AddTileMovement(_tile, newX, newY, _direction);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Moves "tile" to the space in the given
    /// </summary>
    /// <param name="_tile">The tile to be moved</param>
    /// <param name="_x">The x index of the space to move to</param>
    /// <param name="_y">The y index of the space to move to</param>
    /// <param name="_runCallbacks">Should callbacks be run on the tiles (false when resetting tiles, true during normal gameplay)</param>
    /// <param name="_movementDirection">The direction that the tile is moving in (used for callbacks)</param>
    private void MoveTileToSpaceIndex(btTile _tile, int _x, int _y, bool _runCallbacks, btTile.DIRECTION _movementDirection)
    {
        btBoardSpace space = this.GetSpace(_x, _y);

        if (space == null)
        {
            Debug.LogError("Cannot move tile \"" + _tile.name + "\" to (" + _x + ", " + _y + "): Invalid space index", _tile);
            return;
        }
        this.MoveTileToSpace(_tile, space, _runCallbacks, _movementDirection);
    }
Ejemplo n.º 7
0
    public override void OnMoveableTileExit(btTile _tile, DIRECTION _enterDirection)
    {
        if (_tile as btBoulderTile != null && this.wallsToToggle != null)
        {
            this.texture.material = this.upMaterial;

            foreach (btToggleWallTile toggleWall in this.wallsToToggle)
            {
                toggleWall.SetToggle(!toggleWall.isActive);
            }
        }
    }
Ejemplo n.º 8
0
    public override void OnMoveableTileEnter(btTile _tile, DIRECTION _enterDirection)
    {
        btBoardSpace moveToSpace = btTileManager.instance.GetSpaceInDirectionFromTile(this, this.direction, 1);

        if (moveToSpace == null || moveToSpace.IsPassable() == false)
        {
            return;
        }
        _tile.tileState       = btTile.TILESTATE.FORCE_MOVE;
        _tile.forceDirection  = this.direction;
        _tile.currentMovement = 0.0f;
        _tile.startSpace      = this.currentSpace;
        _tile.endSpace        = moveToSpace;
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Returns the tile that is "steps" spaces away from "tile" in "direction"
    /// </summary>
    /// <param name="_tile">The origin</param>
    /// <param name="_Direction">The direction</param>
    /// <param name="_Steps">The steps to take</param>
    /// <returns></returns>
    public btBoardSpace GetSpaceInDirectionFromTile(btTile _tile, btTile.DIRECTION _Direction, int _Steps = 1)
    {
        Vector2 directionVector = DirectionAsVector(_Direction);

        directionVector *= _Steps;

        int newX = (int)directionVector.x + _tile.currentSpace.x;        //_tile.xIndex;
        int newY = (int)directionVector.y + _tile.currentSpace.y;        //_tile.yIndex;

        if (IsValidTileIndex(newX, newY) == false)
        {
            return(null);
        }
        return(instance.tileGrid[newY][newX]);
    }
Ejemplo n.º 10
0
    public override void OnMoveableTileEnter(btTile _tile, DIRECTION _enterDirection)
    {
        DIRECTION    slideDirection = _enterDirection;
        btBoardSpace adjacentSpace  = btTileManager.instance.GetSpaceInDirectionFromTile(this, slideDirection, 1);

        if (adjacentSpace == null || adjacentSpace.IsPassable() == false)
        {
            return;
        }
        _tile.tileState       = btTile.TILESTATE.SLIDING;
        _tile.slideDirection  = slideDirection;
        _tile.startSpace      = this.currentSpace;
        _tile.endSpace        = adjacentSpace;
        _tile.currentMovement = 0.0f;
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Resets the position of the input tile
 /// </summary>
 /// <param name="_tile">The tile to reset</param>
 private void ResetTilePosition(btTile _tile)
 {
     _tile.SetPosition(this.GetSpacePosition(_tile.currentSpace));
     //_tile.SetPosition( this.BoardIndexToPosition( _tile.xIndex, _tile.yIndex ) );
     _tile.ResetRotationUsingDirection();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Adds a movement for the input tile to the input space, using the movement direction
 /// </summary>
 /// <param name="_tile">The tile to be moved</param>
 /// <param name="_space">The space to move the tile to</param>
 /// <param name="_movementDirection">The direction in which the tile is being moved</param>
 public void AddTileMovementToSpace(btTile _tile, btBoardSpace _space, btTile.DIRECTION _movementDirection)
 {
     this.AddTileMovement(_tile, _space.x, _space.y, _movementDirection);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds a movement for the input tile to the input indices, using the movement direction
 /// </summary>
 /// <param name="_tile">The tile to be moved</param>
 /// <param name="_xIndex">The new x index</param>
 /// <param name="_yIndex">The new y index</param>
 /// <param name="_movementDirection"> The direction that the tile is being moved</param>
 public void AddTileMovement(btTile _tile, int _xIndex, int _yIndex, btTile.DIRECTION _movementDirection)
 {
     this.tileMovements.Add(new btTileManager.btTileMovement(_tile, _xIndex, _yIndex, _movementDirection));
 }
Ejemplo n.º 14
0
 public override void OnMoveableTileEnter(btTile _tile, DIRECTION _enterDirection)
 {
     btGameManager.instance.KillPlayer();
     btUIManager.instance.DisplayMessageDialog("You Died", "Don't fly into venus fly traps!");
 }
Ejemplo n.º 15
0
 public virtual void OnMoveableTileExit(btTile _Tile, DIRECTION _exitDirection)
 {
 }
Ejemplo n.º 16
0
 public virtual void OnMoveableTileEnter(btTile _Tile, DIRECTION _enterDirection)
 {
 }
Ejemplo n.º 17
0
 public override void OnMoveableTileEnter(btTile _tile, DIRECTION _enterDirection)
 {
     btGameManager.instance.CompleteLevel();
 }