-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoomObj.cs
130 lines (110 loc) · 3.21 KB
/
RoomObj.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class RoomObj {
public int cubeNumber;
public int faceNumber;
public int faceSize;
public int xStart;
public int yStart;
public int xSize;
public int ySize;
public int roomType;
public int roomNumber;
public int[,] roomTileArray;
public bool overlap;
public bool createSuccess;
public List<RoomObj> connectRoomList = new List<RoomObj>();
FaceObj onFace;
/*
//Rotation holds values for the times by which the room is to be rotated (by ninety degrees clockwise) on its face
public enum Rotation {
ZERO,
ONE,
TWO,
THREE
}
*/
List<int[,]> roomSizeList = new List<int[,]>() {
{new int[4,4]},
{new int[4,8]},
{new int[8,8]},
{new int[16,16]},
{new int[12, 16]}
};
public RoomObj(CubeObj onCube, FaceObj originFace, int roomCount){
onFace = originFace;
this.cubeNumber = onFace.cubeNumber;
this.faceNumber = onFace.faceNumber;
this.faceSize = onFace.faceSize;
if(roomCount == 0){
xSize = Random.Range(5, faceSize - 2);
ySize = Random.Range(5, faceSize - 2);
xStart = (int)Mathf.Floor((faceSize - xSize) / 2);
yStart = (int)Mathf.Floor((faceSize - xSize) / 2);
}
else{
xStart = Random.Range(0, faceSize);
yStart = Random.Range(0, faceSize);
roomType = Random.Range(0, roomSizeList.Count);
}
roomTileArray = roomSizeList[roomType];
xSize = roomTileArray.GetLength(0);
ySize = roomTileArray.GetLength(1);
for(int y = 0; y < ySize; y++){
for(int x = 0; x < xSize; x++){
if (x == xSize - 1 || y == ySize - 1 || x == 0 || y == 0){
roomTileArray[x,y] = TileObj.TileDict["wall"];
}
else{
roomTileArray[x,y] = TileObj.TileDict["floor"];
}
}
}
createSuccess = true;
}
/* When checking for overlap, edges of a face are associated with the these numbers:
*
* 0
* __________
* | |
* 3 | | 1
* | |
* |_________|
*
* 2
*
*/
public void CheckOverlap(FaceObj thisFace){
Debug.Log ("Face number: " +thisFace.faceNumber+ " Room number: " +thisFace.roomList.Count+ " Now beginning CheckOverlap");
Debug.Log ("xStart: " +xStart+ " yStart: " +yStart);
Debug.Log ("xSize: " +xSize+ " ySize: " +ySize);
for(int y = yStart; y < yStart + ySize; y++){
for(int x = xStart; x < xStart + xSize; x++){
Debug.Log ("X: " +x+ " Y: " +y);
Debug.Log ("TileRead for faceNumber: " +faceNumber+ " Room Number: "+roomNumber);
int thisTile = Architect.TileRead(x,y, thisFace);
if(thisTile == 0) {
Debug.Log ("Not overlapping");
overlap = false;
}
else{
overlap = true;
Debug.Log ("-----------------------Overlap, discard--------------------------------");
break;
}
}
}
}
public void DrawRoom(FaceObj thisFace){
for(int y = yStart; y < yStart + ySize; y++){
for(int x = xStart; x < xStart + xSize; x++){
Debug.Log ("TileWrite for FaceNumber: " + thisFace.faceNumber+ " Room Number: " +roomNumber);
Debug.Log ("Passing X: " +x+ " and Y: " +y+ " to TileWrite");
bool drawn = Architect.TileWrite(x,y,roomTileArray[x - xStart, y - yStart], thisFace);
if (drawn) Debug.Log("!!!!!!Draw successful!!!!!!!!!!");
}
}
}
}