From 897df5f3083fa7fc4d1349fc865950546f041649 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Mon, 29 Apr 2019 15:00:35 +0200 Subject: [PATCH] Slimes should attack, but for some reason they don't No idea --- Assets/Prefabs/Player.prefab | 2 +- Assets/Prefabs/ShortSword.prefab | 2 +- Assets/Scenes/Steffo.unity | 36 +++++++++------------------- Assets/Scripts/EntityMonsterSlime.cs | 29 +++++++++++++--------- Assets/Scripts/EntityPlayer.cs | 16 ------------- 5 files changed, 31 insertions(+), 54 deletions(-) diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 3d40d06..3570256 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -195,7 +195,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0cb881aee511ed643880a50159d731b7, type: 3} m_Name: m_EditorClassIdentifier: - damage: 1 + damage: 4 --- !u!95 &7684473867237801912 Animator: serializedVersion: 3 diff --git a/Assets/Prefabs/ShortSword.prefab b/Assets/Prefabs/ShortSword.prefab index 4f54cb0..f0d0e8d 100644 --- a/Assets/Prefabs/ShortSword.prefab +++ b/Assets/Prefabs/ShortSword.prefab @@ -98,4 +98,4 @@ MonoBehaviour: hp: 1 hpChange: -1 maxHpChange: -1 - damage: 3 + damage: 7 diff --git a/Assets/Scenes/Steffo.unity b/Assets/Scenes/Steffo.unity index 0939afa..3fa8bc2 100644 --- a/Assets/Scenes/Steffo.unity +++ b/Assets/Scenes/Steffo.unity @@ -151,7 +151,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 8182065399967645508} - m_RootOrder: 3 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -184,7 +184,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0, g: 1, b: 0, a: 1} + m_Color: {r: 1, g: 0, b: 0, a: 1} m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: @@ -195,10 +195,10 @@ MonoBehaviour: m_Type: 3 m_PreserveAspect: 0 m_FillCenter: 1 - m_FillMethod: 2 + m_FillMethod: 0 m_FillAmount: 1 m_FillClockwise: 1 - m_FillOrigin: 0 + m_FillOrigin: 1 m_UseSpriteMesh: 0 --- !u!222 &1332612188 CanvasRenderer: @@ -239,7 +239,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 8182065399967645508} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -272,7 +272,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 0, b: 0, a: 1} + m_Color: {r: 0.3962264, g: 0, b: 0, a: 1} m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: @@ -283,10 +283,10 @@ MonoBehaviour: m_Type: 3 m_PreserveAspect: 0 m_FillCenter: 1 - m_FillMethod: 2 + m_FillMethod: 0 m_FillAmount: 1 m_FillClockwise: 1 - m_FillOrigin: 0 + m_FillOrigin: 1 m_UseSpriteMesh: 0 --- !u!222 &2051317737 CanvasRenderer: @@ -338,7 +338,6 @@ GameObject: - component: {fileID: 7203168577643633308} - component: {fileID: 4061326455747354953} - component: {fileID: 2984726599447885319} - - component: {fileID: 2392633072578011031} m_Layer: 5 m_Name: Filled HP Bar m_TagString: Untagged @@ -346,19 +345,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!114 &2392633072578011031 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1313580544782099720} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: cbf8b0d2fd980e14f9956f5345d82ddc, type: 3} - m_Name: - m_EditorClassIdentifier: - max: 0 --- !u!114 &2984726599447885319 MonoBehaviour: m_ObjectHideFlags: 0 @@ -413,7 +399,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 8182065399967645508} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} @@ -609,7 +595,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 8182065399967645508} - m_RootOrder: 0 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -721,10 +707,10 @@ RectTransform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 7203168577643633308} - {fileID: 3195245192869872480} - {fileID: 2051317734} - {fileID: 1332612185} + - {fileID: 7203168577643633308} m_Father: {fileID: 8182065398968123531} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/EntityMonsterSlime.cs b/Assets/Scripts/EntityMonsterSlime.cs index b412426..84a93dc 100644 --- a/Assets/Scripts/EntityMonsterSlime.cs +++ b/Assets/Scripts/EntityMonsterSlime.cs @@ -12,6 +12,7 @@ public class EntityMonsterSlime : EntityMonster public float moveChance = 0.5f; public float visionRange = 4f; + public float damage = 1f; public GameObject attackAnimation; protected EntityPlayer player; @@ -38,18 +39,24 @@ public class EntityMonsterSlime : EntityMonster } } else { - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); + if(Vector3.Distance(player.transform.position, transform.position) > 2){ + int direction = Random.Range(0, 4); + if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + } + else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + } + else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + } + else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + } } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); + else{ + float damage_done = Random.value * damage; + player.hp -= damage; } } } diff --git a/Assets/Scripts/EntityPlayer.cs b/Assets/Scripts/EntityPlayer.cs index 1828279..89b9f76 100644 --- a/Assets/Scripts/EntityPlayer.cs +++ b/Assets/Scripts/EntityPlayer.cs @@ -9,8 +9,6 @@ public enum ControlMode { public class EntityPlayer : Entity { - public Dictionary inventory; - public InventoryItems selectedItem; protected ControlMode controlMode; protected Animator animator; @@ -18,29 +16,15 @@ public class EntityPlayer : Entity base.Start(); animator = GetComponent(); controlMode = ControlMode.Move; - //Init inventory - inventory.Add(InventoryItems.HealthPotion, 0); } protected void Update() { CheckForControlModeChange(); - CheckForInventoryInput(); if(controlMode == ControlMode.Move) CheckForMovementInput(); if(controlMode == ControlMode.Attack) CheckForAttackInput(); } - protected void CheckForInventoryInput() { - if(Input.GetKeyDown(KeyCode.X)) { - if(selectedItem == InventoryItems.Empty) { - selectedItem = 0; - } - else { - selectedItem += 1; - } - } - } - protected void CheckForControlModeChange() { if(Input.GetKeyDown(KeyCode.Escape)) { controlMode = ControlMode.Move;