Beispiel #1
0
    /// <summary>
    /// Raises the hit room trigger event. Start the coroutine to load the next room.
    /// </summary>
    /// <param name="direction">The direction that the player has moved.</param>
    public void OnHitRoomTrigger(Room.Direction direction)
    {
        switch (direction)
        {
        case Room.Direction.DOWN:
            StartCoroutine("_LoadNextRoomRoutine", m_curRoom.m_down);
            m_playerLoadPosition = new Vector3(0.0f, 10.0f, 45.0f);
            break;

        case Room.Direction.LEFT:
            StartCoroutine("_LoadNextRoomRoutine", m_curRoom.m_left);
            m_playerLoadPosition = new Vector3(45.0f, 10.0f, 0.0f);
            break;

        case Room.Direction.RIGHT:
            StartCoroutine("_LoadNextRoomRoutine", m_curRoom.m_right);
            m_playerLoadPosition = new Vector3(-45.0f, 10.0f, 0.0f);
            break;

        case Room.Direction.UP:
            StartCoroutine("_LoadNextRoomRoutine", m_curRoom.m_up);
            m_playerLoadPosition = new Vector3(0.0f, 10.0f, -45.0f);
            break;

        default:
            break;
        }
    }
Beispiel #2
0
        private Room.Direction GetOpposite(Room.Direction direction)
        {
            switch (direction)
            {
            case Room.Direction.RIGHT: return(Room.Direction.LEFT);

            case Room.Direction.UP: return(Room.Direction.DOWN);

            case Room.Direction.LEFT: return(Room.Direction.RIGHT);

            default: return(Room.Direction.UP);
            }
            ;
        }
Beispiel #3
0
        virtual protected void ConfigurePitWall(Transform pitStage, Room.Direction direction)
        {
            Vector3 directionVector = Room.DirectionToVector(direction);
            float   width           = Room.DirectionScale(direction, new Vector3(m_size.x, 1, m_size.y)).magnitude;
            Vector2 wallSize        = new Vector2(width, 1);
            string  wallName        = string.Format("Wall_{0}", direction);

            RoomPart wall = Instantiate(m_pitWall);

            wall.Configure(pitStage, wallName, wallSize);

            wall.transform.localPosition = Vector3.Scale(new Vector3(m_size.x, 1, m_size.y), directionVector) / 2;
            wall.transform.Rotate(Vector3.up, Room.DirectionAngle(direction) - 90, Space.World);
        }
Beispiel #4
0
        private void go()
        {
            if (inputActionData.Length > 0)
            {
                try {
                    Room.Direction dir = (Room.Direction)Enum.Parse(typeof(Room.Direction),
                                                                    inputActionData[0],
                                                                    true);

                    if (columns[y].row[x].validDirection(dir))
                    {
                        switch (dir)
                        {
                        case Room.Direction.NORTH:
                            y += 1;
                            break;

                        case Room.Direction.EAST:
                            x += 1;
                            break;

                        case Room.Direction.WEST:
                            x -= 1;
                            break;

                        case Room.Direction.SOUTH:
                            y -= 1;
                            break;
                        }

                        PrintRoom();
                    }
                    else if (columns[y].row[x].isLockedDirection(dir))
                    {
                        LogString("\nThat way is locked");
                    }
                    else
                    {
                        LogString("\nYou can't walk through walls");
                    }
                } catch (System.ArgumentException e) {
                    LogString("\nI'm sorry, but that isn't a direction");
                }
            }
            else
            {
                LogString("\nGo where?");
            }
        }
Beispiel #5
0
    /// <summary>
    /// Create fence of hallway in particular direction of room
    /// </summary>
    /// <param name="room">input</param>
    /// <param name="nextPos">next location of room on Board, ex: [2,3]</param>
    /// <param name="direction">direction from cur room to next room</param>
    private void MakeHallWayOrFence(Room room, int[] nextPos, Room.Direction direction)
    {
        // check
        if (room == null || nextPos == null)
        {
            return;
        }

        // get variable to use
        FenceType fenceType = FenceType.Horizontal; // default, avoid errors
        Transform roomPos   = null;

        if (direction == Room.Direction.Left)
        {
            roomPos          = room.leftPos;
            fenceType        = FenceType.Vertical;
            room.leftConnect = true;
        }
        if (direction == Room.Direction.Right)
        {
            roomPos           = room.rightPos;
            fenceType         = FenceType.Vertical;
            room.rightConnect = true;
        }
        if (direction == Room.Direction.Up)
        {
            roomPos        = room.upPos;
            fenceType      = FenceType.Horizontal;
            room.upConnect = true;
        }
        if (direction == Room.Direction.Down)
        {
            roomPos          = room.downPos;
            fenceType        = FenceType.Horizontal;
            room.downConnect = true;
        }



        // if next location is valid
        if (isValidLocation(nextPos[0], nextPos[1]))
        {
            if (direction == Room.Direction.Left)
            {
                MakeHallWay(room.leftPos);
                rooms[nextPos[0], nextPos[1]].rightConnect = true;
            }
            if (direction == Room.Direction.Right)
            {
                MakeHallWay(room.rightPos);
                rooms[nextPos[0], nextPos[1]].leftConnect = true;
            }
            if (direction == Room.Direction.Up)
            {
                MakeHallWay(room.upPos);
                rooms[nextPos[0], nextPos[1]].downConnect = true;
            }
            if (direction == Room.Direction.Down)
            {
                MakeHallWay(room.downPos);
                rooms[nextPos[0], nextPos[1]].upConnect = true;
            }
        }

        // if next position is invalid
        else
        {
            MakeFence(room, roomPos.position, fenceType);
        }
    }
Beispiel #6
0
        public List <Room> GenerateGrid()
        {
            tiles = new int[mapWidth, mapHeight];
            rooms = new List <Room>();

            //spawn start/ end in the corners
            int startTile = rnd.Next(4);
            int endTile   = rnd.Next(4);

            while (endTile == startTile)
            {
                endTile = rnd.Next(4);
            }

            tiles[(int)GetCorner(startTile).X, (int)GetCorner(startTile).Y] = (int)TileType.start;
            tiles[(int)GetCorner(endTile).X, (int)GetCorner(endTile).Y]     = (int)TileType.end;

            //item tiles
            for (int i = 0; i < itemTileCount; i++)
            {
                PlaceTileAtRandom(TileType.item);
            }

            //boss tiles
            for (int i = 0; i < bossTileCount; i++)
            {
                PlaceTileAtRandom(TileType.boss);
            }

            //find random path between start/finish
            List <Vector2> pathValues = list.GeneratePath(GetCorner(startTile), GetCorner(endTile));

            pathValues.Add(GetCorner(endTile));

            int[,] pathPlaces = new int[mapWidth, mapHeight];
            for (int i = 0; i < pathValues.Count; i++)
            {
                pathPlaces[(int)pathValues[i].X, (int)pathValues[i].Y] = 1;
            }

            //turn path values into rooms
            for (int i = 0; i < pathValues.Count - 1; i++)
            {
                Room.Direction direction1 = Room.Direction.DOWN;

                if (pathValues[i + 1].X > pathValues[i].X)
                {
                    direction1 = Room.Direction.RIGHT;
                }
                else if (pathValues[i + 1].X < pathValues[i].X)
                {
                    direction1 = Room.Direction.LEFT;
                }
                else if (pathValues[i + 1].Y < pathValues[i].Y)
                {
                    direction1 = Room.Direction.UP;
                }

                if (i == 0)
                {
                    Room startRoom = new Room(pathValues[i], direction1);
                    startRoom.roomFunction = Room.RoomFunction.Spawn;
                    rooms.Add(startRoom);
                }
                else
                {
                    rooms[i].AddDirection(direction1);
                }
                Room nextRoom = new Room(pathValues[i + 1], GetOpposite(direction1));
                if (i == pathValues.Count - 2)
                {
                    nextRoom.roomFunction = Room.RoomFunction.Finish;
                }
                rooms.Add(nextRoom);
            }

            List <Vector2> emptyRooms = new List <Vector2>();

            for (int x = 0; x < pathPlaces.GetLength(0); x++)
            {
                for (int y = 0; y < pathPlaces.GetLength(1); y++)
                {
                    if (pathPlaces[x, y] == 0)
                    {
                        emptyRooms.Add(new Vector2(x, y));
                    }
                }
            }

            //link up remaining rooms
            while (rooms.Count < (mapWidth * mapHeight))
            {
                for (int i = 0; i < emptyRooms.Count; i++)
                {
                    Vector2 roomPos = emptyRooms[i];
                    List <Room.Direction> availableDirections = new List <Room.Direction>();
                    if (roomPos.X > 0 && roomPos.Y > 0 && roomPos.X < mapWidth - 1 && roomPos.Y < mapHeight - 1)
                    {
                        if (pathPlaces[(int)roomPos.X - 1, (int)roomPos.Y] == 1)
                        {
                            availableDirections.Add(Room.Direction.LEFT);
                        }
                        if (pathPlaces[(int)roomPos.X + 1, (int)roomPos.Y] == 1)
                        {
                            availableDirections.Add(Room.Direction.RIGHT);
                        }
                        if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                        {
                            availableDirections.Add(Room.Direction.UP);
                        }
                        if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                        {
                            availableDirections.Add(Room.Direction.DOWN);
                        }
                    }
                    else
                    {
                        //if (room.position != GetCorner(startTile) && room.position != GetCorner(endTile))
                        //{
                        if (roomPos.X == 0)
                        {
                            if (pathPlaces[(int)roomPos.X + 1, (int)roomPos.Y] == 1)
                            {
                                availableDirections.Add(Room.Direction.RIGHT);
                            }
                            if (roomPos.Y == 0)
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.DOWN);
                                }
                            }
                            else if (roomPos.Y == mapHeight - 1)
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.UP);
                                }
                            }
                            else
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.UP);
                                }
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.DOWN);
                                }
                            }
                        }
                        else if (roomPos.X == mapWidth - 1)
                        {
                            if (pathPlaces[(int)roomPos.X - 1, (int)roomPos.Y] == 1)
                            {
                                availableDirections.Add(Room.Direction.LEFT);
                            }
                            if (roomPos.Y == 0)
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.DOWN);
                                }
                            }
                            else if (roomPos.Y == mapHeight - 1)
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.UP);
                                }
                            }
                            else
                            {
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.UP);
                                }
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.DOWN);
                                }
                            }
                            //}
                        }
                        else
                        {
                            if (roomPos.Y == 0)
                            {
                                if (pathPlaces[(int)roomPos.X + 1, (int)roomPos.Y] == 1)
                                {
                                    availableDirections.Add(Room.Direction.RIGHT);
                                }
                                if (pathPlaces[(int)roomPos.X - 1, (int)roomPos.Y] == 1)
                                {
                                    availableDirections.Add(Room.Direction.LEFT);
                                }
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y + 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.DOWN);
                                }
                            }
                            else if (roomPos.Y == mapHeight - 1)
                            {
                                if (pathPlaces[(int)roomPos.X + 1, (int)roomPos.Y] == 1)
                                {
                                    availableDirections.Add(Room.Direction.RIGHT);
                                }
                                if (pathPlaces[(int)roomPos.X - 1, (int)roomPos.Y] == 1)
                                {
                                    availableDirections.Add(Room.Direction.LEFT);
                                }
                                if (pathPlaces[(int)roomPos.X, (int)roomPos.Y - 1] == 1)
                                {
                                    availableDirections.Add(Room.Direction.UP);
                                }
                            }
                        }
                    }
                    if (availableDirections.Count > 0)
                    {
                        Room.Direction direction   = availableDirections[rnd.Next(availableDirections.Count)];
                        Vector2        nextRoomPos = roomPos;
                        if (direction == Room.Direction.DOWN)
                        {
                            nextRoomPos.Y += 1;
                        }
                        else if (direction == Room.Direction.UP)
                        {
                            nextRoomPos.Y -= 1;
                        }
                        else if (direction == Room.Direction.RIGHT)
                        {
                            nextRoomPos.X += 1;
                        }
                        else if (direction == Room.Direction.LEFT)
                        {
                            nextRoomPos.X -= 1;
                        }

                        rooms.Where(x => x.position == nextRoomPos).First().AddDirection(GetOpposite(direction));
                        rooms.Add(new Room(roomPos, direction));
                        pathPlaces[(int)roomPos.X, (int)roomPos.Y] = 1;
                        emptyRooms.Remove(roomPos);
                    }
                }
            }
            return(rooms);
        }
Beispiel #7
0
 public void setDoor(Room.Direction direction, bool state)
 {
     // Set the given door to a given state
     doors [(int)direction] = state;
 }
Beispiel #8
0
 public bool getDoor(Room.Direction direction)
 {
     return(doors [(int)direction]);
 }