Esempio n. 1
0
    //If something is at the hero's space, decide what to do (e.g. change direction, pick up item, etc)
    void HandleCurrentTile()
    {
        int curX = (int)curSpace.x;
        int curY = (int)curSpace.y;

        Tile checkTile = mapHandler.tileGrid[curX, curY].GetComponent <Tile>();

        switch (checkTile.tileType)
        {
        case Tile.TileType.TurnUp:
            ChangeHeroDirection(HeroDirections.Up);
            break;

        case Tile.TileType.TurnDown:
            ChangeHeroDirection(HeroDirections.Down);
            break;

        case Tile.TileType.TurnLeft:
            ChangeHeroDirection(HeroDirections.Left);
            break;

        case Tile.TileType.TurnRight:
            ChangeHeroDirection(HeroDirections.Right);
            break;

        case Tile.TileType.Pit:
            if (!inventory.Contains("Ladder"))
            {
                gameOverUI.ActivateGameOver("Game over!\n(The hero fell into a pit)");
            }
            else
            {
                int  x = (int)curSpace.x;
                int  y = (int)curSpace.y;
                Tile extraPitCheck;

                switch (heroDir)
                {
                case HeroDirections.Up:
                    extraPitCheck = mapHandler.GetTileAtCoords(x, y + 1);
                    if (extraPitCheck && extraPitCheck.tileType == Tile.TileType.Pit)
                    {
                        gameOverUI.ActivateGameOver("Game over!\n(The pit was too wide to cross with a ladder)");
                    }
                    break;

                case HeroDirections.Down:
                    extraPitCheck = mapHandler.GetTileAtCoords(x, y - 1);
                    if (extraPitCheck && extraPitCheck.tileType == Tile.TileType.Pit)
                    {
                        gameOverUI.ActivateGameOver("Game over!\n(The pit was too wide to cross with a ladder)");
                    }
                    break;

                case HeroDirections.Left:
                    extraPitCheck = mapHandler.GetTileAtCoords(x - 1, y);
                    if (extraPitCheck && extraPitCheck.tileType == Tile.TileType.Pit)
                    {
                        gameOverUI.ActivateGameOver("Game over!\n(The pit was too wide to cross with a ladder)");
                    }
                    break;

                case HeroDirections.Right:
                    extraPitCheck = mapHandler.GetTileAtCoords(x + 1, y);
                    if (extraPitCheck && extraPitCheck.tileType == Tile.TileType.Pit)
                    {
                        gameOverUI.ActivateGameOver("Game over!\n(The pit was too wide to cross with a ladder)");
                    }
                    break;
                }
            }
            break;

        case Tile.TileType.Ladder:
            if (!inventory.Contains("Ladder"))
            {
                inventory.Add("Ladder");
            }
            Destroy(mapHandler.tileGrid[curX, curY].gameObject);
            break;

        case Tile.TileType.Sword:
            if (!inventory.Contains("Sword"))
            {
                inventory.Add("Sword");
            }
            Destroy(mapHandler.tileGrid[curX, curY].gameObject);
            break;

        case Tile.TileType.Exit:
            heroState = HeroStates.Victory;
            sightGraphic.GetComponent <SpriteRenderer>().enabled = false;
            //Top player exit
            if (curY == (mapHandler.tileGrid.GetLength(1) - 1))
            {
                ChangeHeroDirection(HeroDirections.Up);
            }
            //Bottom player exit
            else if (curY == 0)
            {
                ChangeHeroDirection(HeroDirections.Down);
            }
            //Left player exit
            else if (curX == 0)
            {
                ChangeHeroDirection(HeroDirections.Left);
            }
            //Right player exit
            else if (curX == (mapHandler.tileGrid.GetLength(0) - 1))
            {
                ChangeHeroDirection(HeroDirections.Right);
            }
            else
            {
                print("The exit was in an illegal position (not along the edges of the map) so we're leaving the hero's direction alone");
            }
            break;
        }

        //Cheeky check to see if we should delete a visible ladder
        if (visibleLadder != null)
        {
            if (checkTile.tileType != Tile.TileType.Pit)
            {
                Destroy(visibleLadder);
            }
        }
    }