1
Fork 0

Use vector2int instead of a new class

This commit is contained in:
Steffo 2019-04-27 17:20:25 +02:00
parent c53e5acdd2
commit 0abae3b3b7

View file

@ -13,25 +13,15 @@ public class ImpossibleCorridorError : System.Exception
System.Runtime.Serialization.StreamingContext context) : base(info, context) { } System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
} }
public class IntVector2 {
public int x;
public int y;
public IntVector2(int x, int y) {
this.x = x;
this.y = y;
}
}
public class MapRoom { public class MapRoom {
public readonly IntVector2 start; public readonly Vector2Int start;
public readonly IntVector2 end; public readonly Vector2Int end;
public readonly int mapSize; public readonly int mapSize;
public MapRoom(int mapSize, int maxRoomSize) { 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 Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
end = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize)); end = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
if(start.x > end.x) { if(start.x > end.x) {
int swap = start.x; int swap = start.x;
start.x = end.x; start.x = end.x;
@ -56,32 +46,32 @@ public class MapRoom {
return end.x < mapSize-1; return end.x < mapSize-1;
} }
public IntVector2 RightCorridorAttachment() { public Vector2Int RightCorridorAttachment() {
return new IntVector2(end.x+1, Random.Range(start.y, end.y+1)); return new Vector2Int(end.x+1, Random.Range(start.y, end.y+1));
} }
public bool LeftCheck() { public bool LeftCheck() {
return start.x > 0; return start.x > 0;
} }
public IntVector2 LeftCorridorAttachment() { public Vector2Int LeftCorridorAttachment() {
return new IntVector2(start.x-1, Random.Range(start.y, end.y+1)); return new Vector2Int(start.x-1, Random.Range(start.y, end.y+1));
} }
public bool TopCheck() { public bool TopCheck() {
return end.y < mapSize-1; return end.y < mapSize-1;
} }
public IntVector2 TopCorridorAttachment() { public Vector2Int TopCorridorAttachment() {
return new IntVector2(Random.Range(start.x, end.x+1), end.y+1); return new Vector2Int(Random.Range(start.x, end.x+1), end.y+1);
} }
public bool BottomCheck() { public bool BottomCheck() {
return start.y > 0; return start.y > 0;
} }
public IntVector2 BottomCorridorAttachment() { public Vector2Int BottomCorridorAttachment() {
return new IntVector2(Random.Range(start.x, end.x+1), start.y-1); return new Vector2Int(Random.Range(start.x, end.x+1), start.y-1);
} }
} }
@ -93,8 +83,8 @@ public enum CorridorModes {
} }
public class MapCorridor { public class MapCorridor {
public readonly IntVector2 start; public readonly Vector2Int start;
public readonly IntVector2 end; public readonly Vector2Int end;
public readonly bool horizontal_priority; public readonly bool horizontal_priority;
public MapCorridor(MapRoom from, MapRoom to, int mapSize) { public MapCorridor(MapRoom from, MapRoom to, int mapSize) {
@ -206,7 +196,7 @@ public class Map : MonoBehaviour
} }
private void PlaceCorridor(MapCorridor mc) { private void PlaceCorridor(MapCorridor mc) {
IntVector2 cursor = new IntVector2(mc.start.x, mc.start.y); Vector2Int cursor = new Vector2Int(mc.start.x, mc.start.y);
InitTile(cursor.x, cursor.y, true, corridorSprite, false); InitTile(cursor.x, cursor.y, true, corridorSprite, false);
if(mc.horizontal_priority) { if(mc.horizontal_priority) {
while(cursor.x != mc.end.x) { while(cursor.x != mc.end.x) {