Map does stuff now?
This commit is contained in:
parent
39b5006295
commit
d4a876097d
2 changed files with 81 additions and 22 deletions
39
.vscode/launch.json
vendored
Normal file
39
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Unity Editor",
|
||||||
|
"type": "unity",
|
||||||
|
"path": "/t:/Unity Projects/LD44/Library/EditorInstance.json",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Windows Player",
|
||||||
|
"type": "unity",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "OSX Player",
|
||||||
|
"type": "unity",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Linux Player",
|
||||||
|
"type": "unity",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "iOS Player",
|
||||||
|
"type": "unity",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Android Player",
|
||||||
|
"type": "unity",
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public class MapRoom {
|
||||||
public readonly IntVector2 end;
|
public readonly IntVector2 end;
|
||||||
public readonly int mapSize;
|
public readonly int mapSize;
|
||||||
|
|
||||||
public MapRoom(int mapSize) {
|
public MapRoom(int mapSize, int maxRoomSize) {
|
||||||
this.mapSize = mapSize;
|
this.mapSize = mapSize;
|
||||||
start = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
start = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
||||||
end = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
end = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
||||||
|
@ -42,33 +42,45 @@ public class MapRoom {
|
||||||
start.y = end.y;
|
start.y = end.y;
|
||||||
end.y = swap;
|
end.y = swap;
|
||||||
}
|
}
|
||||||
|
if(end.x - start.x > maxRoomSize) {
|
||||||
|
end.x--;
|
||||||
|
start.x++;
|
||||||
|
}
|
||||||
|
if(end.y - start.y > maxRoomSize) {
|
||||||
|
end.y--;
|
||||||
|
start.y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RightCheck() {
|
||||||
|
return end.x < mapSize-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntVector2 RightCorridorAttachment() {
|
public IntVector2 RightCorridorAttachment() {
|
||||||
if(end.x+1 >= mapSize) {
|
|
||||||
throw new ImpossibleCorridorError();
|
|
||||||
}
|
|
||||||
return new IntVector2(end.x+1, Random.Range(start.y, end.y+1));
|
return new IntVector2(end.x+1, Random.Range(start.y, end.y+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntVector2 LeftCorridorAttachment() {
|
public bool LeftCheck() {
|
||||||
if(start.x-1 <= 0) {
|
return start.x > 0;
|
||||||
throw new ImpossibleCorridorError();
|
|
||||||
}
|
}
|
||||||
return new IntVector2(start.x-1, Random.Range(start.y, start.y-1));
|
|
||||||
|
public IntVector2 LeftCorridorAttachment() {
|
||||||
|
return new IntVector2(start.x-1, Random.Range(start.y, end.y+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TopCheck() {
|
||||||
|
return end.y < mapSize-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntVector2 TopCorridorAttachment() {
|
public IntVector2 TopCorridorAttachment() {
|
||||||
if(end.y+1 >= mapSize) {
|
|
||||||
throw new ImpossibleCorridorError();
|
|
||||||
}
|
|
||||||
return new IntVector2(Random.Range(start.x, end.x+1), end.y+1);
|
return new IntVector2(Random.Range(start.x, end.x+1), end.y+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntVector2 BottomCorridorAttachment() {
|
public bool BottomCheck() {
|
||||||
if(start.y-1 <= 0) {
|
return start.y > 0;
|
||||||
throw new ImpossibleCorridorError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IntVector2 BottomCorridorAttachment() {
|
||||||
return new IntVector2(Random.Range(start.x, end.x+1), start.y-1);
|
return new IntVector2(Random.Range(start.x, end.x+1), start.y-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,11 +100,12 @@ public class MapCorridor {
|
||||||
public MapCorridor(MapRoom from, MapRoom to, int mapSize) {
|
public MapCorridor(MapRoom from, MapRoom to, int mapSize) {
|
||||||
List<CorridorModes> corridorModes = new List<CorridorModes>();
|
List<CorridorModes> corridorModes = new List<CorridorModes>();
|
||||||
//Find allowed CorridorModes
|
//Find allowed CorridorModes
|
||||||
if(from.end.y <= to.start.y) corridorModes.Add(CorridorModes.bottomToTop);
|
if(from.end.y <= to.start.y && from.BottomCheck() && to.TopCheck()) corridorModes.Add(CorridorModes.bottomToTop);
|
||||||
if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.topToBottom);
|
if(from.start.y >= to.end.y && from.TopCheck() && to.BottomCheck()) corridorModes.Add(CorridorModes.topToBottom);
|
||||||
if(from.end.x <= to.start.y) corridorModes.Add(CorridorModes.rightToLeft);
|
if(from.end.x <= to.start.y && from.RightCheck() && to.LeftCheck()) corridorModes.Add(CorridorModes.rightToLeft);
|
||||||
if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.leftToRight);
|
if(from.start.y >= to.end.y && from.LeftCheck() && to.RightCheck()) corridorModes.Add(CorridorModes.leftToRight);
|
||||||
//Select and use a corridor mode
|
//Select and use a corridor mode
|
||||||
|
if(corridorModes.Count < 1) throw new ImpossibleCorridorError();
|
||||||
CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)];
|
CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)];
|
||||||
if(corridorMode == CorridorModes.bottomToTop) {
|
if(corridorMode == CorridorModes.bottomToTop) {
|
||||||
start = from.BottomCorridorAttachment();
|
start = from.BottomCorridorAttachment();
|
||||||
|
@ -123,6 +136,9 @@ public class Map : MonoBehaviour
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public int roomsToGenerate = 5;
|
public int roomsToGenerate = 5;
|
||||||
|
|
||||||
|
[BeforeStartAttribute]
|
||||||
|
public int maxRoomSize = 6;
|
||||||
|
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public Sprite wallSprite;
|
public Sprite wallSprite;
|
||||||
|
|
||||||
|
@ -218,15 +234,19 @@ public class Map : MonoBehaviour
|
||||||
private void GenerateMap() {
|
private void GenerateMap() {
|
||||||
FillWithWalls();
|
FillWithWalls();
|
||||||
while(rooms.Count < roomsToGenerate) {
|
while(rooms.Count < roomsToGenerate) {
|
||||||
MapRoom room = new MapRoom(mapSize);
|
MapRoom room = new MapRoom(mapSize, maxRoomSize);
|
||||||
if(ScanRoom(room)) {
|
if(ScanRoom(room)) {
|
||||||
PlaceRoom(room);
|
PlaceRoom(room);
|
||||||
rooms.Add(room);
|
rooms.Add(room);
|
||||||
}
|
}
|
||||||
if(rooms.Count > 1) {
|
if(rooms.Count > 1) {
|
||||||
MapRoom from = rooms[Random.Range(0, rooms.Count)];
|
MapRoom from = rooms[rooms.Count-1];
|
||||||
MapRoom to = rooms[Random.Range(0, rooms.Count)];
|
MapRoom to = room;
|
||||||
|
try {
|
||||||
MapCorridor corridor = new MapCorridor(from, to, mapSize);
|
MapCorridor corridor = new MapCorridor(from, to, mapSize);
|
||||||
|
PlaceCorridor(corridor);
|
||||||
|
}
|
||||||
|
catch (ImpossibleCorridorError) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue