cose
This commit is contained in:
parent
6c875795a8
commit
ca23b945df
6 changed files with 119 additions and 45 deletions
|
@ -45,8 +45,22 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
mapSize: 30
|
mapSize: 30
|
||||||
roomsToGenerate: 5
|
roomsToGenerate: 5
|
||||||
|
minRoomSize: 2
|
||||||
|
maxRoomSize: 6
|
||||||
|
maxRoomIterations: 100
|
||||||
wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3}
|
wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3}
|
||||||
roomSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
floorSprites:
|
||||||
corridorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
|
||||||
|
- {fileID: 21300000, guid: fa4c9841fd8a5fb4f94ff78c95301065, type: 3}
|
||||||
tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487,
|
tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
|
|
@ -341,15 +341,43 @@ PrefabInstance:
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: wallSprite
|
propertyPath: floorSprites.Array.size
|
||||||
|
value: 6
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: roomsToGenerate
|
||||||
|
value: 10
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: floorSprites.Array.data[2]
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 21300000, guid: 0121970e693ee0a4d987bd5fe694ad67,
|
objectReference: {fileID: 21300000, guid: fa4c9841fd8a5fb4f94ff78c95301065,
|
||||||
type: 3}
|
type: 3}
|
||||||
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: corridorSprite
|
propertyPath: floorSprites.Array.data[3]
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84,
|
objectReference: {fileID: 21300000, guid: fa4c9841fd8a5fb4f94ff78c95301065,
|
||||||
|
type: 3}
|
||||||
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: floorSprites.Array.data[4]
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 21300000, guid: fa4c9841fd8a5fb4f94ff78c95301065,
|
||||||
|
type: 3}
|
||||||
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: floorSprites.Array.data[5]
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 21300000, guid: fa4c9841fd8a5fb4f94ff78c95301065,
|
||||||
|
type: 3}
|
||||||
|
- target: {fileID: 6907631410461015020, guid: cd714ea41cb7c454994bf0f5ad99abd1,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: floorSprites.Array.data[1]
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf,
|
||||||
type: 3}
|
type: 3}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: cd714ea41cb7c454994bf0f5ad99abd1, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: cd714ea41cb7c454994bf0f5ad99abd1, type: 3}
|
||||||
|
|
|
@ -18,10 +18,10 @@ public class MapRoom {
|
||||||
public readonly Vector2Int 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, int minRoomSize) {
|
||||||
this.mapSize = mapSize;
|
this.mapSize = mapSize;
|
||||||
start = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
start = new Vector2Int(Random.Range(1, mapSize-1), Random.Range(1, mapSize-1));
|
||||||
end = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
|
end = new Vector2Int(Random.Range(1, mapSize-1), Random.Range(1, mapSize-1));
|
||||||
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;
|
||||||
|
@ -40,36 +40,30 @@ public class MapRoom {
|
||||||
end.y--;
|
end.y--;
|
||||||
start.y++;
|
start.y++;
|
||||||
}
|
}
|
||||||
}
|
while(end.x - start.x < minRoomSize) {
|
||||||
|
end.x++;
|
||||||
public bool RightCheck() {
|
start.x--;
|
||||||
return end.x < mapSize-1;
|
}
|
||||||
|
while(end.y - start.y < minRoomSize) {
|
||||||
|
end.y++;
|
||||||
|
start.y--;
|
||||||
|
}
|
||||||
|
start.Clamp(new Vector2Int(1, 1), new Vector2Int(mapSize-1, mapSize-1));
|
||||||
|
end.Clamp(new Vector2Int(1, 1), new Vector2Int(mapSize-1, mapSize-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2Int RightCorridorAttachment() {
|
public Vector2Int RightCorridorAttachment() {
|
||||||
return new Vector2Int(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() {
|
|
||||||
return start.x > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2Int LeftCorridorAttachment() {
|
public Vector2Int LeftCorridorAttachment() {
|
||||||
return new Vector2Int(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() {
|
|
||||||
return end.y < mapSize-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2Int TopCorridorAttachment() {
|
public Vector2Int TopCorridorAttachment() {
|
||||||
return new Vector2Int(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() {
|
|
||||||
return start.y > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2Int BottomCorridorAttachment() {
|
public Vector2Int BottomCorridorAttachment() {
|
||||||
return new Vector2Int(Random.Range(start.x, end.x+1), start.y-1);
|
return new Vector2Int(Random.Range(start.x, end.x+1), start.y-1);
|
||||||
}
|
}
|
||||||
|
@ -90,10 +84,10 @@ 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 && from.BottomCheck() && to.TopCheck()) corridorModes.Add(CorridorModes.bottomToTop);
|
if(from.end.y <= to.start.y) corridorModes.Add(CorridorModes.bottomToTop);
|
||||||
if(from.start.y >= to.end.y && from.TopCheck() && to.BottomCheck()) corridorModes.Add(CorridorModes.topToBottom);
|
if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.topToBottom);
|
||||||
if(from.end.x <= to.start.y && from.RightCheck() && to.LeftCheck()) corridorModes.Add(CorridorModes.rightToLeft);
|
if(from.end.x <= to.start.x) corridorModes.Add(CorridorModes.rightToLeft);
|
||||||
if(from.start.y >= to.end.y && from.LeftCheck() && to.RightCheck()) corridorModes.Add(CorridorModes.leftToRight);
|
if(from.start.x >= to.end.x) corridorModes.Add(CorridorModes.leftToRight);
|
||||||
//Select and use a corridor mode
|
//Select and use a corridor mode
|
||||||
if(corridorModes.Count < 1) throw new ImpossibleCorridorError();
|
if(corridorModes.Count < 1) throw new ImpossibleCorridorError();
|
||||||
CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)];
|
CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)];
|
||||||
|
@ -115,6 +109,9 @@ public class MapCorridor {
|
||||||
}
|
}
|
||||||
//50%
|
//50%
|
||||||
horizontal_priority = Random.Range(0f, 1f) >= 0.5f;
|
horizontal_priority = Random.Range(0f, 1f) >= 0.5f;
|
||||||
|
|
||||||
|
start.Clamp(new Vector2Int(1, 1), new Vector2Int(mapSize-1, mapSize-1));
|
||||||
|
end.Clamp(new Vector2Int(1, 1), new Vector2Int(mapSize-1, mapSize-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +123,9 @@ public class Map : MonoBehaviour
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public int roomsToGenerate = 5;
|
public int roomsToGenerate = 5;
|
||||||
|
|
||||||
|
[BeforeStartAttribute]
|
||||||
|
public int minRoomSize = 2;
|
||||||
|
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public int maxRoomSize = 6;
|
public int maxRoomSize = 6;
|
||||||
|
|
||||||
|
@ -136,10 +136,7 @@ public class Map : MonoBehaviour
|
||||||
public Sprite wallSprite;
|
public Sprite wallSprite;
|
||||||
|
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public Sprite roomSprite;
|
public List<Sprite> floorSprites;
|
||||||
|
|
||||||
[BeforeStartAttribute]
|
|
||||||
public Sprite corridorSprite;
|
|
||||||
|
|
||||||
[BeforeStartAttribute]
|
[BeforeStartAttribute]
|
||||||
public GameObject tilePrefab;
|
public GameObject tilePrefab;
|
||||||
|
@ -156,7 +153,12 @@ public class Map : MonoBehaviour
|
||||||
|
|
||||||
public bool CanMoveTo(Vector2Int direction)
|
public bool CanMoveTo(Vector2Int direction)
|
||||||
{
|
{
|
||||||
return GetTile(direction).walkable;
|
try {
|
||||||
|
return GetTile(direction).walkable;
|
||||||
|
}
|
||||||
|
catch(System.ArgumentOutOfRangeException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitTile(Vector2Int position, bool walkable, Sprite tileSprite, bool roomPart) {
|
private void InitTile(Vector2Int position, bool walkable, Sprite tileSprite, bool roomPart) {
|
||||||
|
@ -183,7 +185,7 @@ public class Map : MonoBehaviour
|
||||||
private void PlaceRoom(MapRoom mr) {
|
private void PlaceRoom(MapRoom mr) {
|
||||||
for(int x = mr.start.x; x <= mr.end.x; x++) {
|
for(int x = mr.start.x; x <= mr.end.x; x++) {
|
||||||
for(int y = mr.start.y; y <= mr.end.y; y++) {
|
for(int y = mr.start.y; y <= mr.end.y; y++) {
|
||||||
InitTile(new Vector2Int(x, y), true, roomSprite, true);
|
InitTile(new Vector2Int(x, y), true, GetFloorTileSprite(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,17 +204,17 @@ public class Map : MonoBehaviour
|
||||||
|
|
||||||
private void PlaceCorridor(MapCorridor mc) {
|
private void PlaceCorridor(MapCorridor mc) {
|
||||||
Vector2Int cursor = new Vector2Int(mc.start.x, mc.start.y);
|
Vector2Int cursor = new Vector2Int(mc.start.x, mc.start.y);
|
||||||
InitTile(cursor, true, corridorSprite, false);
|
InitTile(cursor, true, GetFloorTileSprite(), false);
|
||||||
if(mc.horizontal_priority) {
|
if(mc.horizontal_priority) {
|
||||||
while(cursor.x != mc.end.x) {
|
while(cursor.x != mc.end.x) {
|
||||||
if(cursor.x > mc.end.x) cursor.x--;
|
if(cursor.x > mc.end.x) cursor.x--;
|
||||||
else cursor.x++;
|
else cursor.x++;
|
||||||
InitTile(cursor, true, corridorSprite, false);
|
InitTile(cursor, true, GetFloorTileSprite(), false);
|
||||||
}
|
}
|
||||||
while(cursor.y != mc.end.y) {
|
while(cursor.y != mc.end.y) {
|
||||||
if(cursor.y > mc.end.y) cursor.y--;
|
if(cursor.y > mc.end.y) cursor.y--;
|
||||||
else cursor.y++;
|
else cursor.y++;
|
||||||
InitTile(cursor, true, corridorSprite, false);
|
InitTile(cursor, true, GetFloorTileSprite(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -220,12 +222,12 @@ public class Map : MonoBehaviour
|
||||||
while(cursor.y != mc.end.y) {
|
while(cursor.y != mc.end.y) {
|
||||||
if(cursor.y > mc.end.y) cursor.y--;
|
if(cursor.y > mc.end.y) cursor.y--;
|
||||||
else cursor.y++;
|
else cursor.y++;
|
||||||
InitTile(cursor, true, corridorSprite, false);
|
InitTile(cursor, true, GetFloorTileSprite(), false);
|
||||||
}
|
}
|
||||||
while(cursor.x != mc.end.x) {
|
while(cursor.x != mc.end.x) {
|
||||||
if(cursor.x > mc.end.x) cursor.x--;
|
if(cursor.x > mc.end.x) cursor.x--;
|
||||||
else cursor.x++;
|
else cursor.x++;
|
||||||
InitTile(cursor, true, corridorSprite, false);
|
InitTile(cursor, true, GetFloorTileSprite(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,11 +237,13 @@ public class Map : MonoBehaviour
|
||||||
int roomIterations = 0;
|
int roomIterations = 0;
|
||||||
while(rooms.Count < roomsToGenerate && roomIterations < maxRoomIterations) {
|
while(rooms.Count < roomsToGenerate && roomIterations < maxRoomIterations) {
|
||||||
roomIterations++;
|
roomIterations++;
|
||||||
MapRoom room = new MapRoom(mapSize, maxRoomSize);
|
MapRoom room = new MapRoom(mapSize, maxRoomSize, minRoomSize);
|
||||||
if(ScanRoom(room)) {
|
if(ScanRoom(room)) {
|
||||||
|
//Fill with the room
|
||||||
PlaceRoom(room);
|
PlaceRoom(room);
|
||||||
rooms.Add(room);
|
rooms.Add(room);
|
||||||
}
|
}
|
||||||
|
//Place a corridor
|
||||||
if(rooms.Count > 1) {
|
if(rooms.Count > 1) {
|
||||||
MapRoom from = rooms[rooms.Count-2];
|
MapRoom from = rooms[rooms.Count-2];
|
||||||
MapRoom to = rooms[rooms.Count-1];
|
MapRoom to = rooms[rooms.Count-1];
|
||||||
|
@ -247,11 +251,16 @@ public class Map : MonoBehaviour
|
||||||
MapCorridor corridor = new MapCorridor(from, to, mapSize);
|
MapCorridor corridor = new MapCorridor(from, to, mapSize);
|
||||||
PlaceCorridor(corridor);
|
PlaceCorridor(corridor);
|
||||||
}
|
}
|
||||||
catch (ImpossibleCorridorError) {}
|
catch (ImpossibleCorridorError) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Sprite GetFloorTileSprite() {
|
||||||
|
return floorSprites[Random.Range(0, floorSprites.Count)];
|
||||||
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
//Initialize everything
|
//Initialize everything
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class Monster : MonoBehaviour
|
||||||
private Map map;
|
private Map map;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
|
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
|
||||||
hasSpottedPlayer = false;
|
hasSpottedPlayer = false;
|
||||||
|
|
|
@ -45,7 +45,7 @@ TextureImporter:
|
||||||
spriteMeshType: 1
|
spriteMeshType: 1
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 40
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
|
@ -69,6 +69,28 @@ TextureImporter:
|
||||||
allowsAlphaSplitting: 0
|
allowsAlphaSplitting: 0
|
||||||
overridden: 0
|
overridden: 0
|
||||||
androidETC2FallbackOverride: 0
|
androidETC2FallbackOverride: 0
|
||||||
|
- serializedVersion: 2
|
||||||
|
buildTarget: Standalone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
- serializedVersion: 2
|
||||||
|
buildTarget: WebGL
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
spriteSheet:
|
spriteSheet:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
sprites: []
|
sprites: []
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
--- !u!78 &1
|
--- !u!78 &1
|
||||||
TagManager:
|
TagManager:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
tags: []
|
tags:
|
||||||
|
- Map
|
||||||
layers:
|
layers:
|
||||||
- Default
|
- Default
|
||||||
- TransparentFX
|
- TransparentFX
|
||||||
|
|
Loading…
Reference in a new issue