Example #1
0
 private void CreateRooms()
 {
     for (int x = 0; x < this.level.GetWidth(); ++x) {
         for (int y = 0; y < this.level.GetHeight(); ++y) {
             if (this.level.IsFloor(x, y)) {
                 if ( !level.ContainsInRooms(x, y) ) {
                     Room room = new Room();
                     this.level.AddRoom(room);
                     this.AddNeighborRoom(room, x, y);
                     Vector3 center = this.MatrixToPosition(room.GetCenter());
                     GameObject lightPrefab = (GameObject)Resources.Load ("Prefabs/roomLightPrefab", typeof(GameObject));
                     GameObject light = (GameObject)Instantiate (lightPrefab, center + Vector3.up * 10, Quaternion.identity);
                     light.transform.parent = levelObject.transform;
                     foreach (Vector2 point in room.GetFloors()) {
                         Vector2[] neighbors = {point + Vector2.up, point + -Vector2.up, point + Vector2.right, point + -Vector2.right,
                             point + Vector2.one, point - Vector2.one, point + Vector2.up - Vector2.right, -Vector2.up + Vector2.right
                         };
                         foreach (Vector2 neighbor in neighbors) {
                             if (this.level.IsWall((int)neighbor.x, (int)neighbor.y)) {
                                 room.AddWalls(neighbor);
                             }
                         }
                     }
                     // make start room as protected.
                     if (this.level.IsStartUnit(room) ){
                         room.SetProtect(true);
                     }
                 }
             }
         }
     }
 }
Example #2
0
 private void AddNeighborRoom(Room room, int x, int y)
 {
     room.AddFloor(x, y);
     if (this.level.GetCharMap()[new Vector2((int)x, (int)y)] == '*') {
         room.SetProtect(true);
     }
     int[] xs = {x + 1, x - 1, x, x};
     int[] ys = {y, y, y + 1, y - 1};
     for (int i = 0; i < 4; ++i) {
         if (this.level.IsFloor(xs[i], ys[i]) && !this.level.ContainsInRooms(xs[i], ys[i])) {
             this.AddNeighborRoom(room, xs[i], ys[i]);
         }
     }
 }