Example #1
0
File: CubeGen.cs Project: JvJ/CotWM
    // Use this for initialization
    void Start()
    {
        // :o How selfish!!!
        Singleton = this;

        TextAsset t = Resources.Load(textFile) as TextAsset;

        //Room r = Room.FromString(t.text);

        //r.CopyRoom(Chambers.Rooms(ChamberSize.SIZE_1),0,0);

        //r.CopyRoom(Chambers.Rooms(ChamberSize.SIZE_2),20,0);

        //Room r = Room.ChambersGen0(width, height, numRooms);

        coords start = new coords();
        coords end = new coords();

        Maze m = Maze.GrowingTree(width, height, branchRate, noDiagonals, out start, out end);

        gameChambers = new ChamberMap(m.Width, m.Height);

        gameMaze = m;

        Room r = Room.ChambersFromMaze(m, gameChambers, new System.Random(), start, end);

        gameMap = r;

        MakeRoom(r, new System.Random());

        if (roomControls[start.X, start.Y].PlayerStart != null){
            player.transform.position = roomControls[start.X, start.Y].PlayerStart.transform.position;
        }
        else{
            player.transform.position = new Vector3(
                                                BottomLeft.x + ((start.X + 0.5f) * Chambers.CHAMBER_WIDTH * cubeSize),
                                                BottomLeft.y + ((start.Y + 0.5f) * Chambers.CHAMBER_HEIGHT * cubeSize),
                                                0);
        }
        if (firstEnemy != null){
            firstEnemy.transform.position = new Vector3(
                                                    BottomLeft.x + ((start.X + 0.5f) * Chambers.CHAMBER_WIDTH * cubeSize),
                                                    BottomLeft.y + ((start.Y + 0.2f) * Chambers.CHAMBER_HEIGHT * cubeSize),
                                                    0);
        }

        // OK SO!
        // Before the game starts, turn off all rooms
        for (int x = 0; x < roomControls.GetLength(0); x++){
            for (int y = 0; y < roomControls.GetLength(1); y++){
                if (roomControls[x,y] != null){
                    roomControls[x,y].FreezeRoom();
                }
            }
        }

        // Temporary!
        // Output the maze and the room to files

        /*System.IO.File.WriteAllText("mazeText.txt", m.ToString());
        System.IO.File.WriteAllText("levelText.txt", r.ToString());*/
    }
Example #2
0
File: Room.cs Project: JvJ/CotWM
        /// <summary>
        /// 
        /// </summary>
        /// <param name="m">
        /// A <see cref="Maze"/>
        /// </param>
        /// <param name="rand">
        /// A <see cref="System.Random"/>
        /// </param>
        /// <returns>
        /// A <see cref="Room"/>
        /// </returns>
        public static Room ChambersFromMaze(Maze m, ChamberMap cm, System.Random rand, coords StartPosition, coords EndPosition)
        {
            // LEFTOFF: Here!
            Room ret = new Room(m.Width * Chambers.CHAMBER_WIDTH, m.Height  * Chambers.CHAMBER_HEIGHT);

            for (int x = 0; x < m.Width; x++){
                for (int y = 0; y < m.Height; y++){

                    // Select a random chamber type
                    ChamberType ct;

                    if (new coords(x,y) == EndPosition){
                        ct = ChamberType.TYPE_BOSS;
                    }
                    else{
                        ct = (ChamberType)(rand.Next() % (int)ChamberType.NumElements);
                        if (ct == ChamberType.TYPE_BOSS){
                            ct = ChamberType.TYPE_5;
                        }
                    }

                    cm[x,y] = ct;

                    Room r = Chambers.Rooms(ct).Clone() as Room;

                    switch(m[x,y]){
                    case MazeTileType.SPACE:

                        // Handle the door carving
                        // Left and Right
                        if (x > 0){
                            if (m[x-1,y] == MazeTileType.SPACE){
                                Chambers.LeftDoor(r, TileType.SNOW);
                            }
                        }
                        if (x < m.Width-1){
                            if (m[x+1,y] == MazeTileType.SPACE){
                                Chambers.RightDoor(r, TileType.SNOW);
                            }
                        }
                        // Bottom and Top
                        if (y > 0){
                            if (m[x,y-1] == MazeTileType.SPACE){
                                Chambers.BottomDoor(r, TileType.SNOW);
                            }
                        }
                        if (y < m.Height-1){
                            if (m[x,y+1] == MazeTileType.SPACE){
                                Chambers.TopDoor(r, TileType.SNOW);
                            }
                        }

                        ret.CopyRoom(r, x * Chambers.CHAMBER_WIDTH, y * Chambers.CHAMBER_HEIGHT);
                        break;
                    }

                }
            }

            return ret;
        }