Example #1
0
 void resetStatic()
 {
     isGameOn    = true;
     currentRoom = Map.start;
     Cat.newGame();
     isWin    = false;
     timeLeft = Time.time + 60;
 }
Example #2
0
 public Item(Screens.ScreenManager screenManager, Vector2 position, Map.Room parentRoom, Texture2D spriteSheet)
     : base(screenManager)
 {
     this.parentRoom = parentRoom;
     this.spriteSheet = spriteSheet;
     this.position = position;
     spriteRect.width = 32;
     spriteRect.height = 32;
 }
        public EnemyEntity(Screens.ScreenManager screenManager, Vector2 position, Map.Room parentRoom, Player player)
            : base(screenManager)
        {
            this.position = position;
            spriteRect.x = 0;
            spriteRect.y = 0;
            spriteRect.width = 32;
            spriteRect.height = 32;

            this.parentRoom = parentRoom;
            this.player = player;
        }
Example #4
0
    private static void ConnectRooms(Map map)
    {
        var connectedRooms = new HashSet <(Map.Room, Map.Room)>();

        List <Map.Room> rooms = map.FindRooms(map.Rect);

        foreach (Map.Room room1 in rooms)
        {
            Map.Room   closestRoom     = null;
            float      closestDistance = 0.0f;
            Vector2Int closestCell1    = Vector2Int.zero;
            Vector2Int closestCell2    = Vector2Int.zero;

            foreach (Map.Room room2 in rooms)
            {
                if (room1 == room2)
                {
                    continue;
                }

                if (connectedRooms.Contains((room1, room2)))
                {
                    closestRoom = null;
                    break;
                }

                foreach (var cell1 in room1.EdgeCells)
                {
                    foreach (var cell2 in room2.EdgeCells)
                    {
                        float distance = Vector2Int.Distance(cell1, cell2);
                        if (closestRoom == null || distance < closestDistance)
                        {
                            closestDistance = distance;
                            closestRoom     = room2;
                            closestCell1    = cell1;
                            closestCell2    = cell2;
                        }
                    }
                }
            }

            if (closestRoom != null)
            {
                connectedRooms.Add((room1, closestRoom));
                connectedRooms.Add((closestRoom, room1));
                CreatePassage(map, closestCell1, closestCell2);
            }
        }
    }
Example #5
0
    public static void newGame()
    {
        int roomNumber = Random.Range(1, 63);

        currentRoom = Map.roomList["room" + roomNumber];
    }
Example #6
0
    private static void randomMove()
    {
        int rnd = Random.Range(1, 62);

        if (rnd == 1)
        {
            if (currentRoom.moveForward() != null)
            {
                currentRoom = currentRoom.moveForward();
            }
            else
            {
                randomMove();
            }
        }
        else if (rnd == 2)
        {
            if (currentRoom.moveBehind() != null)
            {
                currentRoom = currentRoom.moveBehind();
            }
            else
            {
                randomMove();
            }
        }
        else if (rnd == 3)
        {
            if (currentRoom.moveLeft() != null)
            {
                currentRoom = currentRoom.moveLeft();
            }
            else
            {
                randomMove();
            }
        }
        else if (rnd == 4)
        {
            if (currentRoom.moveRight() != null)
            {
                currentRoom = currentRoom.moveRight();
            }
            else
            {
                randomMove();
            }
        }
        else if (rnd == 5)
        {
            if (currentRoom.moveUp() != null)
            {
                currentRoom = currentRoom.moveUp();
            }
            else
            {
                randomMove();
            }
        }
        else if (rnd == 6)
        {
            if (currentRoom.moveDown() != null)
            {
                currentRoom = currentRoom.moveDown();
            }
            else
            {
                randomMove();
            }
        }
    }
Example #7
0
    private void ConnectRooms()
    {
        var rooms = map.FindRooms(map.Rect);

        Debug.Log($"Connect Rooms: number of rooms={rooms.Count}");

        var connectedRooms = new HashSet <(Map.Room, Map.Room)>();

        foreach (var room1 in rooms)
        {
            Map.Room   closestRoom     = null;
            float      closestDistance = float.MaxValue;
            Vector2Int closestCell1    = Vector2Int.zero;
            Vector2Int closestCell2    = Vector2Int.zero;

            foreach (var room2 in rooms)
            {
                if (room1 == room2)
                {
                    continue;
                }

                if (connectedRooms.Contains((room1, room2)))
                {
                    Debug.Log("Connect Rooms: Connection already exists");
                    closestRoom = null;
                    break;
                }

                foreach (var cell1 in room1.EdgeCells)
                {
                    foreach (var cell2 in room2.EdgeCells)
                    {
                        float distance = Vector2Int.Distance(cell1, cell2);
                        if (closestRoom == null || distance < closestDistance)
                        {
                            closestDistance = distance;
                            closestRoom     = room2;
                            closestCell1    = cell1;
                            closestCell2    = cell2;
                        }
                    }
                }
            }

            if (closestRoom != null)
            {
                connectedRooms.Add((room1, closestRoom));
                connectedRooms.Add((closestRoom, room1));

                closestCell1 = UpdateCellIfPredefinedBlock(closestCell1, closestCell2);
                closestCell2 = UpdateCellIfPredefinedBlock(closestCell2, closestCell1);

                CreatePassage(map, closestCell1, closestCell2);
            }
            else
            {
                Debug.Log($"Connect Rooms: Closest room not found!");
            }
        }
    }
Example #8
0
    void gameScreen()
    {
        List <int> coordinate    = currentRoom.getCoordinate();
        List <int> catCoordinate = Cat.currentRoom.getCoordinate();

        print("x: " + coordinate [0] + " y: " + coordinate [1] + " level: " + coordinate [2]);
        print("Cat: x: " + catCoordinate [0] + " y: " + catCoordinate [1] + " level: " + catCoordinate [2]);
        if (Timer.isTimeUp())
        {
            currentState = States.End;
            isGameOn     = false;
        }
        if (CatDetector.catDistance() == 0)
        {
            isGameOn     = false;
            isWin        = true;
            currentState = States.End;
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            if (currentRoom.moveForward() != null)
            {
                counter++;
                print("Move forward successful");
                currentRoom = currentRoom.moveForward();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
        else if (Input.GetKeyDown(KeyCode.A))
        {
            if (currentRoom.moveLeft() != null)
            {
                counter++;
                print("Move left successful");
                currentRoom = currentRoom.moveLeft();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            if (currentRoom.moveBehind() != null)
            {
                counter++;
                print("Move behind successful");
                currentRoom = currentRoom.moveBehind();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            if (currentRoom.moveRight() != null)
            {
                counter++;
                print("Move right successful");
                currentRoom = currentRoom.moveRight();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
        else if (Input.GetKeyDown(KeyCode.C))
        {
            if (currentRoom.moveUp() != null)
            {
                counter++;
                print("Move up successful");
                currentRoom = currentRoom.moveUp();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
        else if (Input.GetKeyDown(KeyCode.V))
        {
            if (currentRoom.moveDown() != null)
            {
                counter++;
                print("Move down successful");
                currentRoom = currentRoom.moveDown();
                Cat.catMove();
            }
            else
            {
                print("invalid move");
            }
        }
    }