From 21e983237f2dfb312a753ecfe5779c91ae32e343 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Mon, 29 Apr 2019 20:42:11 +0200 Subject: [PATCH 1/2] 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: From bab35ae71fd35b2f54563705a441ead98d9d975e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 29 Apr 2019 20:47:35 +0200 Subject: [PATCH 2/2] Update prefabs --- Assets/Prefabs/Entities/SHOP Rapier.prefab | 4 ++-- Assets/Prefabs/Entities/SHOP Sword.prefab | 4 ++-- Assets/Scripts/EntityItemShopSword.cs | 5 ++--- Assets/Scripts/EntityMonster.cs | 4 ++-- Assets/Scripts/Map.cs | 10 +++++++++- Assets/Sprites/Candle1.png.meta | 2 +- Assets/Sprites/Candle2.png.meta | 2 +- Assets/Sprites/Candle3.png.meta | 2 +- Assets/Sprites/Candle4.png.meta | 2 +- Assets/Sprites/Candle5.png.meta | 2 +- 10 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Assets/Prefabs/Entities/SHOP Rapier.prefab b/Assets/Prefabs/Entities/SHOP Rapier.prefab index c3bbb7f..7af8ef8 100644 --- a/Assets/Prefabs/Entities/SHOP Rapier.prefab +++ b/Assets/Prefabs/Entities/SHOP Rapier.prefab @@ -96,8 +96,8 @@ MonoBehaviour: overlappable: 1 hpMax: 1 hp: 1 - hpChange: -1 - maxHpChange: -1 + hpChange: -2 + maxHpChange: -2 damage: 3 attackAnimation: {fileID: 5896060810164205279, guid: 602b69921902efc44ab8a008655b6574, type: 3} diff --git a/Assets/Prefabs/Entities/SHOP Sword.prefab b/Assets/Prefabs/Entities/SHOP Sword.prefab index 7a09832..0e80a1b 100644 --- a/Assets/Prefabs/Entities/SHOP Sword.prefab +++ b/Assets/Prefabs/Entities/SHOP Sword.prefab @@ -96,8 +96,8 @@ MonoBehaviour: overlappable: 1 hpMax: 1 hp: 0 - hpChange: -1 - maxHpChange: -1 + hpChange: -6 + maxHpChange: -6 damage: 5 attackAnimation: {fileID: 5896060810164205279, guid: 602b69921902efc44ab8a008655b6574, type: 3} diff --git a/Assets/Scripts/EntityItemShopSword.cs b/Assets/Scripts/EntityItemShopSword.cs index 9bbcc54..fae9512 100644 --- a/Assets/Scripts/EntityItemShopSword.cs +++ b/Assets/Scripts/EntityItemShopSword.cs @@ -15,9 +15,8 @@ public class EntityItemShopSword : EntityItemShop { protected override void OnPurchase(EntityPlayer player) { Destroy(player.GetComponent()); - player.gameObject.AddComponent(); - PlayerAttackMelee pam = player.GetComponent(); + PlayerAttackMelee pam = player.gameObject.AddComponent(); pam.damage = this.damage; - pam.attackAnimation = attackAnimation; + pam.attackAnimation = this.attackAnimation; } } \ No newline at end of file diff --git a/Assets/Scripts/EntityMonster.cs b/Assets/Scripts/EntityMonster.cs index 599a1ef..853ea5c 100644 --- a/Assets/Scripts/EntityMonster.cs +++ b/Assets/Scripts/EntityMonster.cs @@ -6,8 +6,8 @@ public class EntityMonster : Entity { public string monsterName; - public virtual void OnTurn(){ - Debug.LogWarning("OnTurn() not overridden"); + public virtual void OnTurn() { + //Do nothing. } public override void Die() { diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 988595e..93f1ede 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -131,7 +131,9 @@ public class Map : MonoBehaviour public bool CanMoveTo(Vector2Int position) { try { - bool walkable = GetTile(position).walkable; + MapTile tile = GetTile(position); + if(tile == null) return false; + bool walkable = tile.walkable; List entities = turnHandler.GetEntitiesAtPosition(position); bool free = true; foreach(Entity entity in entities) { @@ -257,6 +259,9 @@ public class Map : MonoBehaviour for(int i = 0; i < enemiesToSpawn; i++) { MapRoom room = rooms[Random.Range(0, rooms.Count)]; Vector2Int point = room.RandomPoint(); + if(turnHandler.GetEntitiesAtPosition(point).Count > 0) { + continue; + } GameObject enemyPrefab = enemyPrefabs[Random.Range(0, enemyPrefabs.Count)]; GameObject enemyObject = Instantiate(enemyPrefab, turnHandler.transform); enemyObject.name = "Enemy " + i.ToString(); @@ -268,6 +273,9 @@ public class Map : MonoBehaviour for(int i = 0; i < curiositiesToSpawn; i++) { MapRoom room = rooms[Random.Range(0, rooms.Count)]; Vector2Int point = room.RandomPoint(); + if(turnHandler.GetEntitiesAtPosition(point).Count > 0) { + continue; + } GameObject curiosityPrefab = curiositiesPrefabs[Random.Range(0, curiositiesPrefabs.Count)]; GameObject curiosityObject = Instantiate(curiosityPrefab, turnHandler.transform); curiosityObject.name = "Curiosity " + i.ToString(); diff --git a/Assets/Sprites/Candle1.png.meta b/Assets/Sprites/Candle1.png.meta index 8d49723..317839b 100644 --- a/Assets/Sprites/Candle1.png.meta +++ b/Assets/Sprites/Candle1.png.meta @@ -97,7 +97,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: da5d40c84f8595f47b80dcea5d2deb3a + spriteID: 3e6eb75314db5e244bebb22f21c94026 internalID: 0 vertices: [] indices: diff --git a/Assets/Sprites/Candle2.png.meta b/Assets/Sprites/Candle2.png.meta index b7afd62..529e05b 100644 --- a/Assets/Sprites/Candle2.png.meta +++ b/Assets/Sprites/Candle2.png.meta @@ -97,7 +97,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: b492c21463e3a0f4a9b0be683bd11dda + spriteID: 6be7daae85043be438bbec5cd6228385 internalID: 0 vertices: [] indices: diff --git a/Assets/Sprites/Candle3.png.meta b/Assets/Sprites/Candle3.png.meta index 2906292..4764340 100644 --- a/Assets/Sprites/Candle3.png.meta +++ b/Assets/Sprites/Candle3.png.meta @@ -97,7 +97,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: 7c02f5004020e06428309e8025378000 + spriteID: 386bca1aff16bf940a124f9e4fd86f4b internalID: 0 vertices: [] indices: diff --git a/Assets/Sprites/Candle4.png.meta b/Assets/Sprites/Candle4.png.meta index 0c2270a..843577a 100644 --- a/Assets/Sprites/Candle4.png.meta +++ b/Assets/Sprites/Candle4.png.meta @@ -97,7 +97,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: 9f0d734ca5077c34f8b6bfb253e68903 + spriteID: 7021a274552590543af602108d3f2751 internalID: 0 vertices: [] indices: diff --git a/Assets/Sprites/Candle5.png.meta b/Assets/Sprites/Candle5.png.meta index d6f809d..63f800b 100644 --- a/Assets/Sprites/Candle5.png.meta +++ b/Assets/Sprites/Candle5.png.meta @@ -97,7 +97,7 @@ TextureImporter: outline: [] physicsShape: [] bones: [] - spriteID: 554f6d8e091900346aa7a07426a523ee + spriteID: ac8a71570b1ff934596f7800b57ecfd2 internalID: 0 vertices: [] indices: