From fbd17b8ae5a8b6c3f5136a0eef04e26a159dd1dc Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 13:38:29 +0200 Subject: [PATCH 1/9] Create WIP map script --- Assets/Scripts/Map.cs | 81 ++++++++++++++++++++ Assets/Scripts/{Test.cs.meta => Map.cs.meta} | 2 +- Assets/Scripts/Test.cs | 18 ----- Assets/Scripts/Tile.cs | 17 ++++ Assets/Scripts/Tile.cs.meta | 11 +++ 5 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 Assets/Scripts/Map.cs rename Assets/Scripts/{Test.cs.meta => Map.cs.meta} (83%) delete mode 100644 Assets/Scripts/Test.cs create mode 100644 Assets/Scripts/Tile.cs create mode 100644 Assets/Scripts/Tile.cs.meta diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs new file mode 100644 index 0000000..be6b013 --- /dev/null +++ b/Assets/Scripts/Map.cs @@ -0,0 +1,81 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Map : MonoBehaviour +{ + public const int SIZE_X = 30; + public const int SIZE_Y = 30; + public GameObject[,] tiles; + public Sprite wallSprite; + public Sprite floorSprite; + public GameObject tilePrefab; + + public Tile GetTile(int x, int y) { + GameObject tileObject = tiles[x, y]; + Tile tile = tileObject.GetComponent(); + return tile; + } + + private void InitTile(int x, int y, bool is_walkable, Sprite tile_sprite) { + GameObject tileObject = Instantiate(tilePrefab); + tileObject.transform.position = new Vector3(x, y, 0); + tiles[x, y] = tileObject; + Tile tile = GetTile(x, y); + tile.is_walkable = is_walkable; + tile.tile_sprite = tile_sprite; + } + + private void FillWithWalls() { + for(int x = 0; x < SIZE_X; x++) { + for(int y = 0; y < SIZE_Y; y++) { + InitTile(x, y, false, wallSprite); + } + } + } + + private void GenerateSquare(int start_x, int start_y, int end_x, int end_y) { + for(int x = start_x; x <= end_x; x++) { + for(int y = start_y; y <= end_y; y++) { + InitTile(x, y, true, floorSprite); + } + } + } + + private void GenerateCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) { + if(horizontal_priority) { + for(int x = start_x; x <= end_x; x++) { + InitTile(x, start_y, true, floorSprite); + } + for(int y = start_y; y <= end_y; y++) { + InitTile(end_x, y, true, floorSprite); + } + } + else { + for(int y = start_y; y <= end_y; y++) { + InitTile(start_x, y, true, floorSprite); + } + for(int x = start_x; x <= end_x; x++) { + InitTile(x, end_y, true, floorSprite); + } + } + } + + private void GenerateMap() { + FillWithWalls(); + //Generate a random Square + int start_x = Random.Range(0, SIZE_X); + int start_y = Random.Range(0, SIZE_Y); + int end_x = Random.Range(start_x, SIZE_X); + int end_y = Random.Range(start_y, SIZE_Y); + GenerateSquare(start_x, start_y, end_x, end_y); + } + + private void Start() + { + //Create the tile array + tiles = new GameObject[SIZE_X, SIZE_Y]; + //Generate the map + GenerateMap(); + } +} diff --git a/Assets/Scripts/Test.cs.meta b/Assets/Scripts/Map.cs.meta similarity index 83% rename from Assets/Scripts/Test.cs.meta rename to Assets/Scripts/Map.cs.meta index ef9de0e..659896b 100644 --- a/Assets/Scripts/Test.cs.meta +++ b/Assets/Scripts/Map.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3a2a8e24cbb5e9a4f88abc3055e15cb7 +guid: 052bc569472779a429bfc51246f723d4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Test.cs b/Assets/Scripts/Test.cs deleted file mode 100644 index 2f5a7ab..0000000 --- a/Assets/Scripts/Test.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Test : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Tile.cs b/Assets/Scripts/Tile.cs new file mode 100644 index 0000000..3de0bc6 --- /dev/null +++ b/Assets/Scripts/Tile.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Tile : MonoBehaviour +{ + public bool is_walkable; + public Sprite tile_sprite; + + private SpriteRenderer spriteRenderer; + + private void Start() + { + spriteRenderer = GetComponent(); + spriteRenderer.sprite = tile_sprite; + } +} diff --git a/Assets/Scripts/Tile.cs.meta b/Assets/Scripts/Tile.cs.meta new file mode 100644 index 0000000..cb27721 --- /dev/null +++ b/Assets/Scripts/Tile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4df8012d0534aea47b137c1838a5a6af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From d20edc3663beca09721c25b2ba4ba0fbc9728dfe Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 14:21:33 +0200 Subject: [PATCH 2/9] Update a lot of stuff --- Assets/Editor.meta | 8 ++ Assets/Editor/BeforeStartAttributeDrawer.cs | 21 ++++ .../Editor/BeforeStartAttributeDrawer.cs.meta | 11 ++ Assets/Prefabs/Map.prefab | 49 ++++++++ Assets/Prefabs/Map.prefab.meta | 7 ++ Assets/Prefabs/Tile.prefab | 96 +++++++++++++++ Assets/Prefabs/Tile.prefab.meta | 7 ++ Assets/Scenes/Steffo.unity | 69 +++++++++++ Assets/Scripts/BeforeStartAttribute.cs | 5 + Assets/Scripts/BeforeStartAttribute.cs.meta | 11 ++ Assets/Scripts/Map.cs | 48 +++++--- Assets/Scripts/Tile.cs | 6 +- Assets/Sprites/PurpleTileset.png.meta | 112 ++++++++++++++++++ 13 files changed, 428 insertions(+), 22 deletions(-) create mode 100644 Assets/Editor.meta create mode 100644 Assets/Editor/BeforeStartAttributeDrawer.cs create mode 100644 Assets/Editor/BeforeStartAttributeDrawer.cs.meta create mode 100644 Assets/Prefabs/Map.prefab create mode 100644 Assets/Prefabs/Map.prefab.meta create mode 100644 Assets/Prefabs/Tile.prefab create mode 100644 Assets/Prefabs/Tile.prefab.meta create mode 100644 Assets/Scripts/BeforeStartAttribute.cs create mode 100644 Assets/Scripts/BeforeStartAttribute.cs.meta create mode 100644 Assets/Sprites/PurpleTileset.png.meta diff --git a/Assets/Editor.meta b/Assets/Editor.meta new file mode 100644 index 0000000..b718f6a --- /dev/null +++ b/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fd1b080c01a34694793e8f2ff140bfc0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/BeforeStartAttributeDrawer.cs b/Assets/Editor/BeforeStartAttributeDrawer.cs new file mode 100644 index 0000000..19006b1 --- /dev/null +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs @@ -0,0 +1,21 @@ +//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html +using UnityEngine; +using UnityEditor; + +[CustomPropertyDrawer(typeof(BeforeStartAttribute))] +public class BeforeStartAttributeDrawer : PropertyDrawer +{ + // Necessary since some properties tend to collapse smaller than their content + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label, true); + } + + // Draw a disabled property field + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + GUI.enabled = !Application.isPlaying; + EditorGUI.PropertyField(position, property, label, true); + GUI.enabled = true; + } +} \ No newline at end of file diff --git a/Assets/Editor/BeforeStartAttributeDrawer.cs.meta b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta new file mode 100644 index 0000000..4216c56 --- /dev/null +++ b/Assets/Editor/BeforeStartAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13bad693cf0c2634ea1e2be679edf00f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Map.prefab b/Assets/Prefabs/Map.prefab new file mode 100644 index 0000000..aa46ee0 --- /dev/null +++ b/Assets/Prefabs/Map.prefab @@ -0,0 +1,49 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7249059666095778526 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7249059666095778521} + - component: {fileID: 6907631410461015020} + m_Layer: 0 + m_Name: Map + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7249059666095778521 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7249059666095778526} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6907631410461015020 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7249059666095778526} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 052bc569472779a429bfc51246f723d4, type: 3} + m_Name: + m_EditorClassIdentifier: + wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3} + floorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487, + type: 3} diff --git a/Assets/Prefabs/Map.prefab.meta b/Assets/Prefabs/Map.prefab.meta new file mode 100644 index 0000000..f5813e2 --- /dev/null +++ b/Assets/Prefabs/Map.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cd714ea41cb7c454994bf0f5ad99abd1 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Tile.prefab b/Assets/Prefabs/Tile.prefab new file mode 100644 index 0000000..7104d56 --- /dev/null +++ b/Assets/Prefabs/Tile.prefab @@ -0,0 +1,96 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3219556109866242471 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3219556109866242468} + - component: {fileID: 9040756953319481538} + - component: {fileID: 1691311275711631131} + m_Layer: 0 + m_Name: Tile + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3219556109866242468 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3219556109866242471} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &9040756953319481538 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3219556109866242471} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4df8012d0534aea47b137c1838a5a6af, type: 3} + m_Name: + m_EditorClassIdentifier: + walkable: 0 + sprite: {fileID: 0} +--- !u!212 &1691311275711631131 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3219556109866242471} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 0 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 diff --git a/Assets/Prefabs/Tile.prefab.meta b/Assets/Prefabs/Tile.prefab.meta new file mode 100644 index 0000000..493ffc6 --- /dev/null +++ b/Assets/Prefabs/Tile.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0e0b618b5499bbb40b076c0291d55487 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Steffo.unity b/Assets/Scenes/Steffo.unity index ccc28e4..3b2ac89 100644 --- a/Assets/Scenes/Steffo.unity +++ b/Assets/Scenes/Steffo.unity @@ -272,3 +272,72 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 4c25f33cb89f6624db48fc49d353a7f2, type: 3} +--- !u!1001 &7249059666254997933 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 7249059666095778526, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_Name + value: Map + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: cd714ea41cb7c454994bf0f5ad99abd1, type: 3} diff --git a/Assets/Scripts/BeforeStartAttribute.cs b/Assets/Scripts/BeforeStartAttribute.cs new file mode 100644 index 0000000..cd1cf30 --- /dev/null +++ b/Assets/Scripts/BeforeStartAttribute.cs @@ -0,0 +1,5 @@ +using UnityEngine; + +public class BeforeStartAttribute : PropertyAttribute { + +} \ No newline at end of file diff --git a/Assets/Scripts/BeforeStartAttribute.cs.meta b/Assets/Scripts/BeforeStartAttribute.cs.meta new file mode 100644 index 0000000..68df79c --- /dev/null +++ b/Assets/Scripts/BeforeStartAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec73aa347f0168f4f95e1acbd3072646 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index be6b013..2ca3da7 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -4,8 +4,15 @@ using UnityEngine; public class Map : MonoBehaviour { - public const int SIZE_X = 30; - public const int SIZE_Y = 30; + [BeforeStartAttribute] + public int mapSize = 30; + + [BeforeStartAttribute] + public int roomsToGenerate = 5; + + [BeforeStartAttribute] + public int maxRoomSize = 8; + public GameObject[,] tiles; public Sprite wallSprite; public Sprite floorSprite; @@ -18,23 +25,25 @@ public class Map : MonoBehaviour } private void InitTile(int x, int y, bool is_walkable, Sprite tile_sprite) { - GameObject tileObject = Instantiate(tilePrefab); - tileObject.transform.position = new Vector3(x, y, 0); - tiles[x, y] = tileObject; Tile tile = GetTile(x, y); - tile.is_walkable = is_walkable; - tile.tile_sprite = tile_sprite; + tile.walkable = is_walkable; + tile.sprite = tile_sprite; } private void FillWithWalls() { - for(int x = 0; x < SIZE_X; x++) { - for(int y = 0; y < SIZE_Y; y++) { - InitTile(x, y, false, wallSprite); + for(int x = 0; x < mapSize; x++) { + for(int y = 0; y < mapSize; y++) { + GameObject tileObject = Instantiate(tilePrefab, transform); + tileObject.transform.position = new Vector3(x, y, 0); + tiles[x, y] = tileObject; + Tile tile = tileObject.GetComponent(); + tile.walkable = false; + tile.sprite = wallSprite; } } } - private void GenerateSquare(int start_x, int start_y, int end_x, int end_y) { + private void PlaceRoom(int start_x, int start_y, int end_x, int end_y) { for(int x = start_x; x <= end_x; x++) { for(int y = start_y; y <= end_y; y++) { InitTile(x, y, true, floorSprite); @@ -42,7 +51,7 @@ public class Map : MonoBehaviour } } - private void GenerateCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) { + private void PlaceCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) { if(horizontal_priority) { for(int x = start_x; x <= end_x; x++) { InitTile(x, start_y, true, floorSprite); @@ -63,18 +72,19 @@ public class Map : MonoBehaviour private void GenerateMap() { FillWithWalls(); - //Generate a random Square - int start_x = Random.Range(0, SIZE_X); - int start_y = Random.Range(0, SIZE_Y); - int end_x = Random.Range(start_x, SIZE_X); - int end_y = Random.Range(start_y, SIZE_Y); - GenerateSquare(start_x, start_y, end_x, end_y); + for(int i = 0; i < roomsToGenerate; i++) { + int start_x = Random.Range(0, mapSize); + int start_y = Random.Range(0, mapSize); + int end_x = Random.Range(0, mapSize) + start_x; + int end_y = Random.Range(0, mapSize) + start_y; + PlaceRoom(start_x, start_y, end_x, end_y); + } } private void Start() { //Create the tile array - tiles = new GameObject[SIZE_X, SIZE_Y]; + tiles = new GameObject[mapSize, mapSize]; //Generate the map GenerateMap(); } diff --git a/Assets/Scripts/Tile.cs b/Assets/Scripts/Tile.cs index 3de0bc6..c699f9c 100644 --- a/Assets/Scripts/Tile.cs +++ b/Assets/Scripts/Tile.cs @@ -4,14 +4,14 @@ using UnityEngine; public class Tile : MonoBehaviour { - public bool is_walkable; - public Sprite tile_sprite; + public bool walkable; + public Sprite sprite; private SpriteRenderer spriteRenderer; private void Start() { spriteRenderer = GetComponent(); - spriteRenderer.sprite = tile_sprite; + spriteRenderer.sprite = sprite; } } diff --git a/Assets/Sprites/PurpleTileset.png.meta b/Assets/Sprites/PurpleTileset.png.meta new file mode 100644 index 0000000..2135d63 --- /dev/null +++ b/Assets/Sprites/PurpleTileset.png.meta @@ -0,0 +1,112 @@ +fileFormatVersion: 2 +guid: e0e60c9a4ff0b8e429e6cfe316da9bbf +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 40 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 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: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 9a9cdb0ef0236d64bbd871c33fd3d927 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: From c4a244439e4bcb4dcdca59a52a843a18e304c9c5 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Sat, 27 Apr 2019 14:40:09 +0200 Subject: [PATCH 3/9] Player class Add basic player movement --- Assets/Animations.meta | 8 --- Assets/Animators.meta | 8 --- Assets/Assets.meta | 8 --- Assets/PhysMats.meta | 8 --- Assets/Scripts/Player.cs | 56 +++++++++++++++++ Assets/Scripts/Player.cs.meta | 11 ++++ Assets/Sounds.meta | 8 --- Assets/Sprites/PurpleTileset.png.meta | 90 +++++++++++++++++++++++++++ 8 files changed, 157 insertions(+), 40 deletions(-) delete mode 100644 Assets/Animations.meta delete mode 100644 Assets/Animators.meta delete mode 100644 Assets/Assets.meta delete mode 100644 Assets/PhysMats.meta create mode 100644 Assets/Scripts/Player.cs create mode 100644 Assets/Scripts/Player.cs.meta delete mode 100644 Assets/Sounds.meta create mode 100644 Assets/Sprites/PurpleTileset.png.meta diff --git a/Assets/Animations.meta b/Assets/Animations.meta deleted file mode 100644 index b2a79e2..0000000 --- a/Assets/Animations.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ef3d86d84c224344a94715cdfa9fe32c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Animators.meta b/Assets/Animators.meta deleted file mode 100644 index 7ff80b8..0000000 --- a/Assets/Animators.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 043f304edcc831c4ea9fcf0e1a2e520d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Assets.meta b/Assets/Assets.meta deleted file mode 100644 index 4eba494..0000000 --- a/Assets/Assets.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0460346d99d385241a6d87bbd10aceb8 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/PhysMats.meta b/Assets/PhysMats.meta deleted file mode 100644 index bc5b1b2..0000000 --- a/Assets/PhysMats.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e823a56cb429e4b49becdc740fba66b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs new file mode 100644 index 0000000..163ba18 --- /dev/null +++ b/Assets/Scripts/Player.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Player : MonoBehaviour +{ + private int exp, level, hp; + public GameObject player; + public int startingHp; + public Map map; + //TODO: Aggiungi gli oggetti in inventario + + // Start is called before the first frame update + void Start() + { + hp = startingHp; + } + + // Update is called once per frame + void Update() + { + playerMovement(); + } + + void playerMovement() + { + if (Input.GetKey(KeyCode.A)) + { + if (is_valid_movement("left")) player.transform.Translate(Vector3.left); + } + if (Input.GetKey(KeyCode.D)) + { + if (is_valid_movement("right")) player.transform.Translate(Vector3.right); + } + if (Input.GetKey(KeyCode.W)) + { + if (is_valid_movement("up")) player.transform.Translate(Vector3.up); + } + if (Input.GetKey(KeyCode.S)) + { + if (is_valid_movement("down")) player.transform.Translate(Vector3.down); + } + } + + bool is_valid_movement(string direction) + { + Tile tile; + int posX = (int) player.transform.position.x; + int posY = (int) player.transform.position.y; + if (direction == "left") tile = map.GetTile(posX - 1, posY); + else if (direction == "right") tile = map.GetTile(posX + 1, posY); + else if (direction == "up") tile = map.GetTile(posX, posY + 1); + else tile = map.GetTile(posX, posY - 1); + return tile.walkable(); + } +} diff --git a/Assets/Scripts/Player.cs.meta b/Assets/Scripts/Player.cs.meta new file mode 100644 index 0000000..4cba488 --- /dev/null +++ b/Assets/Scripts/Player.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4de6b97c3d785d146a0df2c1c078fe91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sounds.meta b/Assets/Sounds.meta deleted file mode 100644 index 5fd147f..0000000 --- a/Assets/Sounds.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 19c0d85909aede34bb371863f187b9e0 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Sprites/PurpleTileset.png.meta b/Assets/Sprites/PurpleTileset.png.meta new file mode 100644 index 0000000..c4abff8 --- /dev/null +++ b/Assets/Sprites/PurpleTileset.png.meta @@ -0,0 +1,90 @@ +fileFormatVersion: 2 +guid: 61345c477d96361428c3eb1bfb0c293a +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 1cead1e412dade640b800b9e34ee4c89 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: From 66296dd31a853fff3e858d56f0a633ce04b6a353 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 14:52:24 +0200 Subject: [PATCH 4/9] walkable is not a method --- Assets/Scripts/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 163ba18..1f2e98b 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -51,6 +51,6 @@ public class Player : MonoBehaviour else if (direction == "right") tile = map.GetTile(posX + 1, posY); else if (direction == "up") tile = map.GetTile(posX, posY + 1); else tile = map.GetTile(posX, posY - 1); - return tile.walkable(); + return tile.walkable; } } From 39b50062957b67806a3075023c5c65ab8cd558ef Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 16:15:38 +0200 Subject: [PATCH 5/9] commit --- Assets/Animations.meta | 8 ++ Assets/Animators.meta | 8 ++ Assets/Assets.meta | 8 ++ Assets/PhysMats.meta | 8 ++ Assets/Prefabs/Map.prefab | 5 +- Assets/Scripts/Map.cs | 210 ++++++++++++++++++++++++++++++++------ Assets/Scripts/Tile.cs | 1 + Assets/Sounds.meta | 8 ++ 8 files changed, 226 insertions(+), 30 deletions(-) create mode 100644 Assets/Animations.meta create mode 100644 Assets/Animators.meta create mode 100644 Assets/Assets.meta create mode 100644 Assets/PhysMats.meta create mode 100644 Assets/Sounds.meta diff --git a/Assets/Animations.meta b/Assets/Animations.meta new file mode 100644 index 0000000..b2a79e2 --- /dev/null +++ b/Assets/Animations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ef3d86d84c224344a94715cdfa9fe32c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animators.meta b/Assets/Animators.meta new file mode 100644 index 0000000..7ff80b8 --- /dev/null +++ b/Assets/Animators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 043f304edcc831c4ea9fcf0e1a2e520d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Assets.meta b/Assets/Assets.meta new file mode 100644 index 0000000..4eba494 --- /dev/null +++ b/Assets/Assets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0460346d99d385241a6d87bbd10aceb8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PhysMats.meta b/Assets/PhysMats.meta new file mode 100644 index 0000000..bc5b1b2 --- /dev/null +++ b/Assets/PhysMats.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e823a56cb429e4b49becdc740fba66b9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Map.prefab b/Assets/Prefabs/Map.prefab index aa46ee0..e8043ff 100644 --- a/Assets/Prefabs/Map.prefab +++ b/Assets/Prefabs/Map.prefab @@ -43,7 +43,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 052bc569472779a429bfc51246f723d4, type: 3} m_Name: m_EditorClassIdentifier: + mapSize: 30 + roomsToGenerate: 5 wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3} - floorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + roomSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + corridorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487, type: 3} diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 2ca3da7..088866a 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -2,6 +2,119 @@ using System.Collections.Generic; using UnityEngine; +[System.Serializable] +public class ImpossibleCorridorError : System.Exception +{ + public ImpossibleCorridorError() { } + public ImpossibleCorridorError(string message) : base(message) { } + public ImpossibleCorridorError(string message, System.Exception inner) : base(message, inner) { } + protected ImpossibleCorridorError( + System.Runtime.Serialization.SerializationInfo info, + 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 readonly IntVector2 start; + public readonly IntVector2 end; + public readonly int mapSize; + + public MapRoom(int mapSize) { + this.mapSize = mapSize; + start = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize)); + end = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize)); + if(start.x > end.x) { + int swap = start.x; + start.x = end.x; + end.x = swap; + } + if(start.y > end.y) { + int swap = start.y; + start.y = end.y; + end.y = swap; + } + } + + public IntVector2 RightCorridorAttachment() { + if(end.x+1 >= mapSize) { + throw new ImpossibleCorridorError(); + } + return new IntVector2(end.x+1, Random.Range(start.y, end.y+1)); + } + + public IntVector2 LeftCorridorAttachment() { + if(start.x-1 <= 0) { + throw new ImpossibleCorridorError(); + } + return new IntVector2(start.x-1, Random.Range(start.y, start.y-1)); + } + + public IntVector2 TopCorridorAttachment() { + if(end.y+1 >= mapSize) { + throw new ImpossibleCorridorError(); + } + return new IntVector2(Random.Range(start.x, end.x+1), end.y+1); + } + + public IntVector2 BottomCorridorAttachment() { + if(start.y-1 <= 0) { + throw new ImpossibleCorridorError(); + } + return new IntVector2(Random.Range(start.x, end.x+1), start.y-1); + } +} + +public enum CorridorModes { + bottomToTop, + topToBottom, + rightToLeft, + leftToRight +} + +public class MapCorridor { + public readonly IntVector2 start; + public readonly IntVector2 end; + public readonly bool horizontal_priority; + + public MapCorridor(MapRoom from, MapRoom to, int mapSize) { + List corridorModes = new List(); + //Find allowed CorridorModes + if(from.end.y <= to.start.y) corridorModes.Add(CorridorModes.bottomToTop); + if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.topToBottom); + if(from.end.x <= to.start.y) corridorModes.Add(CorridorModes.rightToLeft); + if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.leftToRight); + //Select and use a corridor mode + CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)]; + if(corridorMode == CorridorModes.bottomToTop) { + start = from.BottomCorridorAttachment(); + end = to.TopCorridorAttachment(); + } + if(corridorMode == CorridorModes.topToBottom) { + start = from.TopCorridorAttachment(); + end = to.BottomCorridorAttachment(); + } + if(corridorMode == CorridorModes.rightToLeft) { + start = from.RightCorridorAttachment(); + end = to.LeftCorridorAttachment(); + } + if(corridorMode == CorridorModes.leftToRight) { + start = from.LeftCorridorAttachment(); + end = to.RightCorridorAttachment(); + } + //50% + horizontal_priority = Random.Range(0f, 1f) >= 0.5f; + } +} + public class Map : MonoBehaviour { [BeforeStartAttribute] @@ -11,23 +124,32 @@ public class Map : MonoBehaviour public int roomsToGenerate = 5; [BeforeStartAttribute] - public int maxRoomSize = 8; - - public GameObject[,] tiles; public Sprite wallSprite; - public Sprite floorSprite; + + [BeforeStartAttribute] + public Sprite roomSprite; + + [BeforeStartAttribute] + public Sprite corridorSprite; + + [BeforeStartAttribute] public GameObject tilePrefab; + private GameObject[,] tiles; + private List rooms; + private System.Random rnd; + public Tile GetTile(int x, int y) { GameObject tileObject = tiles[x, y]; Tile tile = tileObject.GetComponent(); return tile; } - private void InitTile(int x, int y, bool is_walkable, Sprite tile_sprite) { + private void InitTile(int x, int y, bool walkable, Sprite tile_sprite, bool roomPart) { Tile tile = GetTile(x, y); - tile.walkable = is_walkable; + tile.walkable = walkable; tile.sprite = tile_sprite; + tile.roomPart = roomPart; } private void FillWithWalls() { @@ -43,48 +165,78 @@ public class Map : MonoBehaviour } } - private void PlaceRoom(int start_x, int start_y, int end_x, int end_y) { - for(int x = start_x; x <= end_x; x++) { - for(int y = start_y; y <= end_y; y++) { - InitTile(x, y, true, floorSprite); + private void PlaceRoom(MapRoom mr) { + for(int x = mr.start.x; x <= mr.end.x; x++) { + for(int y = mr.start.y; y <= mr.end.y; y++) { + InitTile(x, y, true, roomSprite, true); } } } - private void PlaceCorridor(int start_x, int start_y, int end_x, int end_y, bool horizontal_priority) { - if(horizontal_priority) { - for(int x = start_x; x <= end_x; x++) { - InitTile(x, start_y, true, floorSprite); - } - for(int y = start_y; y <= end_y; y++) { - InitTile(end_x, y, true, floorSprite); + private bool ScanRoom(MapRoom mr) { + //Returns true if the room can be safely placed + for(int x = Mathf.Clamp(mr.start.x-1, 0, mapSize-1); x <= Mathf.Clamp(mr.end.x+1, 0, mapSize-1); x++) { + for(int y = Mathf.Clamp(mr.start.y-1, 0, mapSize-1); y <= Mathf.Clamp(mr.end.y+1, 0, mapSize-1); y++) { + if(GetTile(x, y).walkable) { + return false; + } } } - else { - for(int y = start_y; y <= end_y; y++) { - InitTile(start_x, y, true, floorSprite); + return true; + } + + private void PlaceCorridor(MapCorridor mc) { + IntVector2 cursor = new IntVector2(mc.start.x, mc.start.y); + InitTile(cursor.x, cursor.y, true, corridorSprite, false); + if(mc.horizontal_priority) { + while(cursor.x != mc.end.x) { + if(cursor.x > mc.end.x) cursor.x--; + else cursor.x++; + InitTile(cursor.x, cursor.y, true, corridorSprite, false); } - for(int x = start_x; x <= end_x; x++) { - InitTile(x, end_y, true, floorSprite); + while(cursor.y != mc.end.y) { + if(cursor.y > mc.end.y) cursor.y--; + else cursor.y++; + InitTile(cursor.x, cursor.y, true, corridorSprite, false); + } + } + else + { + while(cursor.y != mc.end.y) { + if(cursor.y > mc.end.y) cursor.y--; + else cursor.y++; + InitTile(cursor.x, cursor.y, true, corridorSprite, false); + } + while(cursor.x != mc.end.x) { + if(cursor.x > mc.end.x) cursor.x--; + else cursor.x++; + InitTile(cursor.x, cursor.y, true, corridorSprite, false); } } } private void GenerateMap() { FillWithWalls(); - for(int i = 0; i < roomsToGenerate; i++) { - int start_x = Random.Range(0, mapSize); - int start_y = Random.Range(0, mapSize); - int end_x = Random.Range(0, mapSize) + start_x; - int end_y = Random.Range(0, mapSize) + start_y; - PlaceRoom(start_x, start_y, end_x, end_y); + while(rooms.Count < roomsToGenerate) { + MapRoom room = new MapRoom(mapSize); + if(ScanRoom(room)) { + PlaceRoom(room); + rooms.Add(room); + } + if(rooms.Count > 1) { + MapRoom from = rooms[Random.Range(0, rooms.Count)]; + MapRoom to = rooms[Random.Range(0, rooms.Count)]; + MapCorridor corridor = new MapCorridor(from, to, mapSize); + } } } private void Start() { - //Create the tile array + //Initialize everything tiles = new GameObject[mapSize, mapSize]; + rooms = new List(); + rnd = new System.Random(); //Generate the map GenerateMap(); } diff --git a/Assets/Scripts/Tile.cs b/Assets/Scripts/Tile.cs index c699f9c..04dec14 100644 --- a/Assets/Scripts/Tile.cs +++ b/Assets/Scripts/Tile.cs @@ -5,6 +5,7 @@ using UnityEngine; public class Tile : MonoBehaviour { public bool walkable; + public bool roomPart; public Sprite sprite; private SpriteRenderer spriteRenderer; diff --git a/Assets/Sounds.meta b/Assets/Sounds.meta new file mode 100644 index 0000000..5fd147f --- /dev/null +++ b/Assets/Sounds.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 19c0d85909aede34bb371863f187b9e0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From d4a876097dbb8d063a663771be84cc75ba666b88 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 16:48:37 +0200 Subject: [PATCH 6/9] Map does stuff now? --- .vscode/launch.json | 39 ++++++++++++++++++++++++++ Assets/Scripts/Map.cs | 64 ++++++++++++++++++++++++++++--------------- 2 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ca87d3d --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 088866a..7fda22b 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -28,7 +28,7 @@ public class MapRoom { public readonly IntVector2 end; public readonly int mapSize; - public MapRoom(int mapSize) { + public MapRoom(int mapSize, int maxRoomSize) { this.mapSize = mapSize; start = 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; 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() { - if(end.x+1 >= mapSize) { - throw new ImpossibleCorridorError(); - } return new IntVector2(end.x+1, Random.Range(start.y, end.y+1)); } + public bool LeftCheck() { + return start.x > 0; + } + public IntVector2 LeftCorridorAttachment() { - if(start.x-1 <= 0) { - throw new ImpossibleCorridorError(); - } - return new IntVector2(start.x-1, Random.Range(start.y, start.y-1)); + return new IntVector2(start.x-1, Random.Range(start.y, end.y+1)); + } + + public bool TopCheck() { + return end.y < mapSize-1; } public IntVector2 TopCorridorAttachment() { - if(end.y+1 >= mapSize) { - throw new ImpossibleCorridorError(); - } return new IntVector2(Random.Range(start.x, end.x+1), end.y+1); } + public bool BottomCheck() { + return start.y > 0; + } + public IntVector2 BottomCorridorAttachment() { - if(start.y-1 <= 0) { - throw new ImpossibleCorridorError(); - } 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) { List corridorModes = new List(); //Find allowed CorridorModes - if(from.end.y <= to.start.y) corridorModes.Add(CorridorModes.bottomToTop); - if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.topToBottom); - if(from.end.x <= to.start.y) corridorModes.Add(CorridorModes.rightToLeft); - if(from.start.y >= to.end.y) corridorModes.Add(CorridorModes.leftToRight); + if(from.end.y <= to.start.y && from.BottomCheck() && to.TopCheck()) corridorModes.Add(CorridorModes.bottomToTop); + if(from.start.y >= to.end.y && from.TopCheck() && to.BottomCheck()) corridorModes.Add(CorridorModes.topToBottom); + if(from.end.x <= to.start.y && from.RightCheck() && to.LeftCheck()) corridorModes.Add(CorridorModes.rightToLeft); + if(from.start.y >= to.end.y && from.LeftCheck() && to.RightCheck()) corridorModes.Add(CorridorModes.leftToRight); //Select and use a corridor mode + if(corridorModes.Count < 1) throw new ImpossibleCorridorError(); CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)]; if(corridorMode == CorridorModes.bottomToTop) { start = from.BottomCorridorAttachment(); @@ -123,6 +136,9 @@ public class Map : MonoBehaviour [BeforeStartAttribute] public int roomsToGenerate = 5; + [BeforeStartAttribute] + public int maxRoomSize = 6; + [BeforeStartAttribute] public Sprite wallSprite; @@ -218,15 +234,19 @@ public class Map : MonoBehaviour private void GenerateMap() { FillWithWalls(); while(rooms.Count < roomsToGenerate) { - MapRoom room = new MapRoom(mapSize); + MapRoom room = new MapRoom(mapSize, maxRoomSize); if(ScanRoom(room)) { PlaceRoom(room); rooms.Add(room); } if(rooms.Count > 1) { - MapRoom from = rooms[Random.Range(0, rooms.Count)]; - MapRoom to = rooms[Random.Range(0, rooms.Count)]; - MapCorridor corridor = new MapCorridor(from, to, mapSize); + MapRoom from = rooms[rooms.Count-1]; + MapRoom to = room; + try { + MapCorridor corridor = new MapCorridor(from, to, mapSize); + PlaceCorridor(corridor); + } + catch (ImpossibleCorridorError) {} } } } From 0b74946998daea4d0a5d29f610ca6248875f81f8 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 17:18:09 +0200 Subject: [PATCH 7/9] Update map generation --- Assets/Scripts/Map.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 7fda22b..afb75b4 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -42,11 +42,11 @@ public class MapRoom { start.y = end.y; end.y = swap; } - if(end.x - start.x > maxRoomSize) { + while(end.x - start.x > maxRoomSize) { end.x--; start.x++; } - if(end.y - start.y > maxRoomSize) { + while(end.y - start.y > maxRoomSize) { end.y--; start.y++; } @@ -139,6 +139,9 @@ public class Map : MonoBehaviour [BeforeStartAttribute] public int maxRoomSize = 6; + [BeforeStartAttribute] + public int maxRoomIterations = 100; + [BeforeStartAttribute] public Sprite wallSprite; @@ -161,10 +164,10 @@ public class Map : MonoBehaviour return tile; } - private void InitTile(int x, int y, bool walkable, Sprite tile_sprite, bool roomPart) { + private void InitTile(int x, int y, bool walkable, Sprite tileSprite, bool roomPart) { Tile tile = GetTile(x, y); tile.walkable = walkable; - tile.sprite = tile_sprite; + tile.sprite = tileSprite; tile.roomPart = roomPart; } @@ -174,6 +177,7 @@ public class Map : MonoBehaviour GameObject tileObject = Instantiate(tilePrefab, transform); tileObject.transform.position = new Vector3(x, y, 0); tiles[x, y] = tileObject; + tileObject.name = "Tile [" + x.ToString() + ", " + y.ToString() + "]"; Tile tile = tileObject.GetComponent(); tile.walkable = false; tile.sprite = wallSprite; @@ -193,7 +197,7 @@ public class Map : MonoBehaviour //Returns true if the room can be safely placed for(int x = Mathf.Clamp(mr.start.x-1, 0, mapSize-1); x <= Mathf.Clamp(mr.end.x+1, 0, mapSize-1); x++) { for(int y = Mathf.Clamp(mr.start.y-1, 0, mapSize-1); y <= Mathf.Clamp(mr.end.y+1, 0, mapSize-1); y++) { - if(GetTile(x, y).walkable) { + if(GetTile(x, y).roomPart) { return false; } } @@ -233,15 +237,17 @@ public class Map : MonoBehaviour private void GenerateMap() { FillWithWalls(); - while(rooms.Count < roomsToGenerate) { + int roomIterations = 0; + while(rooms.Count < roomsToGenerate && roomIterations < maxRoomIterations) { + roomIterations++; MapRoom room = new MapRoom(mapSize, maxRoomSize); if(ScanRoom(room)) { PlaceRoom(room); rooms.Add(room); } if(rooms.Count > 1) { - MapRoom from = rooms[rooms.Count-1]; - MapRoom to = room; + MapRoom from = rooms[rooms.Count-2]; + MapRoom to = rooms[rooms.Count-1]; try { MapCorridor corridor = new MapCorridor(from, to, mapSize); PlaceCorridor(corridor); From 32c2382e067cfbe723e74e717c8632363515e3db Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Sat, 27 Apr 2019 17:18:44 +0200 Subject: [PATCH 8/9] Add a massive mess Bunch of unfinished code --- .vscode/settings.json | 56 +++++++++++++++++++++++++++ Assets/Animations.meta | 8 ---- Assets/Animators.meta | 8 ---- Assets/Assets.meta | 8 ---- Assets/PhysMats.meta | 8 ---- Assets/Scripts/Consumabile.cs | 32 +++++++++++++++ Assets/Scripts/Consumabile.cs.meta | 11 ++++++ Assets/Scripts/Map.cs.meta | 6 ++- Assets/Scripts/Mostro.cs | 62 ++++++++++++++++++++++++++++++ Assets/Scripts/Mostro.cs.meta | 11 ++++++ Assets/Scripts/Object.cs | 20 ++++++++++ Assets/Scripts/Object.cs.meta | 11 ++++++ Assets/Scripts/Player.cs | 16 ++++---- Assets/Sounds.meta | 8 ---- 14 files changed, 216 insertions(+), 49 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 Assets/Animations.meta delete mode 100644 Assets/Animators.meta delete mode 100644 Assets/Assets.meta delete mode 100644 Assets/PhysMats.meta create mode 100644 Assets/Scripts/Consumabile.cs create mode 100644 Assets/Scripts/Consumabile.cs.meta create mode 100644 Assets/Scripts/Mostro.cs create mode 100644 Assets/Scripts/Mostro.cs.meta create mode 100644 Assets/Scripts/Object.cs create mode 100644 Assets/Scripts/Object.cs.meta delete mode 100644 Assets/Sounds.meta diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4edd970 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":true, + "**/.gitignore":true, + "**/.gitmodules":true, + "**/*.booproj":true, + "**/*.pidb":true, + "**/*.suo":true, + "**/*.user":true, + "**/*.userprefs":true, + "**/*.unityproj":true, + "**/*.dll":true, + "**/*.exe":true, + "**/*.pdf":true, + "**/*.mid":true, + "**/*.midi":true, + "**/*.wav":true, + "**/*.gif":true, + "**/*.ico":true, + "**/*.jpg":true, + "**/*.jpeg":true, + "**/*.png":true, + "**/*.psd":true, + "**/*.tga":true, + "**/*.tif":true, + "**/*.tiff":true, + "**/*.3ds":true, + "**/*.3DS":true, + "**/*.fbx":true, + "**/*.FBX":true, + "**/*.lxo":true, + "**/*.LXO":true, + "**/*.ma":true, + "**/*.MA":true, + "**/*.obj":true, + "**/*.OBJ":true, + "**/*.asset":true, + "**/*.cubemap":true, + "**/*.flare":true, + "**/*.mat":true, + "**/*.meta":true, + "**/*.prefab":true, + "**/*.unity":true, + "build/":true, + "Build/":true, + "Library/":true, + "library/":true, + "obj/":true, + "Obj/":true, + "ProjectSettings/":true, + "temp/":true, + "Temp/":true + } +} \ No newline at end of file diff --git a/Assets/Animations.meta b/Assets/Animations.meta deleted file mode 100644 index b2a79e2..0000000 --- a/Assets/Animations.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ef3d86d84c224344a94715cdfa9fe32c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Animators.meta b/Assets/Animators.meta deleted file mode 100644 index 7ff80b8..0000000 --- a/Assets/Animators.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 043f304edcc831c4ea9fcf0e1a2e520d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Assets.meta b/Assets/Assets.meta deleted file mode 100644 index 4eba494..0000000 --- a/Assets/Assets.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0460346d99d385241a6d87bbd10aceb8 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/PhysMats.meta b/Assets/PhysMats.meta deleted file mode 100644 index bc5b1b2..0000000 --- a/Assets/PhysMats.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e823a56cb429e4b49becdc740fba66b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Consumabile.cs b/Assets/Scripts/Consumabile.cs new file mode 100644 index 0000000..aecdeda --- /dev/null +++ b/Assets/Scripts/Consumabile.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Consumabile : Object +{ + // Start is called before the first frame update + public enum Tipo {Cura, Danno}; + public GameObject player; + public Player player; + public int valore; + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + void use(){ + if (Tipo == Tipo.Cura){ + player.hp += valore; + if (player.hp >= player.maxhp) player.hp = player.maxhp; + } + if (Tipo == Tipo.Danno){ + player.hp -= valore; + } + } +} diff --git a/Assets/Scripts/Consumabile.cs.meta b/Assets/Scripts/Consumabile.cs.meta new file mode 100644 index 0000000..26b1684 --- /dev/null +++ b/Assets/Scripts/Consumabile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db5a27c0009da214088bb4a3c08b76db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Map.cs.meta b/Assets/Scripts/Map.cs.meta index 659896b..2695166 100644 --- a/Assets/Scripts/Map.cs.meta +++ b/Assets/Scripts/Map.cs.meta @@ -3,7 +3,11 @@ guid: 052bc569472779a429bfc51246f723d4 MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - wallSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + - roomSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + - corridorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3} + - tilePrefab: {instanceID: 0} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Assets/Scripts/Mostro.cs b/Assets/Scripts/Mostro.cs new file mode 100644 index 0000000..467af32 --- /dev/null +++ b/Assets/Scripts/Mostro.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Mostro : MonoBehaviour +{ + public string nome; + public Sprite sprite; + public int hpmax, hp, exp; + public bool is_undead; + public enum speed {slow, standard, fast}; + private bool player_spotted; + public Map map; + // Start is called before the first frame update + void Start() + { + map = gameObjectMappa.GetComponent(); + player_spotted = false; + } + + // Update is called once per frame + void Update() + { + if (!player_spotted){ + roam(); + } + //Da mettere il pathfinding per quando trova il personaggio + } + void roam(){ + while (true) + { + int direction = Random.Range(1, 5); + if (direction==1 && is_valid_movement("left")){ + transform.Translate(Vector3.left); + break; + } + else if (direction==2 && is_valid_movement("right")){ + transform.Translate(Vector3.right); + break; + } + else if (direction==3 && is_valid_movement("up")){ + transform.Translate(Vector3.up); + break; + } + else if (is_valid_movement("down")){ + transform.Translate(Vector3.up); + break; + } + } + } + bool is_valid_movement(string direction) + { + Tile tile; + int posX = (int) transform.position.x; + int posY = (int) transform.position.y; + if (direction == "left") tile = map.GetTile(posX - 1, posY); + else if (direction == "right") tile = map.GetTile(posX + 1, posY); + else if (direction == "up") tile = map.GetTile(posX, posY + 1); + else tile = map.GetTile(posX, posY - 1); + return tile.walkable; + } +} diff --git a/Assets/Scripts/Mostro.cs.meta b/Assets/Scripts/Mostro.cs.meta new file mode 100644 index 0000000..31bb5e3 --- /dev/null +++ b/Assets/Scripts/Mostro.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d484827da1a4f984c837dbfb9f970bdd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Object.cs b/Assets/Scripts/Object.cs new file mode 100644 index 0000000..e01fcdb --- /dev/null +++ b/Assets/Scripts/Object.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Object : MonoBehaviour +{ + public string nome; + public int costo; + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Object.cs.meta b/Assets/Scripts/Object.cs.meta new file mode 100644 index 0000000..ec349c0 --- /dev/null +++ b/Assets/Scripts/Object.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49be0f8468bff6249b7befdf02bc8ec9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 1f2e98b..96900b0 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -4,8 +4,7 @@ using UnityEngine; public class Player : MonoBehaviour { - private int exp, level, hp; - public GameObject player; + private int exp, level, hp, maxhp; public int startingHp; public Map map; //TODO: Aggiungi gli oggetti in inventario @@ -26,27 +25,28 @@ public class Player : MonoBehaviour { if (Input.GetKey(KeyCode.A)) { - if (is_valid_movement("left")) player.transform.Translate(Vector3.left); + if (is_valid_movement("left")) transform.Translate(Vector3.left); } if (Input.GetKey(KeyCode.D)) { - if (is_valid_movement("right")) player.transform.Translate(Vector3.right); + if (is_valid_movement("right")) transform.Translate(Vector3.right); } if (Input.GetKey(KeyCode.W)) { - if (is_valid_movement("up")) player.transform.Translate(Vector3.up); + if (is_valid_movement("up")) transform.Translate(Vector3.up); } if (Input.GetKey(KeyCode.S)) { - if (is_valid_movement("down")) player.transform.Translate(Vector3.down); + if (is_valid_movement("down")) transform.Translate(Vector3.down); } + // Qui c'è da aggiungere la condizione per il controllo degli hp } bool is_valid_movement(string direction) { Tile tile; - int posX = (int) player.transform.position.x; - int posY = (int) player.transform.position.y; + int posX = (int) transform.position.x; + int posY = (int) transform.position.y; if (direction == "left") tile = map.GetTile(posX - 1, posY); else if (direction == "right") tile = map.GetTile(posX + 1, posY); else if (direction == "up") tile = map.GetTile(posX, posY + 1); diff --git a/Assets/Sounds.meta b/Assets/Sounds.meta deleted file mode 100644 index 5fd147f..0000000 --- a/Assets/Sounds.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 19c0d85909aede34bb371863f187b9e0 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 0abae3b3b7c2b2156ecec79f9fd22b5976760181 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 27 Apr 2019 17:20:25 +0200 Subject: [PATCH 9/9] Use vector2int instead of a new class --- Assets/Scripts/Map.cs | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index afb75b4..c86df1e 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -13,25 +13,15 @@ public class ImpossibleCorridorError : System.Exception 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 readonly IntVector2 start; - public readonly IntVector2 end; + public readonly Vector2Int start; + public readonly Vector2Int end; public readonly int mapSize; public MapRoom(int mapSize, int maxRoomSize) { this.mapSize = mapSize; - start = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize)); - end = new IntVector2(Random.Range(0, mapSize), Random.Range(0, mapSize)); + start = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize)); + end = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize)); if(start.x > end.x) { int swap = start.x; start.x = end.x; @@ -56,32 +46,32 @@ public class MapRoom { return end.x < mapSize-1; } - public IntVector2 RightCorridorAttachment() { - return new IntVector2(end.x+1, Random.Range(start.y, end.y+1)); + public Vector2Int RightCorridorAttachment() { + return new Vector2Int(end.x+1, Random.Range(start.y, end.y+1)); } public bool LeftCheck() { return start.x > 0; } - public IntVector2 LeftCorridorAttachment() { - return new IntVector2(start.x-1, Random.Range(start.y, end.y+1)); + public Vector2Int LeftCorridorAttachment() { + return new Vector2Int(start.x-1, Random.Range(start.y, end.y+1)); } public bool TopCheck() { return end.y < mapSize-1; } - public IntVector2 TopCorridorAttachment() { - return new IntVector2(Random.Range(start.x, end.x+1), end.y+1); + public Vector2Int TopCorridorAttachment() { + return new Vector2Int(Random.Range(start.x, end.x+1), end.y+1); } public bool BottomCheck() { return start.y > 0; } - public IntVector2 BottomCorridorAttachment() { - return new IntVector2(Random.Range(start.x, end.x+1), start.y-1); + public Vector2Int BottomCorridorAttachment() { + return new Vector2Int(Random.Range(start.x, end.x+1), start.y-1); } } @@ -93,8 +83,8 @@ public enum CorridorModes { } public class MapCorridor { - public readonly IntVector2 start; - public readonly IntVector2 end; + public readonly Vector2Int start; + public readonly Vector2Int end; public readonly bool horizontal_priority; public MapCorridor(MapRoom from, MapRoom to, int mapSize) { @@ -206,7 +196,7 @@ public class Map : MonoBehaviour } 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); if(mc.horizontal_priority) { while(cursor.x != mc.end.x) {