Ejemplo n.º 1
0
		public int Distance (Room target)
		{
			return Mathf.Abs (this.PosY - target.PosX) + Mathf.Abs (this.PosY - target.PosX);
		}
Ejemplo n.º 2
0
		void ConnectRooms (Room origin, Room target)
		{
			bool _dirX = origin.PosX < target.PosX;
			bool _dirY = origin.PosY < target.PosY;

			int dirX = _dirX ? 1 : -1;
			int dirY = _dirY ? 1 : -1;

			int targetX = target.PosX * cellSizeX + cellSizeX / 2;
			int targetY = target.PosY * cellSizeY + cellSizeY / 2;
			int roomX = origin.PosX * cellSizeY + cellSizeY / 2;
			int roomY = origin.PosY * cellSizeY + cellSizeY / 2;

			//Строим коридор
			for (int n = roomX - dirX; (n != (targetX + dirX * 2)); n += dirX) {
				if (n < map.GetLength (0) && map [n, roomY] != 1) {
					map [n, roomY] = 2;
					if (map [n, roomY + 1] != 1) {
						map [n, roomY + 1] = 2;
					}
					if (map [n, roomY + 2] == 0) {
						map [n, roomY + 2] = 3;
					}
					if (map [n, roomY - 1] != 1) {
						map [n, roomY - 1] = 2;
					}
//					if (map [n, roomY - 2] == 0) {
//						map [n, roomY - 2] = 3;
//					}
				}
			}

			for (int j = roomY - dirY; (j != targetY + dirY * 2); j += dirY) {
				if (map [targetX, j] != 1) {
					map [targetX, j] = 2;

					if (map [targetX + 1, j] != 1) {
						map [targetX + 1, j] = 2;
					}
					if (map [targetX + 2, j] == 0) {
						map [targetX + 2, j] = 3;
					}
					if (map [targetX - 1, j] != 1) {
						map [targetX - 1, j] = 2;
					}
//					if (map [targetX - 2, j] == 0) {
//						map [targetX - 2, j] = 3;
//					}

				}
			}
		}