void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0) { map_data[r.left + x, r.top + y] = nameToInt["Wall"]; } else if (x == r.width - 1) { map_data[r.left + x, r.top + y] = nameToInt["Wall"]; } else if (y == 0) { map_data[r.left + x, r.top + y] = nameToInt["Wall"]; } else if (y == r.height - 1) { map_data[r.left + x, r.top + y] = nameToInt["Wall"]; } else { map_data[r.left + x, r.top + y] = nameToInt["Ground"]; } } } }
}//AddConnection public static bool CheckConnections(DRoom StartRoom, DRoom TargetRoom) { //If we are looking at the same room then we dont have an issue if (StartRoom == TargetRoom) { //So return that we have a connection return(true); } //A list of all rooms currently searched List <DRoom> SearchedRooms = new List <DRoom>(); //Add the room we started in SearchedRooms.Add(StartRoom); //For each connection foreach (DRoom Connection in StartRoom.Connections) { //Search through the rooms if (SearchRooms(ref SearchedRooms, Connection, TargetRoom)) { //And if it was successful, then we have found our room return(true); } } //Otherwise no route was found return(false); }//Check Connections
/// <summary> /// 房间类别 /// </summary> /// <returns></returns> public string RoomType() { var data = new DRoom().RoomType(); //new Log().Info(data); return(data); }
public DRoom GetJointRoom(CollisionBehaviour cb) { DRoom room = null; mJointsDict.TryGetValue(cb, out room); return(room); }
}//Check Connections private static bool SearchRooms(ref List <DRoom> SearchedRooms, DRoom CurrentRoom, DRoom TargetRoom) { //Add the room we are currently looking at if (!SearchedRooms.Contains(CurrentRoom)) { SearchedRooms.Add(CurrentRoom); Debug.Log("Room Added"); } //For each further connection foreach (DRoom Connection in CurrentRoom.Connections) { //If this is the target room if (Connection == TargetRoom) { //Then fall back through the loop return(true); } else { //If this connection hasn't been searched yet if (!SearchedRooms.Contains(Connection)) { Debug.Log("Searching Connection"); //Continue down the chain return(SearchRooms(ref SearchedRooms, Connection, TargetRoom)); } } } return(false); } //SearchRooms
IEnumerator nextRoomCoroutine(CollisionBehaviour cb) { SMovableObject mainRole = MainGameData.MainRole; mainRole.enabled = false; mainRole.SetKinematic(true); unregisterEvent(); mCurRoom.OnExitRoom(); //try get next room DRoom nextRoom = mCurRoom.GetJointRoom(cb); if (nextRoom == null) { //TODO: Be Random After GameObject go = Instantiate(Rooms[0]) as GameObject; nextRoom = go.GetComponent <DRoom>(); nextRoom.Init(); CollisionBehaviour nextCb = nextRoom.AlignmentOtherRoom(cb, mCurRoom.CenterPos); mCurRoom.JointRoom(cb, nextRoom); nextRoom.JointRoom(nextCb, mCurRoom); } StartCoroutine(mainRoleCutScene(nextRoom.CenterPos)); yield return(StartCoroutine(SCameraMgr.Instance.moveToPos(nextRoom.CenterPos))); while (mRoleCurSceneEnable == true) { yield return(null); } mCurRoom = nextRoom; registerEvent(); mCurRoom.OnEnterRoom(); mainRole.SetKinematic(false); mainRole.enabled = true; }
public void JointRoom(CollisionBehaviour jointCb, DRoom jointRoom) { if (mJointsDict.ContainsKey(jointCb) == true) { mJointsDict[jointCb] = jointRoom; } }
void createEastDoor(DRoom r, int col, int row) { if (map_layout[col + 1, row] == true) { r.hasEastDoor = true; } }
void createWestDoor(DRoom r, int col, int row) { if (map_layout[col - 1, row] == true) { r.hasWestDoor = true; } }
void createNorthDoor(DRoom r, int col, int row) { if (map_layout[col, row + 1] == true) { r.hasNorthDoor = true; } }
void createSouthDoor(DRoom r, int col, int row) { if (map_layout[col, row - 1] == true) { r.hasSouthDoor = true; } }
void makeDoors(DRoom r) { //create doors where needed. if (r.hasNorthDoor) { map_data[r.center_x, r.bottom] = (int)tileType.N_Normal_Door; //Debug.Log(new Vector3(r.center_x,0,r.bottom)); //GameObject wall = (GameObject) GameObject.Instantiate(wallGB, //new Vector3((r.center_x * tileSize),0,(r.bottom * tileSize) + -(size_z * tileSize)), Quaternion.identity); } if (r.hasWestDoor) { map_data[r.left, r.center_y] = (int)tileType.W_Normal_Door; //GameObject wall = (GameObject) GameObject.Instantiate(wallGB, //new Vector3((r.left * tileSize),0,(r.center_y * tileSize) + -(size_z * tileSize)), Quaternion.identity); } if (r.hasSouthDoor) { map_data[r.center_x, r.top] = (int)tileType.S_Normal_Door; //GameObject wall = (GameObject) GameObject.Instantiate(wallGB, //new Vector3((r.center_x * tileSize),0,(r.top * tileSize) + -(size_z * tileSize)), Quaternion.identity); } if (r.hasEastDoor) { map_data[r.right, r.center_y] = (int)tileType.E_Normal_Door; //GameObject wall = (GameObject) GameObject.Instantiate(wallGB, // new Vector3((r.right * tileSize),0,(r.center_y * tileSize) + -(size_z * tileSize)), Quaternion.identity); } }
void MakeCorridor(DRoom r1, DRoom r2) { int x = Random.Range(r1.left + 1, r1.right); int y = Random.Range(r1.top + 1, r1.bottom); //int x = r1.center_x; //int y = r1.center_y; int x2 = Random.Range(r2.left + 1, r2.right); int y2 = Random.Range(r2.top + 1, r2.bottom); while (y != y2) { map_data[x, y] = randomGround(); y += y < y2 ? 1 : -1; } while (x != x2) { map_data[x, y] = randomGround(); x += x < x2 ? 1 : -1; } r1.isConnected = true; r2.isConnected = true; }
void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0) { map_data[r.left + x, r.top + y] = lookupByName("Wall"); } else if (x == r.width - 1) { map_data[r.left + x, r.top + y] = lookupByName("Wall"); } else if (y == 0) { map_data[r.left + x, r.top + y] = lookupByName("Wall"); } else if (y == r.height - 1) { map_data[r.left + x, r.top + y] = lookupByName("Wall"); } else { map_data[r.left + x, r.top + y] = randomGround(); } } } }
}//CollidesWidth public void AddConnection(DRoom OtherRoom) { if (!Connections.Contains(OtherRoom) && OtherRoom != this) { Connections.Add(OtherRoom); } }//AddConnection
private void Format() { d_RoomInfo = new DRoom(); m_bFormatted = true; d_RoomInfo.d_Size = d_Size; d_RoomInfo.d_ID = m_nID; //0,0 locates in the left bottom corner. for (int i = 1; i < d_Size.d_nWidth - 1; i++) { int _tmp = i; if (d_Data[_tmp].d_bIsDoor) { d_RoomInfo.d_DoorList.AddLast(new DDoor(i, 0, DDoor.BOTTOM)); } _tmp = i + (d_Size.d_nHeight - 1) * d_Size.d_nWidth; if (d_Data[_tmp].d_bIsDoor) { d_RoomInfo.d_DoorList.AddLast(new DDoor(i, d_Size.d_nHeight - 1, DDoor.TOP)); } } for (int i = 1; i < d_Size.d_nHeight - 1; i++) { int _tmp = i * d_Size.d_nWidth; if (d_Data[_tmp].d_bIsDoor) { d_RoomInfo.d_DoorList.AddLast(new DDoor(0, i, DDoor.LEFT)); } _tmp = i * d_Size.d_nWidth + d_Size.d_nWidth - 1; if (d_Data[_tmp].d_bIsDoor) { d_RoomInfo.d_DoorList.AddLast(new DDoor(d_Size.d_nWidth - 1, i, DDoor.RIGHT)); } } }
/* * 0 = unknown * 1 = floor * 2 = wall * 3 = stone */ // Constructor public TDMap(int width, int height) { this.sizeX = width; this.sizeY = height; mapData = new int[sizeX, sizeY]; for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { mapData[x, y] = 3; } } rooms = new List <DRoom> (); int maxFails = 3; while (rooms.Count < 10) { int rsx = Random.Range(4, 8); int rsy = Random.Range(4, 8); DRoom r = new DRoom(); r.left = Random.Range(0, sizeX - rsx); r.top = Random.Range(0, sizeY - rsy); r.width = rsx; r.height = rsy; if (!RoomCollides(r)) { rooms.Add(r); } else { maxFails--; if (maxFails <= 0) { break; } } } foreach (DRoom r in rooms) { MakeRoom(r); } for (int i = 0; i < rooms.Count; i++) { if (!rooms[i].isConnected) { int j = Random.Range(1, rooms.Count); MakeCorridor(rooms[i], rooms[(i + j) % rooms.Count]); } } MakeWalls(); }
public DRoom(DRoom room) { d_ID = room.d_ID; d_Size = new DSizeN(room.d_Size.d_nWidth, room.d_Size.d_nHeight); d_DoorList = new LinkedList <DDoor>(); foreach (DDoor _door in room.d_DoorList) { d_DoorList.AddLast(new DDoor(_door)); } }
bool RoomCollides(DRoom r) { foreach (DRoom r2 in rooms) { if (r.CollidesWith(r2)) { return(true); } } return(false); }
public DTileMap(int size_x, int size_y) { DRoom r; this.sizeX = size_x; this.sizeY = size_y; map_data = new int[size_x, size_y]; rooms = new List <DRoom>(); int maxFails = 10; for (int i = 0; i < 10; i++) { int roomSizeX = Random.Range(4, 8); int roomSizeY = Random.Range(4, 8); r = new DRoom(); r.left = Random.Range(0, size_x - roomSizeX); r.top = Random.Range(0, size_y - roomSizeY); r.width = roomSizeX; r.height = roomSizeY; if (!RoomCollider(r)) { rooms.Add(r); } else { maxFails--; if (maxFails <= 0) { break; } } foreach (DRoom r2 in rooms) { MakeRoom(r2); } for (int j = 0; j < rooms.Count; j++) { if (!rooms[j].isConnected) { int k = Random.Range(1, rooms.Count); MakeCorridor(rooms[j], rooms[(j + k) % rooms.Count]); } } //MakeCorridor(rooms[0], rooms[1]); } }
void makeSet3Body3Room(DRoom r) { //make floors and wall for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { //Debug.Log(x + " " + y); //make wall //use r property to create colliders if (addWallColliders(r, x, y)) { //makes wall } //Make Content of Room else if ((x >= 1 && x <= 2 && y >= 1 && y <= 3) || (y >= 10 && y <= 11 && x >= 1 && x <= 2) || (x >= 8 && x <= 9 && y >= 10 && y <= 11) || (x >= 2 && x <= 3 && y >= 6 && y <= 7) || (x >= 4 && x <= 5 && y >= 6 && y <= 9) || (x >= 9 && x <= 10 && y >= 4 && y <= 5) || (x == 5 && y >= 2 && y <= 3) || (x == 6 && y >= 2 && y <= 6) || (x == 7 && y >= 4 && y <= 7) || (x == 8 && y >= 5 && y <= 8) || (x == 11 && y >= 7 && y <= 11) || (x == 5 && y == 5) || (x == 9 && (y == 7 || y == 8))) { map_data[r.left + x, r.top + y] = (int)tileType.Barrier; GameObject wall = createWall(r.left + x, r.top + y); } else if (x == 6 & y == 7) { map_data[r.left + x, r.top + y] = (int)tileType.Objects; } else if (x == 8 && y == 4) { GameObject enemy = createEnemy(r.left + x, r.top + y); map_data[r.left + x, r.top + y] = (int)tileType.Monster_Spawn; } else if ((x == 5 && y == 4) || (x == 9 && y == 6)) { GameObject hazard = createHazard(r.left + x, r.top + y); map_data[r.left + x, r.top + y] = (int)tileType.Floor; } else { map_data[r.left + x, r.top + y] = (int)tileType.Floor; } } } //use r property to create colliders makeDoors(r); }
/* * 0 = unknown * 1 = floor * 2 = wall * 3 = stone */ public DTileMap(int size_x, int size_y) { DRoom r; this.size_x = size_x; this.size_y = size_y; map_data = new int[size_x,size_y]; for(int x=0;x<size_x;x++) { for(int y=0;y<size_y;y++) { map_data[x,y] = 3; } } rooms = new List<DRoom>(); int maxFails = 10; while(rooms.Count < 6) { int rsx = Random.Range(4,10); int rsy = Random.Range(4,5); r = new DRoom(); r.left = Random.Range(0, size_x - rsx); r.top = Random.Range(0, size_y-rsy); r.width = rsx; r.height = rsy; if(!RoomCollides(r)) { rooms.Add (r); } else { maxFails--; if(maxFails <=0) break; } } foreach(DRoom r2 in rooms) { MakeRoom(r2); } for(int i=0; i < rooms.Count; i++) { if(!rooms[i].isConnected) { int j = Random.Range(1, rooms.Count); MakeCorridor(rooms[i], rooms[(i + j) % rooms.Count ]); } } MakeWalls(); }
public override void Init() { base.Init(); //init room GameObject go = Instantiate(StartRoom) as GameObject; mCurRoom = go.GetComponent <DRoom>(); mCurRoom.CenterPos = Vector3.zero; mCurRoom.Init(); registerEvent(); mRoomList.Add(go); }
//Base Constructor public DTileMap(int size_x, int size_y, int numrooms, int roomsizex, int roomsizey , int x_range, int y_range) { this.size_x = size_x; this.size_y = size_y; this.num_rooms = numrooms; room_size_x = roomsizex; room_size_y = roomsizey; map_data = new int[size_x, size_y]; for(int x =0; x<size_x; x++) { for (int y = 0; y<size_y; y++) { map_data[x, y] = 3; //TDTile tile = new TDTile(TILE_TYPE.EMPTY); //tile.prefab = Instantiate( ) ; //tile_data[x, y] = tile; } } rooms = new List<DRoom>(); for (int i = 0; i < num_rooms; i++) { int rsx = Random.Range(room_size_x - x_range, room_size_x + x_range); int rsy = Random.Range(room_size_y - y_range, room_size_y + y_range); DRoom r = new DRoom(); r.left = Random.Range(0,size_x - rsx); r.top = Random.Range(0, size_y - rsy); r.width = rsx; r.height = rsy; if (!RoomCollides(r)) { rooms.Add(r); MakeRoom(r); } } if (rooms.Count > 1) MakeCorridor(rooms[0], rooms[1]); for( int i =0; i <rooms.Count; i++) { if (!rooms[i].isConnected) { int j = Random.Range(1,i - 1); MakeCorridor(rooms[i], rooms[(i + j) % rooms.Count]); } } MakeWalls(); }
void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0 && y == 0) // Lower Left Wall { map_data[r.left + x, r.top + y] = (int)TileType.LowerLeftWall; } else if (x == r.width - 1 && y == 0) // Lower Right Wall { map_data[r.left + x, r.top + y] = (int)TileType.LowerRightWall; } else if (x == 0 && y == r.height - 1) // Upper Left Wall { map_data[r.left + x, r.top + y] = (int)TileType.UpperLeftWall; } else if (x == r.width - 1 && y == r.height - 1) // Upper Right Wall { map_data[r.left + x, r.top + y] = (int)TileType.UpperRightWall; } else if (y == 0) // Down Wall { map_data[r.left + x, r.top + y] = (int)TileType.DownWall; } else if (x == 0) // Left Wall { map_data[r.left + x, r.top + y] = (int)TileType.LeftWall; } else if (x == r.width - 1) // Right Wall { map_data[r.left + x, r.top + y] = (int)TileType.RightWall; } else if (y == r.height - 1) // Up Wall { map_data[r.left + x, r.top + y] = (int)TileType.UpWall; } else if (x > 0 && x < r.width - 1 && y > 0 && y < r.height - 1) // Floor { map_data[r.left + x, r.top + y] = (int)TileType.Floor; } else // Unknown { map_data[r.left + x, r.top + y] = (int)TileType.Unknown; } //map_data[left + x, top + y] = (int)TileType.Floor; } } }
/// <summary> /// 远期房态 /// </summary> /// <returns></returns> public string HistoryState(string roomtype) { var data = string.Empty; if (string.IsNullOrEmpty(roomtype)) { data = new DRoom().HistoryState(); } else { data = new DRoom().HistoryState(roomtype); } //new Log().Info(data); return(data); }
public bool CollidesWith(DRoom other) { if( left > other.right-1 ) return false; if( top > other.bottom-1 ) return false; if( right < other.left+1 ) return false; if( bottom < other.top+1 ) return false; return true; }
/// <summary> /// 根据楼层取实时房态 /// </summary> /// <param name="floor">楼层</param> /// <returns></returns> public string RealTimeRoom(string floor) { var data = string.Empty; if (string.IsNullOrEmpty(floor)) { data = new DRoom().RealTimeState(); } else { data = new DRoom().RealTimeState(floor); } //new Log().Info(data); return(data); }
void makeSet1Body2Room(DRoom r) { //make floors and wall for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { //Debug.Log(x + " " + y); //make wall //use r property to create colliders if (addWallColliders(r, x, y)) { //makes wall } //Make Content of Room else if (x >= 3 && x <= 9 && y == 5 || x >= 3 && x <= 9 && y == 6) { map_data[r.left + x, r.top + y] = (int)tileType.Barrier; GameObject wall = createWall(r.left + x, r.top + y); } else if (x == 10 && y == 6) { map_data[r.left + x, r.top + y] = (int)tileType.Objects; } else if (x >= 2 && x <= 10 && y == 2 || x >= 2 && x <= 10 && y == 10) { GameObject hazard = createHazard(r.left + x, r.top + y); map_data[r.left + x, r.top + y] = (int)tileType.Floor; } else if (x == 6 && (y == 4 || y == 7)) { GameObject enemy = createEnemy(r.left + x, r.top + y); map_data[r.left + x, r.top + y] = (int)tileType.Monster_Spawn; } else { map_data[r.left + x, r.top + y] = (int)tileType.Floor; } } } //use r property to create colliders makeDoors(r); }
void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0 || x == r.width - 1 || y == 0 || y == r.height - 1) { mapData[r.left + x, r.top + y] = 2; } else { mapData[r.left + x, r.top + y] = 1; } } } }
void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0 || x == r.width - 1 || y == 0 || y == r.height - 1) { _tiles[y * _width + x + r.top * _width + r.left].type = TDTile.TILES.WALL; } else { _tiles[y * _width + x + r.top * _width + r.left].type = TDTile.TILES.STONE; } } } }
void MakeCorridor(DRoom r1, DRoom r2) { int x = r1.centerX; int y = r1.centerY; while (x != r2.centerX) { map_data[x, y] = (int)TileType.Floor; x += x < r2.centerX ? 1 : -1; } while (y != r2.centerY) { map_data[x, y] = (int)TileType.Floor; y += y < r2.centerY ? 1 : -1; } }
void makeSet1Body1Room(DRoom r) { //make floors and wall for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { //Debug.Log(x + " " + y); //make wall //use r property to create colliders if (addWallColliders(r, x, y)) { //makes wall } //Make Content of Room else if ((x == 2 && (y >= 3 && y <= 9)) || (x == 10 && (y >= 3 && y <= 9)) || ((x >= 4 && x <= 8) && y == 9) || ((x >= 4 && x <= 8) && y == 3) || ((x >= 5 && x <= 7) && y == 5) || ((x >= 5 && x <= 7) && y == 7)) { map_data[r.left + x, r.top + y] = (int)tileType.Barrier; GameObject wall = createWall(r.left + x, r.top + y); } else if (x == 6 && y == 6) { map_data[r.left + x, r.top + y] = (int)tileType.Objects; } else if ((x >= 5 && x <= 7) && y == 4) { GameObject hazard = createHazard(r.left + x, r.top + y); map_data[r.left + x, r.top + y] = (int)tileType.Floor; } else { map_data[r.left + x, r.top + y] = (int)tileType.Floor; } } } //use r property to create colliders makeDoors(r); }
void MakeRoom(DRoom r) { for (int x = 0; x < r.width; x++) { for (int y = 0; y < r.height; y++) { if (x == 0 || x ==r.width-1 ||y==0 || y == r.height - 1){ map_data[r.left + x, r.top + y] = 2; } else { map_data[r.left + x, r.top + y] = 1; } } } }
void MakeCorridor(DRoom r1, DRoom r2) { int x = r1.center_x; int y = r1.center_y; while (x != r2.center_x) { map_data[x, y] = 1; x += x < r2.center_x ? 1 : -1;//Move x dir } while(y != r2.center_y) { map_data[x, y] = 1; y += y < r2.center_y ? 1 : -1;//Move y dir } r1.isConnected = true; }
bool RoomCollides(DRoom r) { foreach(DRoom r2 in rooms) { if (r.CollidesWith(r2)) { return true; } } return false; }