diff --git a/Assets/Prefabs/GameController.prefab b/Assets/Prefabs/GameController.prefab index 7d30b1c..835ca33 100644 --- a/Assets/Prefabs/GameController.prefab +++ b/Assets/Prefabs/GameController.prefab @@ -289,7 +289,8 @@ MonoBehaviour: type: 3} enemyPrefabs: - {fileID: 470211819356819165, guid: 1bd6e08f590fdd844854a34504aeaa4a, type: 3} - enemiesToSpawn: 10 + - {fileID: 1164136568549368904, guid: a4aeecfb369f0974490d158ef9489335, type: 3} + enemiesToSpawn: 15 --- !u!1 &6763073704789207264 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/MainCamera.prefab b/Assets/Prefabs/MainCamera.prefab deleted file mode 100644 index a1cac78..0000000 --- a/Assets/Prefabs/MainCamera.prefab +++ /dev/null @@ -1,85 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &7475959774386308610 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 7475959774386308609} - - component: {fileID: 7475959774386308608} - - component: {fileID: 7475959774386308611} - m_Layer: 0 - m_Name: Main Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &7475959774386308609 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7475959774386308610} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -10} - 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!20 &7475959774386308608 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7475959774386308610} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} - m_projectionMatrixMode: 1 - m_GateFitMode: 2 - m_FOVAxisMode: 0 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 1 - orthographic size: 8 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!81 &7475959774386308611 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7475959774386308610} - m_Enabled: 1 diff --git a/Assets/Prefabs/MainCamera.prefab.meta b/Assets/Prefabs/MainCamera.prefab.meta deleted file mode 100644 index 03dd195..0000000 --- a/Assets/Prefabs/MainCamera.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 04409c352bfbdea4b9830f11d7b4d40e -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index d9785e0..0e27d8e 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -1,5 +1,88 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &2894367173346332696 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2894367173346332699} + - component: {fileID: 2894367173346332698} + - component: {fileID: 2894367173346332697} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2894367173346332699 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2894367173346332696} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 2935319493830293414} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!20 &2894367173346332698 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2894367173346332696} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 1 + orthographic size: 8 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!81 &2894367173346332697 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2894367173346332696} + m_Enabled: 1 --- !u!1 &2935319493830293412 GameObject: m_ObjectHideFlags: 0 @@ -9,8 +92,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2935319493830293414} - - component: {fileID: 2935319493830293413} - component: {fileID: -5893075763862095451} + - component: {fileID: 2935319493830293413} + - component: {fileID: 8856581523727923621} m_Layer: 0 m_Name: Player m_TagString: Player @@ -33,24 +117,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2935319493830293413 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2935319493830293412} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4de6b97c3d785d146a0df2c1c078fe91, type: 3} - m_Name: - m_EditorClassIdentifier: - hpMax: 10 - overlappable: 0 - hp: 10 - sprite: {fileID: 21300000, guid: 88f4c277892ae9449a57b321cd810bce, type: 3} - exp: 0 - level: 0 --- !u!212 &-5893075763862095451 SpriteRenderer: m_ObjectHideFlags: 0 @@ -99,78 +165,34 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!1001 &5734536248370648602 -PrefabInstance: +--- !u!114 &2935319493830293413 +MonoBehaviour: m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 2935319493830293414} - m_Modifications: - - target: {fileID: 7475959774386308610, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_Name - value: Main Camera - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalPosition.z - value: -10 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalRotation.x - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalRotation.y - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalRotation.z - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 04409c352bfbdea4b9830f11d7b4d40e, type: 3} ---- !u!4 &2894367173346332699 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e, - type: 3} - m_PrefabInstance: {fileID: 5734536248370648602} + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2935319493830293412} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f16e1b4841b0d4546a52853aafbb7d85, type: 3} + m_Name: + m_EditorClassIdentifier: + hpMax: 10 + overlappable: 0 + hp: 0 + sprite: {fileID: 0} + exp: 0 + level: 0 +--- !u!114 &8856581523727923621 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2935319493830293412} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cb881aee511ed643880a50159d731b7, type: 3} + m_Name: + m_EditorClassIdentifier: + damage: 1 diff --git a/Assets/Prefabs/Slime.prefab b/Assets/Prefabs/Slime.prefab index 30a9177..40d7ddf 100644 --- a/Assets/Prefabs/Slime.prefab +++ b/Assets/Prefabs/Slime.prefab @@ -9,8 +9,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2043533519980591455} - - component: {fileID: 571363246873614695} - component: {fileID: 1351652798109185028} + - component: {fileID: 571363246873614695} m_Layer: 0 m_Name: Slime m_TagString: Untagged @@ -32,22 +32,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &571363246873614695 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1164136568549368904} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 2fcfe4b94620b234fb7a294bf4453a69, type: 3} - m_Name: - m_EditorClassIdentifier: - hpMax: 0 - hp: 0 - sprite: {fileID: 21300000, guid: ee7ef72c830dc204c9df0595e161f049, type: 3} - visionRange: 4 --- !u!212 &1351652798109185028 SpriteRenderer: m_ObjectHideFlags: 0 @@ -96,3 +80,21 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!114 &571363246873614695 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1164136568549368904} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ce1b6adc640d6f46bbf4d7072735b7f, type: 3} + m_Name: + m_EditorClassIdentifier: + hpMax: 2 + overlappable: 0 + hp: 0 + sprite: {fileID: 0} + moveChance: 0.5 + visionRange: 4 diff --git a/Assets/Prefabs/TEST Item.prefab b/Assets/Prefabs/TEST Item.prefab index d91ed64..fc955a3 100644 --- a/Assets/Prefabs/TEST Item.prefab +++ b/Assets/Prefabs/TEST Item.prefab @@ -12,7 +12,7 @@ GameObject: - component: {fileID: 470211819356819162} - component: {fileID: 7501912107144583665} m_Layer: 0 - m_Name: TEST_ Item + m_Name: TEST Item m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -41,13 +41,13 @@ MonoBehaviour: m_GameObject: {fileID: 470211819356819165} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1f0883433553dbb4fa23a815949f596b, type: 3} + m_Script: {fileID: 11500000, guid: cfb3c44da9ebb1840b5a2bcdfd5e2730, type: 3} m_Name: m_EditorClassIdentifier: - hpMax: 0 + hpMax: 1 overlappable: 0 hp: 0 - sprite: {fileID: 21300000, guid: 5e4d29e1adc2ea0429b199b82253416c, type: 3} + sprite: {fileID: 0} --- !u!212 &7501912107144583665 SpriteRenderer: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/AI.cs b/Assets/Scripts/AI.cs deleted file mode 100644 index fd30b46..0000000 --- a/Assets/Scripts/AI.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class AI : Entity -{ - public virtual void OnTurn(){ - Debug.LogWarning("OnTurn() not overridden"); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index bae1035..c2cfe15 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -10,9 +10,6 @@ public class Entity : MonoBehaviour [AfterStartAttribute] public float hp; - [BeforeStartAttribute] - public Sprite sprite; - public Vector2Int MapPosition { get { return new Vector2Int((int)transform.position.x, (int)transform.position.y); @@ -23,14 +20,21 @@ public class Entity : MonoBehaviour protected SpriteRenderer spriteRenderer; protected TurnHandler turnHandler; protected Map map; + protected MessageBar messageBar; protected virtual void Start() { spriteRenderer = GetComponent(); - spriteRenderer.sprite = sprite; gameController = GameObject.FindGameObjectWithTag("GameController"); turnHandler = gameController.GetComponentInChildren(); map = gameController.GetComponentInChildren(); + GameObject canvas = GameObject.FindGameObjectWithTag("Canvas"); + messageBar = canvas.GetComponentInChildren(); hp = hpMax; } + + public virtual void Die() { + Debug.LogWarning("Die not overridden"); + Destroy(gameObject); + } } diff --git a/Assets/Scripts/EntityItem.cs b/Assets/Scripts/EntityItem.cs new file mode 100644 index 0000000..1d62286 --- /dev/null +++ b/Assets/Scripts/EntityItem.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityItem : Entity +{ + public virtual string Name { + get { + Debug.LogWarning("No name given to an item"); + return ""; + } + } + + protected override void Start() { + base.Start(); + overlappable = true; + } + + public virtual void OnPickup(EntityPlayer player) { + Debug.LogWarning("OnPickup not overridden"); + messageBar.Write("Picked up: " + Name, Color.yellow); + Destroy(gameObject); + } + + public override void Die() { + messageBar.Write("Destroyed: " + Name, Color.red); + Destroy(gameObject); + } +} \ No newline at end of file diff --git a/Assets/Scripts/AISlime.cs.meta b/Assets/Scripts/EntityItem.cs.meta similarity index 83% rename from Assets/Scripts/AISlime.cs.meta rename to Assets/Scripts/EntityItem.cs.meta index 9c04775..45a55ad 100644 --- a/Assets/Scripts/AISlime.cs.meta +++ b/Assets/Scripts/EntityItem.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2fcfe4b94620b234fb7a294bf4453a69 +guid: cfb3c44da9ebb1840b5a2bcdfd5e2730 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/EntityMonster.cs b/Assets/Scripts/EntityMonster.cs new file mode 100644 index 0000000..1a130b5 --- /dev/null +++ b/Assets/Scripts/EntityMonster.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityMonster : Entity +{ + public virtual string Name { + get { + Debug.LogWarning("No name given to a monster"); + return ""; + } + } + + public virtual void OnTurn(){ + Debug.LogWarning("OnTurn() not overridden"); + } + + public override void Die() { + messageBar.Write("Killed: " + Name, Color.red); + Destroy(gameObject); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player.cs.meta b/Assets/Scripts/EntityMonster.cs.meta similarity index 83% rename from Assets/Scripts/Player.cs.meta rename to Assets/Scripts/EntityMonster.cs.meta index 4cba488..1e746d3 100644 --- a/Assets/Scripts/Player.cs.meta +++ b/Assets/Scripts/EntityMonster.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4de6b97c3d785d146a0df2c1c078fe91 +guid: aec5e971190b4b544a78be24566f9e6c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/AISlime.cs b/Assets/Scripts/EntityMonsterSlime.cs similarity index 90% rename from Assets/Scripts/AISlime.cs rename to Assets/Scripts/EntityMonsterSlime.cs index 85306a3..7b49a38 100644 --- a/Assets/Scripts/AISlime.cs +++ b/Assets/Scripts/EntityMonsterSlime.cs @@ -2,15 +2,21 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class AISlime : AI +public class EntityMonsterSlime : EntityMonster { + public override string Name { + get { + return "Slime"; + } + } + public float moveChance = 0.5f; public float visionRange = 4; - protected Player player; + protected EntityPlayer player; protected new void Start() { base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + player = GameObject.FindGameObjectWithTag("Player").GetComponent(); } public override void OnTurn(){ diff --git a/Assets/Scripts/Item.cs.meta b/Assets/Scripts/EntityMonsterSlime.cs.meta similarity index 83% rename from Assets/Scripts/Item.cs.meta rename to Assets/Scripts/EntityMonsterSlime.cs.meta index 0b76504..3495293 100644 --- a/Assets/Scripts/Item.cs.meta +++ b/Assets/Scripts/EntityMonsterSlime.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1f0883433553dbb4fa23a815949f596b +guid: 1ce1b6adc640d6f46bbf4d7072735b7f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/EntityPlayer.cs b/Assets/Scripts/EntityPlayer.cs new file mode 100644 index 0000000..2b04105 --- /dev/null +++ b/Assets/Scripts/EntityPlayer.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum ControlMode { + Move, + Attack +} + +public class EntityPlayer : Entity +{ + protected ControlMode controlMode; + + protected override void Start() { + base.Start(); + controlMode = ControlMode.Move; + } + + protected void Update() + { + CheckForControlModeChange(); + if(controlMode == ControlMode.Move) CheckForMovementInput(); + if(controlMode == ControlMode.Attack) CheckForAttackInput(); + } + + protected void CheckForControlModeChange() { + if(Input.GetKeyDown(KeyCode.Escape)) { + controlMode = ControlMode.Move; + messageBar.Write("Control mode: Move", Color.cyan); + } + if(Input.GetKeyDown(KeyCode.A)) { + controlMode = ControlMode.Attack; + messageBar.Write("Control mode: Attack", Color.cyan); + } + } + + protected void CheckForAttackInput() { + bool hasAttacked = false; + if (Input.GetKeyDown(KeyCode.LeftArrow)) + { + hasAttacked = GetComponent().Attack(MapPosition + Vector2Int.left); + } + else if (Input.GetKeyDown(KeyCode.RightArrow)) + { + hasAttacked = GetComponent().Attack(MapPosition + Vector2Int.right); + } + else if (Input.GetKeyDown(KeyCode.UpArrow)) + { + hasAttacked = GetComponent().Attack(MapPosition + Vector2Int.up); + } + else if (Input.GetKeyDown(KeyCode.DownArrow)) + { + hasAttacked = GetComponent().Attack(MapPosition + Vector2Int.down); + } + if(hasAttacked) { + //Turn happens! + turnHandler.OnTurn(); + } + } + + protected void CheckForMovementInput() + { + bool hasMoved = false; + if (Input.GetKeyDown(KeyCode.LeftArrow)) + { + if (map.CanMoveTo(MapPosition + Vector2Int.left)) { + transform.Translate(Vector3.left); + hasMoved = true; + spriteRenderer.flipX = false; + } + } + else if (Input.GetKeyDown(KeyCode.RightArrow)) + { + if (map.CanMoveTo(MapPosition + Vector2Int.right)) { + transform.Translate(Vector3.right); + hasMoved = true; + spriteRenderer.flipX = true; + } + } + else if (Input.GetKeyDown(KeyCode.UpArrow)) + { + if (map.CanMoveTo(MapPosition + Vector2Int.up)) { + transform.Translate(Vector3.up); + hasMoved = true; + } + } + else if (Input.GetKeyDown(KeyCode.DownArrow)) + { + if (map.CanMoveTo(MapPosition + Vector2Int.down)) { + transform.Translate(Vector3.down); + hasMoved = true; + } + } + if(hasMoved) { + //Check for pickuppable items + List entities = turnHandler.GetEntitiesAtPosition(MapPosition); + foreach(Entity entity in entities) { + if(entity is EntityItem) { + EntityItem item = entity as EntityItem; + item.OnPickup(this); + } + } + //Turn happens! + turnHandler.OnTurn(); + } + } +} diff --git a/Assets/Scripts/AI.cs.meta b/Assets/Scripts/EntityPlayer.cs.meta similarity index 83% rename from Assets/Scripts/AI.cs.meta rename to Assets/Scripts/EntityPlayer.cs.meta index 438e77b..370a2be 100644 --- a/Assets/Scripts/AI.cs.meta +++ b/Assets/Scripts/EntityPlayer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e694420377849854db7a2686ff36420c +guid: f16e1b4841b0d4546a52853aafbb7d85 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/FillAmountFromPlayerHP.cs b/Assets/Scripts/FillAmountFromPlayerHP.cs index db83a6c..be01f33 100644 --- a/Assets/Scripts/FillAmountFromPlayerHP.cs +++ b/Assets/Scripts/FillAmountFromPlayerHP.cs @@ -5,11 +5,11 @@ using UnityEngine.UI; public class FillAmountFromPlayerHP : MonoBehaviour { - private Player player; + private EntityPlayer player; private Image image; private void Start() { - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + player = GameObject.FindGameObjectWithTag("Player").GetComponent(); image = GetComponent(); } diff --git a/Assets/Scripts/Item.cs b/Assets/Scripts/Item.cs deleted file mode 100644 index 5d99cf6..0000000 --- a/Assets/Scripts/Item.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Item : Entity -{ - protected override void Start() { - base.Start(); - overlappable = true; - } - - public virtual void OnPickup(Player player) { - Debug.LogWarning("OnPickup not overridden"); - turnHandler.WriteToMessageBar("Picked up [NULL]."); - Destroy(gameObject); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 696e369..a5f6c3d 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -124,10 +124,10 @@ public class Map : MonoBehaviour private List rooms; private TurnHandler turnHandler; - public Tile GetTile(Vector2Int position) { + public MapTile GetTile(Vector2Int position) { try { GameObject tileObject = tiles[position.x, position.y]; - return tileObject.GetComponent(); + return tileObject.GetComponent(); } catch(System.IndexOutOfRangeException) { return null; @@ -138,7 +138,7 @@ public class Map : MonoBehaviour { try { bool walkable = GetTile(position).walkable; - List entities = turnHandler.GetEntityAtPosition(position); + List entities = turnHandler.GetEntitiesAtPosition(position); bool free = true; foreach(Entity entity in entities) { free &= entity.overlappable; @@ -151,7 +151,7 @@ public class Map : MonoBehaviour } private void EditTile(Vector2Int position, bool walkable, bool roomPart) { - Tile tile = GetTile(position); + MapTile tile = GetTile(position); tile.walkable = walkable; tile.roomPart |= roomPart; } @@ -163,7 +163,7 @@ public class Map : MonoBehaviour tileObject.transform.position = new Vector3(x, y, 0); tiles[x, y] = tileObject; tileObject.name = "Tile [" + x.ToString() + ", " + y.ToString() + "]"; - Tile tile = tileObject.GetComponent(); + MapTile tile = tileObject.GetComponent(); tile.walkable = false; } } @@ -270,8 +270,8 @@ public class Map : MonoBehaviour public void GenerateTileSprites() { for(int x = 0; x < mapSize; x++) { for(int y = 0; y < mapSize; y++) { - Tile tile = GetTile(new Vector2Int(x, y)); - Tile otherTile; + MapTile tile = GetTile(new Vector2Int(x, y)); + MapTile otherTile; if(tile.walkable) tile.sprite = SampleSprite(floorSprites); else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(botWallSprites); else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(topWallSprites); diff --git a/Assets/Scripts/Tile.cs b/Assets/Scripts/MapTile.cs similarity index 90% rename from Assets/Scripts/Tile.cs rename to Assets/Scripts/MapTile.cs index 04dec14..847627a 100644 --- a/Assets/Scripts/Tile.cs +++ b/Assets/Scripts/MapTile.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class Tile : MonoBehaviour +public class MapTile : MonoBehaviour { public bool walkable; public bool roomPart; diff --git a/Assets/Scripts/Tile.cs.meta b/Assets/Scripts/MapTile.cs.meta similarity index 100% rename from Assets/Scripts/Tile.cs.meta rename to Assets/Scripts/MapTile.cs.meta diff --git a/Assets/Scripts/MessageBar.cs b/Assets/Scripts/MessageBar.cs index e70ffe8..1c2fc3d 100644 --- a/Assets/Scripts/MessageBar.cs +++ b/Assets/Scripts/MessageBar.cs @@ -17,7 +17,8 @@ public class MessageBar : MonoBehaviour opacity = 0f; } - public void Write(string message) { + public void Write(string message, Color color) { + text.color = color; text.text = message; opacity = 1f; } diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs deleted file mode 100644 index dd6ccc9..0000000 --- a/Assets/Scripts/Player.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Player : Entity -{ - public int exp; - public int level; - - void Update() - { - CheckForMovementInput(); - } - - void CheckForMovementInput() - { - bool hasMoved = false; - if (Input.GetKeyDown(KeyCode.A)) - { - if (map.CanMoveTo(MapPosition + Vector2Int.left)) { - transform.Translate(Vector3.left); - hasMoved = true; - spriteRenderer.flipX = false; - } - } - else if (Input.GetKeyDown(KeyCode.D)) - { - if (map.CanMoveTo(MapPosition + Vector2Int.right)) { - transform.Translate(Vector3.right); - hasMoved = true; - spriteRenderer.flipX = true; - } - } - else if (Input.GetKeyDown(KeyCode.W)) - { - if (map.CanMoveTo(MapPosition + Vector2Int.up)) { - transform.Translate(Vector3.up); - hasMoved = true; - } - } - else if (Input.GetKeyDown(KeyCode.S)) - { - if (map.CanMoveTo(MapPosition + Vector2Int.down)) { - transform.Translate(Vector3.down); - hasMoved = true; - } - } - if(hasMoved) { - //Check for pickuppable items - List entities = turnHandler.GetEntityAtPosition(MapPosition); - foreach(Entity entity in entities) { - if(entity is Item) { - Item item = entity as Item; - item.OnPickup(this); - } - } - //Turn happens! - turnHandler.OnTurn(); - } - } -} diff --git a/Assets/Scripts/PlayerAttack.cs b/Assets/Scripts/PlayerAttack.cs new file mode 100644 index 0000000..b9b5d11 --- /dev/null +++ b/Assets/Scripts/PlayerAttack.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAttack : MonoBehaviour +{ + protected EntityPlayer player; + protected GameObject gameController; + protected TurnHandler turnHandler; + protected Map map; + + protected void Start() { + player = GetComponent(); + gameController = GameObject.FindGameObjectWithTag("GameController"); + turnHandler = gameController.GetComponentInChildren(); + map = gameController.GetComponentInChildren(); + } + + public virtual bool Attack(Vector2Int target) { + //Returns if the attack was successful. + Debug.LogWarning("Attack not overridden"); + return false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/PlayerAttack.cs.meta b/Assets/Scripts/PlayerAttack.cs.meta new file mode 100644 index 0000000..86ea067 --- /dev/null +++ b/Assets/Scripts/PlayerAttack.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1bb56d02d177e9e4e9146940057ba1ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerAttackMelee.cs b/Assets/Scripts/PlayerAttackMelee.cs new file mode 100644 index 0000000..936f9da --- /dev/null +++ b/Assets/Scripts/PlayerAttackMelee.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAttackMelee : PlayerAttack +{ + public float damage = 1f; + + public override bool Attack(Vector2Int target) { + List targetEntities = turnHandler.GetEntitiesAtPosition(target); + if(targetEntities.Count == 0) { + return false; + } + Entity targetEntity = targetEntities[0]; + targetEntity.hp -= damage; + return true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/PlayerAttackMelee.cs.meta b/Assets/Scripts/PlayerAttackMelee.cs.meta new file mode 100644 index 0000000..9a4a586 --- /dev/null +++ b/Assets/Scripts/PlayerAttackMelee.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0cb881aee511ed643880a50159d731b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/TurnHandler.cs b/Assets/Scripts/TurnHandler.cs index 4493018..3165f09 100644 --- a/Assets/Scripts/TurnHandler.cs +++ b/Assets/Scripts/TurnHandler.cs @@ -4,25 +4,22 @@ using UnityEngine; public class TurnHandler : MonoBehaviour { - private MessageBar messageBar; - - private void Start() { - GameObject canvas = GameObject.FindGameObjectWithTag("Canvas"); - messageBar = canvas.GetComponentInChildren(); - } - - public void WriteToMessageBar(string message) { - messageBar.Write(message); - } - public void OnTurn() { - AI[] ais = gameObject.GetComponentsInChildren(); - foreach(AI ai in ais) { - ai.OnTurn(); + Entity[] entities = gameObject.GetComponentsInChildren(); + foreach(Entity entity in entities) { + //Check for deaths + if(entity.hp <= 0) { + entity.Die(); + } + //Move AIs + if(entity is EntityMonster) { + EntityMonster ai = entity as EntityMonster; + ai.OnTurn(); + } } } - public List GetEntityAtPosition(Vector2Int position) { + public List GetEntitiesAtPosition(Vector2Int position) { Entity[] entities = GetComponentsInChildren(); List found = new List(); foreach(Entity entity in entities) {