Beispiel #1
0
        public List <Vector2Int> PossibleMovementDirections(Vector2Int pos)
        {
            ProxyRoom room = map[pos.y].rooms[pos.x];

            List <Vector2Int> results = new List <Vector2Int>();

            if (room.left == ProxyRoom.Door || room.left == ProxyRoom.Open)
            {
                var leftPos = new Vector2Int(pos.x - 1, pos.y);

                results.Add(leftPos);
            }

            if (room.top == ProxyRoom.Door || room.top == ProxyRoom.Open)
            {
                var upPos = new Vector2Int(pos.x, pos.y - 1);

                results.Add(upPos);
            }

            if (room.bottom == ProxyRoom.Door || room.bottom == ProxyRoom.Open)
            {
                var bottomPos = new Vector2Int(pos.x, pos.y + 1);

                results.Add(bottomPos);
            }

            if (room.right == ProxyRoom.Door || room.right == ProxyRoom.Open)
            {
                var rightPos = new Vector2Int(pos.x + 1, pos.y);

                results.Add(rightPos);
            }
            return(results);
        }
Beispiel #2
0
 protected void GenerateRoomElements(ProxyRoom proxyRoom, string type, float chance, LevelGenTemplate template)
 {
     AddRoomElement(ref proxyRoom.topLeft, TopLeft, proxyRoom.left, proxyRoom.top, type, chance, template);
     AddRoomElement(ref proxyRoom.topRight, TopRight, proxyRoom.right, proxyRoom.top, type, chance, template);
     AddRoomElement(ref proxyRoom.bottomLeft, BottomLeft, proxyRoom.left, proxyRoom.bottom, type, chance, template);
     AddRoomElement(ref proxyRoom.bottomRight, BottomRight, proxyRoom.right, proxyRoom.bottom, type, chance, template);
 }
Beispiel #3
0
        private List <Vector2Int> PossibleBuildDirections(Vector2Int pos, Level level)
        {
            ProxyRoom room = level.map[pos.y].rooms[pos.x];

            List <Vector2Int> results = new List <Vector2Int>();

            if (room.left == ProxyRoom.Door || room.left == ProxyRoom.Open)
            {
                var leftPos = new Vector2Int(pos.x - 1, pos.y);
                if (!PositionHasRoom(leftPos, level))
                {
                    results.Add(leftPos);
                }
            }

            if (room.top == ProxyRoom.Door || room.top == ProxyRoom.Open)
            {
                var upPos = new Vector2Int(pos.x, pos.y - 1);
                if (!PositionHasRoom(upPos, level))
                {
                    results.Add(upPos);
                }
            }

            if (room.bottom == ProxyRoom.Door || room.bottom == ProxyRoom.Open)
            {
                var bottomPos = new Vector2Int(pos.x, pos.y + 1);
                if (!PositionHasRoom(bottomPos, level))
                {
                    results.Add(bottomPos);
                }
            }

            if (room.right == ProxyRoom.Door || room.right == ProxyRoom.Open)
            {
                var rightPos = new Vector2Int(pos.x + 1, pos.y);
                if (!PositionHasRoom(rightPos, level))
                {
                    results.Add(rightPos);
                }
            }

            return(results);
        }
Beispiel #4
0
        private ProxyRoom RoomFromString(string str, bool isEntry, bool isMainChain, bool isNearEntry)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(null);
            }

            ProxyRoom response = new ProxyRoom()
            {
                isEntry     = isEntry,
                isNearEntry = isNearEntry,
                isMainChain = isMainChain
            };

            string[] splitString = str.Split('_');

            if (splitString.Length < 1)
            {
                return(null);
            }

            if (splitString.Length > 0)
            {
                response.left   = splitString[0].Substring(0, 1);
                response.top    = splitString[0].Substring(1, 1);
                response.bottom = splitString[0].Substring(2, 1);
                response.right  = splitString[0].Substring(3, 1);
            }

            if (splitString.Length > 1)
            {
                response.isEntry = splitString[1] == ProxyRoom.ObjTypeEntry;
                response.isEnd   = splitString[1] == ProxyRoom.ObjTypeEnd;
            }

            return(response);
        }
Beispiel #5
0
        private List <string> PossibleRightSides(Vector2Int position, List <string> freeChoice, Level level)
        {
            List <String> sides = new List <string>();

            // If the side would lead out of the level, the side has to be wall
            if (position.x >= (level.template.levelWidth - 1))
            {
                sides.Add(ProxyRoom.Wall);
                return(sides);
            }

            // Get what's at the position
            ProxyRoom room = level.map[position.y].rooms[position.x + 1];

            // If there's nothing then we're free to do anything
            if (room is null)
            {
                return(freeChoice);
            }

            // Otherwise, match what's currently on the right
            sides.Add(room.left);
            return(sides);
        }
Beispiel #6
0
        private List <string> PossibleTopSides(Vector2Int pos, List <string> freeChoice, Level level)
        {
            List <string> sides = new List <string>();

            // If the side would lead out of the level, the side has to be wall
            if (pos.y <= 0)
            {
                sides.Add(ProxyRoom.Wall);
                return(sides);
            }

            // Get what's at the position
            ProxyRoom room = level.map[pos.y - 1].rooms[pos.x];

            // If there's nothing then we're free to do anything
            if (room is null)
            {
                return(freeChoice);
            }

            // Otherwise, match what's currently on the top
            sides.Add(room.bottom);
            return(sides);
        }
Beispiel #7
0
        public void PopulateLevelDoors(Level level, List <Door> doorList)
        {
            if (!level.template.generateDoors)
            {
                Logger.Log(name, "Skipping doors");
                return;
            }

            //FIXME: swap i & j to be consistent!
            for (int i = 0; i < level.map.Count(); i++)
            {
                for (int j = 0; j < level.map[i].rooms.Count(); j++)
                {
                    ProxyRoom room = level.map[i].rooms[j];

                    if (room == null)
                    {
                        continue;
                    }

                    if (room.top == ProxyRoom.Door)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal + (level.template.spanHorizontal / 2), i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + level.template.spanVertical, 0);
                        var     go   = Instantiate(doorewPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }

                    if (room.left == ProxyRoom.Door)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal, i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + (level.template.spanVertical / 2), 0);
                        var     go   = Instantiate(doornsPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }

                    if (room.top == ProxyRoom.Exit)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal + (level.template.spanHorizontal / 2), i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + level.template.spanVertical, 0);
                        var     go   = Instantiate(exitewPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }

                    if (room.left == ProxyRoom.Exit)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal, i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + (level.template.spanVertical / 2), 0);
                        var     go   = Instantiate(exitnsPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }
                    if (room.bottom == ProxyRoom.Exit)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal + (level.template.spanHorizontal / 2), (i + 1) * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + level.template.spanVertical, 0);
                        var     go   = Instantiate(exitewPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }
                    if (room.top == ProxyRoom.Entry)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal + (level.template.spanHorizontal / 2), i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + level.template.spanVertical, 0);
                        var     go   = Instantiate(entryewPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }

                    if (room.left == ProxyRoom.Entry)
                    {
                        Vector3 pos  = new Vector3(j * level.template.spanHorizontal, i * -level.template.spanVertical + ((level.template.levelHeight - 1) * level.template.spanVertical) + (level.template.spanVertical / 2), 0);
                        var     go   = Instantiate(entrynsPrefab, pos, Quaternion.identity, levelParent.transform);
                        Door    door = go.GetComponent <Door>();
                        if (door != null)
                        {
                            doorList.Add(door);
                        }
                    }
                }
            }

            return;
        }