예제 #1
0
    void Awake()
    {
        roomSetup = GetComponent <RoomSetup> ();
        if (!roomSetup)
        {
            Debug.LogError("I can't find the room setup tool.");
        }
        switch (HouseSize)
        {
        case houseSize.small:
            InitializeHouse(4);
            break;

        case houseSize.medium:
            InitializeHouse(6);
            break;

        case houseSize.large:
            InitializeHouse(8);
            break;

        case houseSize.huge:
            InitializeHouse(12);
            break;
        }
        UpdateCash();
    }
예제 #2
0
    private void RearrangeBlocks()
    {
        RoomSetup setup = RoomController.roomController.GetRoomSetup();

        foreach (GameObject block in blocks)
        {
            GridController.gridController.RemoveFromPosition(block.transform.position);
            Destroy(block.gameObject);
        }
        for (int i = 0; i < setup.blockNumber; i++)
        {
            int x, y;
            for (int j = 0; j < 100; j++)
            {
                int[] roomRange = GridController.gridController.GetRoomRange();
                x = Random.Range(roomRange[0], roomRange[1]);
                y = Random.Range(roomRange[2], roomRange[3]);
                if (GridController.gridController.GetObjectAtLocation(new Vector2(x, y)) == null)
                {
                    GameObject thisBlock = Instantiate(block, new Vector2(x, y), Quaternion.identity);
                    blocks.Add(thisBlock);
                    break;
                }
                else
                {
                    Debug.Log("Tried block at: " + x.ToString() + ", " + y.ToString());
                }
            }
        }
    }
예제 #3
0
        private void LoadRooms(RoomSetup roomSetup, TreeNode parentNode)
        {
            TreeNode RoomNode = new TreeNode("Room");

            parentNode.Nodes.Add(RoomNode);

            foreach (var mesh in roomSetup.Meshes)
            {
                RoomNode.Nodes.Add(mesh);
            }

            foreach (var room in roomSetup.SubSetups)
            {
                LoadRooms(room, parentNode);
            }
        }
예제 #4
0
 public void SetSetup(RoomSetup newSetup)
 {
     setup = newSetup;
 }
예제 #5
0
 // Start is called before the first frame update
 void Awake()
 {
     //highlight = GetComponent<Outline>();
     //collider = GetComponent<Collider2D>();
     setup = ScriptableObject.CreateInstance <RoomSetup>();
 }
예제 #6
0
        private List <RoomSetup> ReadRoomHeaders(FileReader reader, GameVersion version)
        {
            List <RoomSetup> roomSetups = new List <RoomSetup>();

            int offset = 0;

            long pos = reader.Position;

            while (true)
            {
                reader.SeekBegin(pos + offset);

                offset += 8;

                reader.SetByteOrder(true);
                uint cmd1 = reader.ReadUInt32();
                reader.SetByteOrder(false);
                uint cmd2 = reader.ReadUInt32();

                var cmdType = cmd1 >> 24;

                if (cmdType == (uint)HeaderCommands.End)
                {
                    break;
                }

                RoomSetup setup = new RoomSetup();
                roomSetups.Add(setup);

                Console.WriteLine((HeaderCommands)cmdType);

                switch (cmdType)
                {
                case (uint)HeaderCommands.MultiSetup:
                {
                    int numSetups = ((int)cmd1 >> 16) & 0xFF;

                    reader.SeekBegin(pos + cmd2);
                    for (int i = 0; i < numSetups; i++)
                    {
                        uint setupOffset = reader.ReadUInt32();
                        if (setupOffset == 0)
                        {
                            continue;
                        }

                        using (reader.TemporarySeek(setupOffset, System.IO.SeekOrigin.Begin))
                        {
                            var subsetups = ReadRoomHeaders(reader, version);
                            setup.SubSetups.AddRange(subsetups);
                        }
                    }
                }
                break;

                case (uint)HeaderCommands.Actor:
                {
                    int numActors = ((int)cmd1 >> 16) & 0xFF;

                    reader.SeekBegin(pos + cmd2);
                    setup.Actors = ReadActors(reader, version, numActors);
                }
                break;

                case (uint)HeaderCommands.Mesh:
                {
                    reader.SeekBegin(pos + cmd2);
                    setup.Meshes = ReadMesh(reader);
                }
                break;
                }
            }

            return(roomSetups);
        }
예제 #7
0
    public void RandomizeRoom()
    {
        RoomSetup setup = RoomController.roomController.GetRoomSetup();

        GameObject[]      players = GameObject.FindGameObjectsWithTag("Player");
        List <GameObject> enemies = new List <GameObject>();

        blocks = new List <GameObject>();
        int counter = 0;

        foreach (GameObject player in players)
        {
            if (setup.playwerSpawnLocations.Count == 0)
            {
                player.GetComponent <PlayerController>().Spawn();
            }
            else
            {
                player.GetComponent <PlayerController>().Spawn(setup.playwerSpawnLocations[counter]);
            }
            counter += 1;
        }
        foreach (GameObject enemy in setup.enemies)
        {
            Debug.Log("Spawned enemy");
            GameObject thisEnemy = Instantiate(enemy);
            thisEnemy.GetComponent <EnemyController>().Spawn();
            enemies.Add(thisEnemy);
        }
        for (int i = 0; i < setup.blockNumber; i++)
        {
            int x, y;
            for (int j = 0; j < 100; j++)
            {
                int[] roomRange = GridController.gridController.GetRoomRange();
                x = Random.Range(roomRange[0], roomRange[1]);
                y = Random.Range(roomRange[2], roomRange[3]);
                if (GridController.gridController.GetObjectAtLocation(new Vector2(x, y)) == null)
                {
                    GameObject thisBlock = Instantiate(block, new Vector2(x, y), Quaternion.identity);
                    blocks.Add(thisBlock);
                    break;
                }
                else
                {
                    Debug.Log("Tried block at: " + x.ToString() + ", " + y.ToString());
                }
            }
        }
        bool exit = false;

        for (int i = 0; i < 1000; i++)
        {
            exit = true;
            foreach (GameObject player in players)
            {
                foreach (GameObject enemy in enemies)
                {
                    List <Vector2> path = PathFindController.pathFinder.PathFind(player.transform.position, enemy.transform.position);
                    if (path[path.Count - 1] != (Vector2)enemy.transform.position)
                    {
                        RearrangeBlocks();
                        exit = false;
                    }
                }
            }
            if (exit)
            {
                break;
            }
        }
    }
예제 #8
0
    public RoomSetup GetRoomSetup()
    {
        RoomSetup setup = roomSetups[Random.Range(0, roomSetups.Length)];

        return(setup);
    }
예제 #9
0
    public void RandomizeRoom()
    {
        setup = RoomController.roomController.GetRoomSetup();

        GameObject[]      players = GameObject.FindGameObjectsWithTag("Player");
        List <GameObject> enemies = new List <GameObject>();

        blocks = new List <GameObject>();
        int counter = 0;

        //Spawn players first. If specified location, at location, if not, spawn randomly
        foreach (GameObject player in players)
        {
            if (setup.playwerSpawnLocations.Count == 0)
            {
                player.GetComponent <PlayerController>().Spawn();
            }
            else
            {
                player.GetComponent <PlayerController>().Spawn(setup.playwerSpawnLocations[counter]);
            }
            counter += 1;
        }
        //Then spawn enemies
        foreach (GameObject enemy in setup.enemies)
        {
            GameObject thisEnemy = Instantiate(enemy);
            thisEnemy.GetComponent <EnemyController>().Spawn();
            enemies.Add(thisEnemy);
        }
        for (int i = 0; i < setup.blockNumber; i++)
        {
            int x, y;
            for (int j = 0; j < 100; j++)
            {
                int[] roomRange = GridController.gridController.GetRoomRange();
                x = Random.Range(roomRange[0], roomRange[1]);
                y = Random.Range(roomRange[2], roomRange[3]);
                if (GridController.gridController.GetObjectAtLocation(new Vector2(x, y)).Count == 0)
                {
                    GameObject thisBlock = Instantiate(block, new Vector2(x, y), Quaternion.identity);
                    GridController.gridController.ReportPosition(thisBlock, new Vector2(x, y));
                    blocks.Add(thisBlock);
                    break;
                }
            }
        }
        bool exit = false;

        for (int blockNumber = setup.blockNumber; blockNumber >= 0; blockNumber--)
        {
            for (int i = 0; i < 2; i++)
            {
                exit = true;
                foreach (GameObject player in players)
                {
                    foreach (GameObject enemy in enemies)
                    {
                        EnemyController enemyController = enemy.GetComponent <EnemyController>();
                        List <Vector2>  path            = PathFindController.pathFinder.PathFind(enemy.transform.position, player.transform.position, new string[] { "Player", "Enemy" }, enemy.GetComponent <HealthController>().GetOccupiedSpaces(), enemy.GetComponent <HealthController>().size); //Must be enemy position first
                        if (Mathf.Abs((path[path.Count - 1] - (Vector2)player.transform.position).magnitude) > Mathf.Pow(2 * Mathf.Pow((0.5f * enemy.GetComponent <HealthController>().size - 0.5f), 2), 0.5f))
                        {
                            exit = false;
                        }
                    }
                }
                if (exit)
                {
                    break;
                }
                else
                {
                    RearrangeBlocks(blockNumber);
                }
            }
        }
    }