From 21e983237f2dfb312a753ecfe5779c91ae32e343 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Mon, 29 Apr 2019 20:42:11 +0200 Subject: [PATCH] New AI Monsters are now basically "glowing brains" --- Assets/Assets.meta | 8 -- Assets/PhysMats.meta | 8 -- Assets/Prefabs/Entities/Skeleton.prefab | 18 +-- Assets/Prefabs/Entities/Watcher.prefab | 19 +-- .../Scripts/EntityMonsterSkeletonSwordsman.cs | 85 ++++++++++++++ .../EntityMonsterSkeletonSwordsman.cs.meta | 11 ++ Assets/Scripts/EntityMonsterWatcher.cs | 108 ++++++++++++++++++ Assets/Scripts/EntityMonsterWatcher.cs.meta | 11 ++ 8 files changed, 234 insertions(+), 34 deletions(-) delete mode 100644 Assets/Assets.meta delete mode 100644 Assets/PhysMats.meta create mode 100644 Assets/Scripts/EntityMonsterSkeletonSwordsman.cs create mode 100644 Assets/Scripts/EntityMonsterSkeletonSwordsman.cs.meta create mode 100644 Assets/Scripts/EntityMonsterWatcher.cs create mode 100644 Assets/Scripts/EntityMonsterWatcher.cs.meta 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/Prefabs/Entities/Skeleton.prefab b/Assets/Prefabs/Entities/Skeleton.prefab index 42a7ded..dc73285 100644 --- a/Assets/Prefabs/Entities/Skeleton.prefab +++ b/Assets/Prefabs/Entities/Skeleton.prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 8229417268116166537} - component: {fileID: -4227728170108252613} - - component: {fileID: -7336024761621732000} + - component: {fileID: 6575694489730919195} m_Layer: 0 m_Name: Skeleton m_TagString: Untagged @@ -80,7 +80,7 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!114 &-7336024761621732000 +--- !u!114 &6575694489730919195 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -89,18 +89,18 @@ MonoBehaviour: m_GameObject: {fileID: 8811060229651695861} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1ce1b6adc640d6f46bbf4d7072735b7f, type: 3} + m_Script: {fileID: 11500000, guid: 08019d8cb8af79544a488e243ab1fec4, type: 3} m_Name: m_EditorClassIdentifier: - hpTrueMax: 6 + hpTrueMax: 10 overlappable: 0 - hpMax: 0 - hp: 0 - monsterName: Skeleton - moveChance: 0.9 + hpMax: 10 + hp: 10 + monsterName: Skeleton Swordsman + moveChance: 0.1 visionRange: 5 attackRange: 1 - damage: 3 + damage: 2 attackAnimation: {fileID: 5896060810164205279, guid: 602b69921902efc44ab8a008655b6574, type: 3} upSprite: {fileID: 21300000, guid: 5c2d2fa90021e444aaac3dd540becacb, type: 3} diff --git a/Assets/Prefabs/Entities/Watcher.prefab b/Assets/Prefabs/Entities/Watcher.prefab index e9242dd..2c02c79 100644 --- a/Assets/Prefabs/Entities/Watcher.prefab +++ b/Assets/Prefabs/Entities/Watcher.prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 4565250353192838926} - component: {fileID: 7689595554396751579} - - component: {fileID: 7361680276203333039} + - component: {fileID: 2344911077221548336} m_Layer: 0 m_Name: Watcher m_TagString: Untagged @@ -80,7 +80,7 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!114 &7361680276203333039 +--- !u!114 &2344911077221548336 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -89,18 +89,19 @@ MonoBehaviour: m_GameObject: {fileID: 2071995852067845502} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1ce1b6adc640d6f46bbf4d7072735b7f, type: 3} + m_Script: {fileID: 11500000, guid: d03e35d46ecc79e45a2b1a4735094763, type: 3} m_Name: m_EditorClassIdentifier: - hpTrueMax: 10 + hpTrueMax: 15 overlappable: 0 - hpMax: 0 - hp: 0 + hpMax: 15 + hp: 15 monsterName: Watcher - moveChance: 0.2 - visionRange: 12 + moveChance: 0.1 + visionRange: 5 attackRange: 1 - damage: 5 + damage: 2 + dash_chance_starting: 0.5 attackAnimation: {fileID: 5896060810164205279, guid: 602b69921902efc44ab8a008655b6574, type: 3} upSprite: {fileID: 21300000, guid: 82bebf5d3f0f9864ea1f8f7a58b67bb7, type: 3} diff --git a/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs b/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs new file mode 100644 index 0000000..91d8b78 --- /dev/null +++ b/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs @@ -0,0 +1,85 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityMonsterSkeletonSwordsman : EntityMonster +{ + public float moveChance = 1f; + public float visionRange = 5f; + public float attackRange = 1f; + public float damage = 2f; + public GameObject attackAnimation; + protected EntityPlayer player; + + [BeforeStartAttribute] + public Sprite upSprite; + + [BeforeStartAttribute] + public Sprite downSprite; + + private bool has_attacked = false; + + protected new void Start() { + base.Start(); + player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + } + + public override void OnTurn(){ + if(Random.value < moveChance) return; + if (CanSeePlayer() && !has_attacked){ + Vector2Int distance = player.MapPosition - MapPosition; + if(distance.magnitude <= attackRange) { + float actualDamage = Random.value * damage; + player.hp -= actualDamage; + Instantiate(attackAnimation, player.transform); + messageBar.Write("Took " + actualDamage.ToString("0.0") + " damage!", Color.red); + has_attacked = true; + } + else if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + spriteRenderer.flipX = false; + } + else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + spriteRenderer.flipX = true; + } + else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + spriteRenderer.sprite = upSprite; + } + else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + spriteRenderer.sprite = downSprite; + } + } + else { + int direction = Random.Range(0, 4); + if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + spriteRenderer.flipX = false; + } + else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + spriteRenderer.flipX = true; + } + else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + spriteRenderer.sprite = upSprite; + } + else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + spriteRenderer.sprite = downSprite; + } + has_attacked = false; + } + } + + public bool CanSeePlayer(){ + return Vector3.Distance(player.transform.position, transform.position) < visionRange; + } + + private void OnDrawGizmosSelected() { + Gizmos.color = Color.cyan; + Gizmos.DrawWireSphere(transform.position, visionRange); + } +} diff --git a/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs.meta b/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs.meta new file mode 100644 index 0000000..8a4c292 --- /dev/null +++ b/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 08019d8cb8af79544a488e243ab1fec4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/EntityMonsterWatcher.cs b/Assets/Scripts/EntityMonsterWatcher.cs new file mode 100644 index 0000000..d0f1997 --- /dev/null +++ b/Assets/Scripts/EntityMonsterWatcher.cs @@ -0,0 +1,108 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityMonsterWatcher : EntityMonster +{ +public float moveChance = 1f; + public float visionRange = 5f; + public float attackRange = 1f; + public float damage = 2f; + public float dash_chance_starting = 0.5f; + private float dash_chance_current; + public GameObject attackAnimation; + protected EntityPlayer player; + + [BeforeStartAttribute] + public Sprite upSprite; + + [BeforeStartAttribute] + public Sprite downSprite; + + + protected new void Start() { + base.Start(); + player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + dash_chance_current=dash_chance_starting; + } + + public override void OnTurn(){ + if(Random.value < moveChance) return; + if (CanSeePlayer()){ + Vector2Int distance = player.MapPosition - MapPosition; + if(distance.magnitude <= attackRange) { + float actualDamage = Random.value * damage; + player.hp -= actualDamage; + Instantiate(attackAnimation, player.transform); + messageBar.Write("Took " + actualDamage.ToString("0.0") + " damage!", Color.red); + if(Random.value < dash_chance_current){ + int direction_dash = Random.Range(0, 4); + if (direction_dash == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + spriteRenderer.flipX = false; + } + else if (direction_dash == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + spriteRenderer.flipX = true; + } + else if (direction_dash == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + spriteRenderer.sprite = upSprite; + } + else if (direction_dash == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + spriteRenderer.sprite = downSprite; + } + dash_chance_current=dash_chance_starting; + } + else{ + dash_chance_current-=0.1f; + } + } + else if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + spriteRenderer.flipX = false; + } + else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + spriteRenderer.flipX = true; + } + else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + spriteRenderer.sprite = upSprite; + } + else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + spriteRenderer.sprite = downSprite; + } + } + else { + int direction = Random.Range(0, 4); + if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); + spriteRenderer.flipX = false; + } + else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + spriteRenderer.flipX = true; + } + else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + spriteRenderer.sprite = upSprite; + } + else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); + spriteRenderer.sprite = downSprite; + } + } + } + + public bool CanSeePlayer(){ + return Vector3.Distance(player.transform.position, transform.position) < visionRange; + } + + private void OnDrawGizmosSelected() { + Gizmos.color = Color.cyan; + Gizmos.DrawWireSphere(transform.position, visionRange); + } +} diff --git a/Assets/Scripts/EntityMonsterWatcher.cs.meta b/Assets/Scripts/EntityMonsterWatcher.cs.meta new file mode 100644 index 0000000..6a64c67 --- /dev/null +++ b/Assets/Scripts/EntityMonsterWatcher.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d03e35d46ecc79e45a2b1a4735094763 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: