From b33d0984c5a3aa00b23eebf89d4562023ac99279 Mon Sep 17 00:00:00 2001 From: Ny Bruker <robinhs@stud.ntnu.no> Date: Sat, 10 Dec 2022 17:45:13 +0100 Subject: [PATCH] Fixed code formatting on files. --- .vscode/settings.json | 55 ++ .../Code/Bosses/BringerOfDeathController.cs | 249 ++++--- .../Code/Bosses/SkeletonBossController.cs | 225 +++--- .../Assets/Code/Bosses/attacks/BoDSpell.cs | 19 +- MrBigsock/Assets/Code/Character.cs | 167 +++-- .../Code/Core/Abilities/Base/AbilityEntity.cs | 7 +- .../Code/Core/Abilities/Base/BaseAbility.cs | 34 +- .../Code/Core/Abilities/Base/BaseAttack.cs | 2 +- .../Code/Core/Abilities/Base/IAbility.cs | 8 +- .../Code/Core/Abilities/Base/IAbilityParam.cs | 1 + .../Code/Core/Abilities/Base/IAttack.cs | 3 +- MrBigsock/Assets/Code/DestroyObject.cs | 26 +- MrBigsock/Assets/Code/EmptyCollider.cs | 36 +- MrBigsock/Assets/Code/FollowPlayer.cs | 215 +++--- .../Assets/Code/InteractionSystem/Chest.cs | 75 +- .../Assets/Code/InteractionSystem/Door.cs | 62 +- .../Code/InteractionSystem/IInteractable.cs | 13 +- .../Code/InteractionSystem/Interactor.cs | 43 +- .../Assets/Code/InteractionSystem/Stairs.cs | 30 +- MrBigsock/Assets/Code/Map/AbstractMapGen.cs | 47 +- MrBigsock/Assets/Code/Map/Data/NeigbourSO.cs | 22 +- MrBigsock/Assets/Code/Map/Data/TileSetSO.cs | 18 +- .../Assets/Code/Map/NeighbourMapGenerator.cs | 87 ++- MrBigsock/Assets/Code/Map/TilemapGenerator.cs | 674 ++++++++---------- MrBigsock/Assets/Code/PlayerController.cs | 187 +++-- .../Assets/Code/Slime/SlimeController.cs | 38 +- MrBigsock/Assets/Code/UI/AbilityCluster.cs | 66 +- MrBigsock/Assets/Code/UI/AbilityElement.cs | 87 ++- MrBigsock/Assets/Code/UI/ChestDisplay.cs | 155 ++-- MrBigsock/Assets/Code/UI/ChestShowItemDesc.cs | 23 +- MrBigsock/Assets/Code/UI/ControlScheme.cs | 33 +- MrBigsock/Assets/Code/UI/EndScreen.cs | 47 +- MrBigsock/Assets/Code/UI/EndScreenDed.cs | 19 +- MrBigsock/Assets/Code/UI/HPBar.cs | 23 +- MrBigsock/Assets/Code/UI/HpBarEnemy.cs | 41 +- MrBigsock/Assets/Code/UI/InvTrash.cs | 11 +- MrBigsock/Assets/Code/UI/InventoryPanel.cs | 13 +- MrBigsock/Assets/Code/UI/ItemPref.cs | 26 +- MrBigsock/Assets/Code/UI/ItemSlot.cs | 22 +- MrBigsock/Assets/Code/UI/MainMenuScript.cs | 36 +- MrBigsock/Assets/Code/UI/PlayerMenu.cs | 44 +- MrBigsock/Assets/Code/UI/StatPanel.cs | 435 ++++++----- MrBigsock/Assets/Code/UI/TabButton.cs | 58 +- MrBigsock/Assets/Code/UI/TabGroup.cs | 113 ++- MrBigsock/Assets/Code/UI/UtilBar.cs | 99 ++- .../Assets/Code/attack/AttackMovement.cs | 31 +- MrBigsock/Assets/Code/orc/EnemyController.cs | 52 +- MrBigsock/Assets/Code/orc/Enemy_orc_range.cs | 60 +- .../Code/skeleton/Enemy_skeleton_range.cs | 62 +- MrBigsock/Packages/packages-lock.json | 22 +- 50 files changed, 1861 insertions(+), 2060 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e232cd65 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,55 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":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/MrBigsock/Assets/Code/Bosses/BringerOfDeathController.cs b/MrBigsock/Assets/Code/Bosses/BringerOfDeathController.cs index 3ad06ed3..199c694d 100644 --- a/MrBigsock/Assets/Code/Bosses/BringerOfDeathController.cs +++ b/MrBigsock/Assets/Code/Bosses/BringerOfDeathController.cs @@ -7,133 +7,124 @@ using System; using BigSock.Service; namespace BigSock { - - public partial class BringerOfDeathController : EnemyController - { - - protected static readonly TimeSpan SPELL_CAST_COOLDOWN = new TimeSpan(0, 0, 0, 4, 0); - protected static readonly TimeSpan CAST_START = new TimeSpan(0, 0, 0, 0, 500); - protected static readonly TimeSpan CAST_LOCATE = new TimeSpan(0, 0, 0, 0, 150); - protected static readonly TimeSpan CAST_FINISH = new TimeSpan(0, 0, 0, 0, 750); - - protected Vector3 spellLocation; - - protected DateTime casting_time = DateTime.Now; - protected DateTime spell_cooldown = DateTime.Now + SPELL_CAST_COOLDOWN; - - protected static readonly TimeSpan TELEPORT_COOLDOWN = new TimeSpan(0, 0, 0, 6, 0); - protected static readonly TimeSpan TELEPORT_START = new TimeSpan(0, 0, 0, 0, 500); - protected static readonly TimeSpan TELEPORT_LOCATE = new TimeSpan(0, 0, 0, 0, 50); - protected static readonly TimeSpan TELEPORT_FINISH = new TimeSpan(0, 0, 0, 0, 850); - - protected Vector3 teleportLocation; - - protected DateTime teleport_time = DateTime.Now; - protected DateTime teleport_cooldown = DateTime.Now + TELEPORT_COOLDOWN; - - public BoDState State { get; protected set; } = BoDState.Idle; - - protected EmptyCollider spellCollider; - - protected IAttack _testAttack; - public const string PROJECTILE_NAME = "Bosses/Attacks/Bringer_of_Death_Spell"; - - - protected override void Update() { - Regenerate(); - - if (target != null && DateTime.Now > spell_cooldown && (this.baseHP >= baseMaxHP*0.65 || this.baseHP < baseMaxHP*0.3)){ - casting_time = DateTime.Now + CAST_START; - State = BoDState.CastLocate; - m_Animator.SetTrigger("cast"); - spell_cooldown = DateTime.Now + SPELL_CAST_COOLDOWN; - } - else if (target != null && State == BoDState.CastLocate && DateTime.Now > casting_time) { - casting_time = DateTime.Now + CAST_LOCATE; - State = BoDState.Casting; - spellLocation = target.transform.position; - } - else if (State == BoDState.Casting && DateTime.Now > casting_time) { - casting_time = DateTime.Now + CAST_FINISH; - State = BoDState.CastFinish; - CastSpell(spellLocation); - } - else if (State == BoDState.CastFinish && DateTime.Now > casting_time) { - m_Animator.SetTrigger("walk"); - State = BoDState.Walk; - - } - else if (target != null && DateTime.Now > teleport_cooldown && this.baseHP <= baseMaxHP*0.65) { - teleport_time = DateTime.Now + TELEPORT_START; - State = BoDState.TeleportLocate; - m_Animator.SetTrigger("death"); - teleport_cooldown = DateTime.Now + TELEPORT_COOLDOWN; - } - else if (target != null && State == BoDState.TeleportLocate && DateTime.Now > teleport_time) { - teleport_time = DateTime.Now + TELEPORT_LOCATE; - State = BoDState.Teleporting; - teleportLocation = target.transform.position; - } - else if (State == BoDState.Teleporting && DateTime.Now > teleport_time) { - teleport_time = DateTime.Now + TELEPORT_FINISH; - State = BoDState.TeleportFinish; - TeleportAttack(teleportLocation); - } - else if (State == BoDState.TeleportFinish && DateTime.Now > teleport_time) { - m_Animator.SetTrigger("walk"); - State = BoDState.Walk; - - } - else if (target != null && (State == BoDState.Walk || State == BoDState.Idle)){ - var movement = (new Vector2(target.position.x, target.position.y) - rb.position).normalized; - TryMove(movement); - RotateAnimation(-movement); - } - } - } - - public partial class BringerOfDeathController : EnemyController { - - protected void CastSpell(Vector3 spellLocation) { - var spell = PrefabService.SINGLETON.Instance(PROJECTILE_NAME, spellLocation); - spellCollider = spell.transform.GetChild(0).GetComponent<EmptyCollider>(); - spellCollider.OnColliderEnter2D_Action += Spell_onColliderEnter2D; - } - - protected void Spell_onColliderEnter2D(Collider2D other) { - var player = other.gameObject.GetComponent<PlayerController>(); - if(player != null) { - // Create attack object. - var attack = (AttackStats) new AttackStats{ - Damage = 1, - Knockback = 0, - Range = 0, - AttackSpeed = 0, - Source = transform.position, - Actor = this, - }.Calculate(Stats); - - // Get the player to take the damage. - if(player.TakeDamage(attack)){ - //rb position - player position - //Vector2 difference = (other.transform.position - transform.position).normalized; - //player.KnockBack(KnockbackForce, difference); - //animer nå ? - } - } - } - - protected void TeleportAttack(Vector3 teleportLocation) { - if (transform.position.x > teleportLocation.x) { - transform.position = teleportLocation + new Vector3(2, 0, 0); - } else { - transform.position = teleportLocation + new Vector3(-2, 0, 0); - } - m_Animator.SetTrigger("attack"); - } - } - - public enum BoDState { - Idle, Walk, Cast, Casting, CastLocate, CastFinish, Teleport, Teleporting, TeleportLocate, TeleportFinish, Attack - } + + public partial class BringerOfDeathController : EnemyController { + + protected static readonly TimeSpan SPELL_CAST_COOLDOWN = new TimeSpan(0, 0, 0, 4, 0); + protected static readonly TimeSpan CAST_START = new TimeSpan(0, 0, 0, 0, 500); + protected static readonly TimeSpan CAST_LOCATE = new TimeSpan(0, 0, 0, 0, 150); + protected static readonly TimeSpan CAST_FINISH = new TimeSpan(0, 0, 0, 0, 750); + + protected Vector3 spellLocation; + + protected DateTime casting_time = DateTime.Now; + protected DateTime spell_cooldown = DateTime.Now + SPELL_CAST_COOLDOWN; + + protected static readonly TimeSpan TELEPORT_COOLDOWN = new TimeSpan(0, 0, 0, 6, 0); + protected static readonly TimeSpan TELEPORT_START = new TimeSpan(0, 0, 0, 0, 500); + protected static readonly TimeSpan TELEPORT_LOCATE = new TimeSpan(0, 0, 0, 0, 50); + protected static readonly TimeSpan TELEPORT_FINISH = new TimeSpan(0, 0, 0, 0, 850); + + protected Vector3 teleportLocation; + + protected DateTime teleport_time = DateTime.Now; + protected DateTime teleport_cooldown = DateTime.Now + TELEPORT_COOLDOWN; + + public BoDState State { get; protected set; } = BoDState.Idle; + + protected EmptyCollider spellCollider; + + protected IAttack _testAttack; + public const string PROJECTILE_NAME = "Bosses/Attacks/Bringer_of_Death_Spell"; + + + protected override void Update() { + Regenerate(); + + if (target != null && DateTime.Now > spell_cooldown && (this.baseHP >= baseMaxHP * 0.65 || this.baseHP < baseMaxHP * 0.3)) { + casting_time = DateTime.Now + CAST_START; + State = BoDState.CastLocate; + m_Animator.SetTrigger("cast"); + spell_cooldown = DateTime.Now + SPELL_CAST_COOLDOWN; + } else if (target != null && State == BoDState.CastLocate && DateTime.Now > casting_time) { + casting_time = DateTime.Now + CAST_LOCATE; + State = BoDState.Casting; + spellLocation = target.transform.position; + } else if (State == BoDState.Casting && DateTime.Now > casting_time) { + casting_time = DateTime.Now + CAST_FINISH; + State = BoDState.CastFinish; + CastSpell(spellLocation); + } else if (State == BoDState.CastFinish && DateTime.Now > casting_time) { + m_Animator.SetTrigger("walk"); + State = BoDState.Walk; + + } else if (target != null && DateTime.Now > teleport_cooldown && this.baseHP <= baseMaxHP * 0.65) { + teleport_time = DateTime.Now + TELEPORT_START; + State = BoDState.TeleportLocate; + m_Animator.SetTrigger("death"); + teleport_cooldown = DateTime.Now + TELEPORT_COOLDOWN; + } else if (target != null && State == BoDState.TeleportLocate && DateTime.Now > teleport_time) { + teleport_time = DateTime.Now + TELEPORT_LOCATE; + State = BoDState.Teleporting; + teleportLocation = target.transform.position; + } else if (State == BoDState.Teleporting && DateTime.Now > teleport_time) { + teleport_time = DateTime.Now + TELEPORT_FINISH; + State = BoDState.TeleportFinish; + TeleportAttack(teleportLocation); + } else if (State == BoDState.TeleportFinish && DateTime.Now > teleport_time) { + m_Animator.SetTrigger("walk"); + State = BoDState.Walk; + + } else if (target != null && (State == BoDState.Walk || State == BoDState.Idle)) { + var movement = (new Vector2(target.position.x, target.position.y) - rb.position).normalized; + TryMove(movement); + RotateAnimation(-movement); + } + } + } + + public partial class BringerOfDeathController : EnemyController { + + protected void CastSpell(Vector3 spellLocation) { + var spell = PrefabService.SINGLETON.Instance(PROJECTILE_NAME, spellLocation); + spellCollider = spell.transform.GetChild(0).GetComponent<EmptyCollider>(); + spellCollider.OnColliderEnter2D_Action += Spell_onColliderEnter2D; + } + + protected void Spell_onColliderEnter2D(Collider2D other) { + var player = other.gameObject.GetComponent<PlayerController>(); + if (player != null) { + // Create attack object. + var attack = (AttackStats)new AttackStats { + Damage = 1, + Knockback = 0, + Range = 0, + AttackSpeed = 0, + Source = transform.position, + Actor = this, + }.Calculate(Stats); + + // Get the player to take the damage. + if (player.TakeDamage(attack)) { + //rb position - player position + //Vector2 difference = (other.transform.position - transform.position).normalized; + //player.KnockBack(KnockbackForce, difference); + //animer nå ? + } + } + } + + protected void TeleportAttack(Vector3 teleportLocation) { + if (transform.position.x > teleportLocation.x) { + transform.position = teleportLocation + new Vector3(2, 0, 0); + } else { + transform.position = teleportLocation + new Vector3(-2, 0, 0); + } + m_Animator.SetTrigger("attack"); + } + } + + public enum BoDState { + Idle, Walk, Cast, Casting, CastLocate, CastFinish, Teleport, Teleporting, TeleportLocate, TeleportFinish, Attack + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Bosses/SkeletonBossController.cs b/MrBigsock/Assets/Code/Bosses/SkeletonBossController.cs index fbc2f653..4f4a3127 100644 --- a/MrBigsock/Assets/Code/Bosses/SkeletonBossController.cs +++ b/MrBigsock/Assets/Code/Bosses/SkeletonBossController.cs @@ -5,151 +5,148 @@ using System.Linq; using System; namespace BigSock { - public partial class SkeletonBossController : EnemyController { - - - protected EmptyCollider chargeCollider; - - public SkeletonBossState State { get; protected set; } = SkeletonBossState.Idle; - - protected bool isInCharge = false; - - protected DateTime timer = DateTime.Now; - - protected DateTime nextChargeTime = DateTime.Now; - - protected static readonly TimeSpan CHARGE_COOLDOWN = new TimeSpan(0, 0, 0, 5, 0); - - protected static readonly TimeSpan CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 25); - - protected static readonly TimeSpan SECOND_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 800); - - protected static readonly TimeSpan FINISH_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 450); - - public double LeapForce => MovementSpeed*8; - - - protected override void Start() { - base.Start(); - - chargeCollider = transform.Find("ChargeCollider").GetComponent<EmptyCollider>(); - chargeCollider.OnColliderEnter2D_Action += Charge_OnColliderEnter2D; - chargeCollider.OnColliderStay2D_Action += Charge_OnColliderStay2D; - chargeCollider.OnColliderExit2D_Action += Charge_OnColliderExit2D; - } - - - protected override void Update() { - Regenerate(); - - if (target != null && (State == SkeletonBossState.Idle || State == SkeletonBossState.Walking)){ - - /* //walk - float step = speed * Time.deltaTime; - transform.position = Vector2.MoveTowards(transform.position, target.position, step); - - //distance = Vector3.Distance (transform.position, target.position); - //roter - RotateAnimation(); - */ - var movement = (new Vector2(target.position.x, target.position.y) - rb.position).normalized; - TryMove(movement); - RotateAnimation(movement); - } - else if (State == SkeletonBossState.Charge && DateTime.Now >= timer) { - var pos = target.position; //target.position; - var temp = (pos - rb.transform.position); - temp.z = 0; - var direction = temp.normalized; - //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); - Charge(direction, LeapForce); - timer = DateTime.Now + SECOND_CHARGE_WAIT_TIME; - State = SkeletonBossState.SecondCharge; - } - else if (State == SkeletonBossState.SecondCharge && DateTime.Now >= timer) { - var pos = target.position; //target.position; - var temp = (pos - rb.transform.position); - temp.z = 0; - var direction = temp.normalized; - //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); - Charge(direction, LeapForce*2); - timer = DateTime.Now + FINISH_CHARGE_WAIT_TIME; - State = SkeletonBossState.FinishAttack; - } - else if (State == SkeletonBossState.FinishAttack && DateTime.Now >= timer) { - State = SkeletonBossState.Walking; - m_Animator.SetTrigger("walk"); - } - } - - - protected virtual bool Charge(Vector2 direction, double leapForce) { - if(direction != Vector2.zero) { - rb.AddForce((float) leapForce * direction, ForceMode2D.Impulse); + public partial class SkeletonBossController : EnemyController { + + + protected EmptyCollider chargeCollider; + + public SkeletonBossState State { get; protected set; } = SkeletonBossState.Idle; + + protected bool isInCharge = false; + + protected DateTime timer = DateTime.Now; + + protected DateTime nextChargeTime = DateTime.Now; + + protected static readonly TimeSpan CHARGE_COOLDOWN = new TimeSpan(0, 0, 0, 5, 0); + + protected static readonly TimeSpan CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 25); + + protected static readonly TimeSpan SECOND_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 800); + + protected static readonly TimeSpan FINISH_CHARGE_WAIT_TIME = new TimeSpan(0, 0, 0, 0, 450); + + public double LeapForce => MovementSpeed * 8; + + + protected override void Start() { + base.Start(); + + chargeCollider = transform.Find("ChargeCollider").GetComponent<EmptyCollider>(); + chargeCollider.OnColliderEnter2D_Action += Charge_OnColliderEnter2D; + chargeCollider.OnColliderStay2D_Action += Charge_OnColliderStay2D; + chargeCollider.OnColliderExit2D_Action += Charge_OnColliderExit2D; + } + + + protected override void Update() { + Regenerate(); + + if (target != null && (State == SkeletonBossState.Idle || State == SkeletonBossState.Walking)) { + + /* //walk + float step = speed * Time.deltaTime; + transform.position = Vector2.MoveTowards(transform.position, target.position, step); + + //distance = Vector3.Distance (transform.position, target.position); + //roter + RotateAnimation(); + */ + var movement = (new Vector2(target.position.x, target.position.y) - rb.position).normalized; + TryMove(movement); + RotateAnimation(movement); + } else if (State == SkeletonBossState.Charge && DateTime.Now >= timer) { + var pos = target.position; //target.position; + var temp = (pos - rb.transform.position); + temp.z = 0; + var direction = temp.normalized; + //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + Charge(direction, LeapForce); + timer = DateTime.Now + SECOND_CHARGE_WAIT_TIME; + State = SkeletonBossState.SecondCharge; + } else if (State == SkeletonBossState.SecondCharge && DateTime.Now >= timer) { + var pos = target.position; //target.position; + var temp = (pos - rb.transform.position); + temp.z = 0; + var direction = temp.normalized; + //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + Charge(direction, LeapForce * 2); + timer = DateTime.Now + FINISH_CHARGE_WAIT_TIME; + State = SkeletonBossState.FinishAttack; + } else if (State == SkeletonBossState.FinishAttack && DateTime.Now >= timer) { + State = SkeletonBossState.Walking; + m_Animator.SetTrigger("walk"); + } + } + + + protected virtual bool Charge(Vector2 direction, double leapForce) { + if (direction != Vector2.zero) { + rb.AddForce((float)leapForce * direction, ForceMode2D.Impulse); return true; } return false; } - } + } - /* - Attack - */ - public partial class SkeletonBossController { + /* + Attack + */ + public partial class SkeletonBossController { - protected virtual void Charge_OnColliderEnter2D(Collider2D other) { + protected virtual void Charge_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") isInCharge = !isInCharge; } - protected virtual void Charge_OnColliderStay2D(Collider2D other) { - var player = other.gameObject.GetComponent<PlayerController>(); - if(player != null) { - if (DateTime.Now >= nextChargeTime) { - - m_Animator.SetTrigger("attack"); - timer = DateTime.Now + CHARGE_WAIT_TIME; - State = SkeletonBossState.Charge; - nextChargeTime = DateTime.Now + CHARGE_COOLDOWN; - } - } - } - - protected virtual void Charge_OnColliderExit2D(Collider2D other) { - if (other.gameObject.tag == "Player") isInCharge = !isInCharge; - //State = SkeletonBossState.Walking; - } + protected virtual void Charge_OnColliderStay2D(Collider2D other) { + var player = other.gameObject.GetComponent<PlayerController>(); + if (player != null) { + if (DateTime.Now >= nextChargeTime) { + + m_Animator.SetTrigger("attack"); + timer = DateTime.Now + CHARGE_WAIT_TIME; + State = SkeletonBossState.Charge; + nextChargeTime = DateTime.Now + CHARGE_COOLDOWN; + } + } + } + + protected virtual void Charge_OnColliderExit2D(Collider2D other) { + if (other.gameObject.tag == "Player") isInCharge = !isInCharge; + //State = SkeletonBossState.Walking; + } } - public partial class SkeletonBossController { + public partial class SkeletonBossController { protected override void Move_OnColliderEnter2D(Collider2D other) { //Debug.Log("enter"); - if (other.gameObject.tag == "Player" && State != SkeletonBossState.Charge && State != SkeletonBossState.SecondCharge && State != SkeletonBossState.FinishAttack){ + if (other.gameObject.tag == "Player" && State != SkeletonBossState.Charge && State != SkeletonBossState.SecondCharge && State != SkeletonBossState.FinishAttack) { //Debug.Log("enter if"); - + m_Animator.SetTrigger("walk"); target = other.transform; } } protected override void Move_OnColliderExit2D(Collider2D other) { - if (other.gameObject.tag == "Player"){ + if (other.gameObject.tag == "Player") { m_Animator.SetTrigger("idle"); target = other.transform; - target = null; - } + target = null; + } } - + } - public partial class SkeletonBossController { - + public partial class SkeletonBossController { - } + + } /* The different states the slime can be in. diff --git a/MrBigsock/Assets/Code/Bosses/attacks/BoDSpell.cs b/MrBigsock/Assets/Code/Bosses/attacks/BoDSpell.cs index cf594748..662d1ae0 100644 --- a/MrBigsock/Assets/Code/Bosses/attacks/BoDSpell.cs +++ b/MrBigsock/Assets/Code/Bosses/attacks/BoDSpell.cs @@ -8,17 +8,16 @@ using UnityEngine.InputSystem; namespace BigSock { -public class BoDSpell : MonoBehaviour -{ + public class BoDSpell : MonoBehaviour { - protected static readonly TimeSpan DURATION = new TimeSpan(0, 0, 0, 1, 500); + protected static readonly TimeSpan DURATION = new TimeSpan(0, 0, 0, 1, 500); - protected DateTime destroyObject = DateTime.Now + DURATION; + protected DateTime destroyObject = DateTime.Now + DURATION; - private void Update() { - if (DateTime.Now > destroyObject) { - Destroy(this.gameObject); - } - } -} + private void Update() { + if (DateTime.Now > destroyObject) { + Destroy(this.gameObject); + } + } + } } diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 968d7824..f1674f8f 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -10,7 +10,7 @@ namespace BigSock { /* Common class for all characters. - */ + */ public partial class Character : Entity { public const float MOVE_MULTIPLIER = 0.7f; @@ -27,14 +27,14 @@ namespace BigSock { Cooldown between attacks. */ public float AttackCooldown => 1.0f / AttackSpeed; - + /* Movement speed of the character. */ public float MovementSpeed => Stats.MoveSpeed; public float baseMovementSpeed = 1; - + /* Damage of the character. */ @@ -47,16 +47,16 @@ namespace BigSock { public float KnockbackForce => Stats.Knockback; public float knockbackForce = 150; - + /* Hit points of the character. */ - public float HP { - get => baseHP; - set => baseHP = value; + public float HP { + get => baseHP; + set => baseHP = value; } public float baseHP = 10; - + /* Mana of the character. */ @@ -66,7 +66,7 @@ namespace BigSock { Stamina of the character. */ public float Stamina { get; set; } - + /* Maximum hit points of the character. */ @@ -79,7 +79,7 @@ namespace BigSock { public float dropXP; public float xp; public float maxXp; - public int level; + public int level; public HpBarEnemy HpBarEnemy; @@ -128,7 +128,7 @@ namespace BigSock { MaxStamina = 20, RegenMana = 2, RegenStamina = 1, - + Damage = baseDamage, MoveSpeed = baseMovementSpeed, Knockback = knockbackForce, @@ -141,14 +141,14 @@ namespace BigSock { }; // Add audio sources. - foreach(var s in Camera.main.gameObject.GetComponents<AudioSource>()) - if(s != null) + foreach (var s in Camera.main.gameObject.GetComponents<AudioSource>()) + if (s != null) source.Add(s); var src = GetComponent<AudioSource>(); - if(src != null) source.Add(src); + if (src != null) source.Add(src); + - UpdateModifiers(); Mana = Stats.MaxMana; @@ -176,7 +176,7 @@ namespace BigSock { Gets the AbilityParams we want. */ public virtual IAbilityParam GetAbilityParam(Vector2? targetPos) { - return new AbilityParam{ + return new AbilityParam { Actor = this, TargetPos = targetPos, MovementDir = moveDir, @@ -185,13 +185,12 @@ namespace BigSock { /* Using a courutine to set trigger in knockback. */ - IEnumerator knockBackTimer() - { + IEnumerator knockBackTimer() { inKnockBack = true; yield return new WaitForSeconds(0.15F); rb.velocity = Vector2.zero; - inKnockBack = false; - } + inKnockBack = false; + } /* Add Knockback. (used only for dash ?) @@ -199,26 +198,26 @@ namespace BigSock { public void KnockBack(float force, Vector2 difference) { rb.AddForce(difference * force, ForceMode2D.Impulse); StartCoroutine(knockBackTimer()); - + //rb.MovePosition((Vector2)transform.position + (difference * force * Time.fixedDeltaTime)); } public void KnockBack(IAttackStats attack) { - Vector2 difference = ((Vector2) transform.position - attack.Source).normalized; + Vector2 difference = ((Vector2)transform.position - attack.Source).normalized; rb.AddForce(difference * attack.Knockback, ForceMode2D.Impulse); StartCoroutine(knockBackTimer()); } - + /* Try to move in a given direction. */ protected virtual bool TryMove(Vector2 direction) { - + moveDir = direction; - if(direction != Vector2.zero && !inKnockBack) { + if (direction != Vector2.zero && !inKnockBack) { //Using movePosition to get a "snappy" movement. //rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); - rb.MovePosition((Vector2)transform.position + (direction * (float) MovementSpeed * Time.fixedDeltaTime * MOVE_MULTIPLIER)); + rb.MovePosition((Vector2)transform.position + (direction * (float)MovementSpeed * Time.fixedDeltaTime * MOVE_MULTIPLIER)); //rb.velocity = (direction * (float) MovementSpeed); return true; } @@ -229,11 +228,11 @@ namespace BigSock { Adds damage to the character if they don't have IFrames. */ public virtual bool TakeDamage(AttackStats attack) { - if(attack == null) throw new ArgumentNullException(nameof(attack)); - if(!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack)); + if (attack == null) throw new ArgumentNullException(nameof(attack)); + if (!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack)); // Check if player has IFrames - if(HasIFrames) + if (HasIFrames) return false; // Start new IFrames @@ -241,26 +240,26 @@ namespace BigSock { // Trigger the event for taking damage. OnTakeDamage?.Invoke(this, attack.Actor, attack); - - if(HpBarEnemy == null) print("Error feil funk ikke"); + + if (HpBarEnemy == null) print("Error feil funk ikke"); HpBarEnemy?.SetMaxHpEnemy(this.MaxHP); HpBarEnemy?.SetHPEnemy(this.HP); print(this.HP + " ___ " + this.MaxHP); - if(TakeDamageAudio != null && source?.Count > 0 && source[0] != null) { + if (TakeDamageAudio != null && source?.Count > 0 && source[0] != null) { source[0].clip = TakeDamageAudio; source[0].Play(); } // Inform the attacker they hit us. - if(attack.Actor != null){ + if (attack.Actor != null) { attack.Actor.TargetHit(this, attack); - - - } - + + + } + // Add damage HP -= attack.Damage; @@ -276,7 +275,7 @@ namespace BigSock { Try to kill the character. */ public bool TryKill(AttackStats attack) { - if(Alive && HP <= 0) { + if (Alive && HP <= 0) { // Trigger the event for us dying. @@ -287,9 +286,9 @@ namespace BigSock { Alive = false; // Inform the attacker killed us. - if(attack.Actor != null) { + if (attack.Actor != null) { attack.Actor.TargetKilled(this, attack); - if(attack.Actor is PlayerController player) + if (attack.Actor is PlayerController player) player.GainXp(dropXP); } @@ -306,7 +305,7 @@ namespace BigSock { */ public bool TryHeal(float amount) { // Can't heal if full. - if(HP >= MaxHP) { + if (HP >= MaxHP) { print($"[Character.TryHeal()] Already Full! ({HP:N1} >= {MaxHP:N1})"); return false; } @@ -316,7 +315,7 @@ namespace BigSock { // Heal the character. var res = HP + amount; - if(res > MaxHP) res = MaxHP; + if (res > MaxHP) res = MaxHP; HP = res; AfterHeal(); return true; @@ -326,7 +325,7 @@ namespace BigSock { Method for what to do when the character takes damage. */ protected virtual void AfterDamage(IAttackStats attack) { - print($"[Character.AfterDamage()] {HP + attack.Damage:N1} - {attack.Damage:N1} = {HP:N1} {(attack.IsCrit ? "[CRIT]":"")}"); + print($"[Character.AfterDamage()] {HP + attack.Damage:N1} - {attack.Damage:N1} = {HP:N1} {(attack.IsCrit ? "[CRIT]" : "")}"); KnockBack(attack); } @@ -351,19 +350,19 @@ namespace BigSock { Items */ public partial class Character { - + /* Adds a listener for a conditional item to this character's event. */ public void AddItemListener(IConditionalItem item) { - switch(item.Trigger) { - case TriggerType.Fire: OnFire += ((OnFireItemBase) item).Handler; break; - case TriggerType.Hit: OnHit += ((OnHitItemBase) item).Handler; break; - case TriggerType.Kill: OnKill += ((OnKillItemBase) item).Handler; break; + switch (item.Trigger) { + case TriggerType.Fire: OnFire += ((OnFireItemBase)item).Handler; break; + case TriggerType.Hit: OnHit += ((OnHitItemBase)item).Handler; break; + case TriggerType.Kill: OnKill += ((OnKillItemBase)item).Handler; break; - case TriggerType.TakeDamage: OnTakeDamage += ((OnTakeDamageItemBase) item).Handler; break; - case TriggerType.Heal: OnHeal += ((OnHealItemBase) item).Handler; break; - case TriggerType.Death: OnDeath += ((OnDeathItemBase) item).Handler; break; + case TriggerType.TakeDamage: OnTakeDamage += ((OnTakeDamageItemBase)item).Handler; break; + case TriggerType.Heal: OnHeal += ((OnHealItemBase)item).Handler; break; + case TriggerType.Death: OnDeath += ((OnDeathItemBase)item).Handler; break; default: print($"[Character.AddItemListener()] No handler for {item.Trigger}!"); break; } @@ -373,14 +372,14 @@ namespace BigSock { Remove a listener for a conditional item from this character's event. */ public void RemoveItemListener(IConditionalItem item) { - switch(item.Trigger) { - case TriggerType.Fire: OnFire -= ((OnFireItemBase) item).Handler; break; - case TriggerType.Hit: OnHit -= ((OnHitItemBase) item).Handler; break; - case TriggerType.Kill: OnKill -= ((OnKillItemBase) item).Handler; break; + switch (item.Trigger) { + case TriggerType.Fire: OnFire -= ((OnFireItemBase)item).Handler; break; + case TriggerType.Hit: OnHit -= ((OnHitItemBase)item).Handler; break; + case TriggerType.Kill: OnKill -= ((OnKillItemBase)item).Handler; break; - case TriggerType.TakeDamage: OnTakeDamage -= ((OnTakeDamageItemBase) item).Handler; break; - case TriggerType.Heal: OnHeal -= ((OnHealItemBase) item).Handler; break; - case TriggerType.Death: OnDeath -= ((OnDeathItemBase) item).Handler; break; + case TriggerType.TakeDamage: OnTakeDamage -= ((OnTakeDamageItemBase)item).Handler; break; + case TriggerType.Heal: OnHeal -= ((OnHealItemBase)item).Handler; break; + case TriggerType.Death: OnDeath -= ((OnDeathItemBase)item).Handler; break; default: print($"[Character.RemoveItemListener()] No handler for {item.Trigger}!"); break; } @@ -390,7 +389,7 @@ namespace BigSock { Try to pick up an item. */ public bool TryPickUpItem(IItem item) { - if(Inventory.AddItem(item) != -1) { + if (Inventory.AddItem(item) != -1) { //UpdateModifiers(); print($"[Character.TryPickUpItem()] {item.Name} picked up. ({Inventory.Backpack.Count}/{Inventory.BackpackCap})"); return true; @@ -433,10 +432,10 @@ namespace BigSock { public void TargetKilled(Character target, AttackStats attack) { OnKill?.Invoke(this, target, attack); } - + public void GiveXp(float xp) { - this.xp += xp; + this.xp += xp; OnGainedXP?.Invoke(this, xp); } @@ -502,7 +501,7 @@ namespace BigSock { */ public event Action<Character> OnLevelUp; - + /* Triggers when character enters a new room. @@ -525,7 +524,7 @@ namespace BigSock { */ public event Action<Character> OnEnterNewStage; - + } @@ -539,13 +538,13 @@ namespace BigSock { Indicates whether or not the characer is alive. */ public bool Alive { get; private set; } = true; - + /* How long between each time the character can take damage. */ - public TimeSpan IFrameDuration { - get => _iFrameDuration; - protected set => _iFrameDuration = value; + public TimeSpan IFrameDuration { + get => _iFrameDuration; + protected set => _iFrameDuration = value; } public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 0); @@ -584,18 +583,18 @@ namespace BigSock { Stores the next time the character can recieve damage. */ public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now; - + /* Adds a status effect to the character. */ public bool AddStatusEffect(StatusEffectType statusType, TimeSpan amount) { - switch(statusType) { + switch (statusType) { case StatusEffectType.Invincible: return AddIFrames(amount); - case StatusEffectType.Invisible: return AddInvisibility(amount); - case StatusEffectType.Stun: return AddStun(amount); - default: return false; + case StatusEffectType.Invisible: return AddInvisibility(amount); + case StatusEffectType.Stun: return AddStun(amount); + default: return false; } } @@ -609,9 +608,9 @@ namespace BigSock { var wouldExpire = DateTime.Now + IFrameDuration; // Only if that's later than current. - if(wouldExpire > NextTimeNotStunned) { + if (wouldExpire > NextTimeNotStunned) { // If character currently doesn't have the status effect. - if(NextTimeNotStunned < DateTime.Now) { + if (NextTimeNotStunned < DateTime.Now) { ApplyStun(); } @@ -625,13 +624,13 @@ namespace BigSock { Appies Stun to the character. */ private void ApplyStun() { - + } /* Removes Stun for the character. */ private void RemoveStun() { - + } @@ -644,9 +643,9 @@ namespace BigSock { var wouldExpire = DateTime.Now + IFrameDuration; // Only if that's later than current. - if(wouldExpire > NextTimeVisible) { + if (wouldExpire > NextTimeVisible) { // If character currently doesn't have the status effect. - if(NextTimeVisible < DateTime.Now) { + if (NextTimeVisible < DateTime.Now) { ApplyInvisibility(); } @@ -660,13 +659,13 @@ namespace BigSock { Appies invisibility to the character. */ private void ApplyInvisibility() { - + } /* Removes invisibility for the character. */ private void RemoveInvisibility() { - + } @@ -679,9 +678,9 @@ namespace BigSock { var nextCanTakeDamage = DateTime.Now + amount; // Only if that's later than current. - if(nextCanTakeDamage > NextTimeCanTakeDamage) { + if (nextCanTakeDamage > NextTimeCanTakeDamage) { // If character currently doesn't have the status effect. - if(NextTimeCanTakeDamage < DateTime.Now) { + if (NextTimeCanTakeDamage < DateTime.Now) { ApplyIFrames(); } @@ -695,13 +694,13 @@ namespace BigSock { Appies IFrames to the character. */ private void ApplyIFrames() { - + } /* Removes IFrames for the character. */ private void RemoveIFrames() { - + } } diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/AbilityEntity.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/AbilityEntity.cs index bdb968d6..eececd02 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/AbilityEntity.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/AbilityEntity.cs @@ -5,6 +5,7 @@ using UnityEngine; using UnityEngine.InputSystem; + namespace BigSock { /* An object representing an ability held by a player. @@ -37,12 +38,12 @@ namespace BigSock { // How far into the cooldown the attack is. - public float CooldownPercent - => (float) Math.Clamp((DateTime.Now - Ability.NextTimeCanUse + Ability.Cooldown) / Ability.Cooldown, 0, 1); + public float CooldownPercent + => (float)Math.Clamp((DateTime.Now - Ability.NextTimeCanUse + Ability.Cooldown) / Ability.Cooldown, 0, 1); public AbilityEntity(IAbility ability, int index, List<KeyCode> keys = null) { - if(ability == null) throw new ArgumentNullException(nameof(ability)); + if (ability == null) throw new ArgumentNullException(nameof(ability)); Ability = ability; Index = index; diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs index 920ec10e..25f8be23 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs @@ -23,8 +23,8 @@ namespace BigSock { /* The name of the ability. */ - public abstract string Name { get;} - + public abstract string Name { get; } + /* The description of the ability. */ @@ -86,7 +86,7 @@ namespace BigSock { What kind of firetype this ability uses. */ public FireType FireType { get; protected set; } - + /* The minimum time in seconds the ability needs to be charged. */ @@ -108,31 +108,31 @@ namespace BigSock { var actor = par.Actor; // Check the charging - if(FireType == FireType.Charge) { + if (FireType == FireType.Charge) { // Check that we charged the minimum time. - if(par.ChargeTime < MinCharge) return false; + if (par.ChargeTime < MinCharge) return false; // Calculate how much optional charging we did. par.ChargeTimePercent = Math.Clamp((par.ChargeTime - MinCharge) / (MaxCharge - MinCharge), 0f, 1f); } - + // Check that the ability is cooled down. - if(Ready) { + if (Ready) { //> Handle checking costs here. - if(ManaCost > 0f && actor.Mana < ManaCost) return false; - if(StaminaCost > 0f && actor.Stamina < StaminaCost) return false; - if(HPCost > 0f && actor.HP < HPCost) return false; + if (ManaCost > 0f && actor.Mana < ManaCost) return false; + if (StaminaCost > 0f && actor.Stamina < StaminaCost) return false; + if (HPCost > 0f && actor.HP < HPCost) return false; // Activate the ability. var res = Activate(par); // If it succeeded, update cooldown and pay ability cost. - if(res) { + if (res) { NextTimeCanUse = DateTime.Now + Cooldown; //> Handle paying the cost (HP, mana, stamina) here. - if(ManaCost > 0f) actor.Mana -= ManaCost; - if(StaminaCost > 0f) actor.Stamina -= StaminaCost; - if(HPCost > 0f) actor.HP -= HPCost; + if (ManaCost > 0f) actor.Mana -= ManaCost; + if (StaminaCost > 0f) actor.Stamina -= StaminaCost; + if (HPCost > 0f) actor.HP -= HPCost; } return res; @@ -163,9 +163,9 @@ namespace BigSock { .AppendLine(Description) .AppendLine($"Cooldown: {Cooldown}"); - if(ManaCost != 0) sb.AppendLine($"Mana Cost: {ManaCost}"); - if(StaminaCost != 0) sb.AppendLine($"Stamina Cost: {StaminaCost}"); - if(HPCost != 0) sb.AppendLine($"HP Cost: {HPCost}"); + if (ManaCost != 0) sb.AppendLine($"Mana Cost: {ManaCost}"); + if (StaminaCost != 0) sb.AppendLine($"Stamina Cost: {StaminaCost}"); + if (HPCost != 0) sb.AppendLine($"HP Cost: {HPCost}"); return sb.ToString(); } diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs index a0c6b44b..107f4714 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs @@ -11,7 +11,7 @@ namespace BigSock { Base class for attacks. */ public abstract class BaseAttack : BaseAbility, IAttack { - + /* The attack stats of the ability. */ diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs index 7fa26add..31edf503 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs @@ -20,7 +20,7 @@ namespace BigSock { The name of the ability. */ string Name { get; } - + /* The description of the ability. */ @@ -75,7 +75,7 @@ namespace BigSock { What kind of firetype this ability uses. */ FireType FireType { get; } - + /* The minimum time in seconds the ability needs to be charged. */ @@ -104,11 +104,11 @@ namespace BigSock { Try to use the ability. */ bool Use(IAbilityParam par); - + /* Returns text that represents info about the ability. */ string GetToolTip(); - + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbilityParam.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbilityParam.cs index e0b29b97..86cbe564 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbilityParam.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbilityParam.cs @@ -42,6 +42,7 @@ namespace BigSock { */ float ChargeTimePercent { get; set; } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs index 6fdcdfb0..0b2cd839 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs @@ -5,6 +5,7 @@ using UnityEngine; using UnityEngine.InputSystem; + namespace BigSock { /* @@ -18,6 +19,6 @@ namespace BigSock { - + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/DestroyObject.cs b/MrBigsock/Assets/Code/DestroyObject.cs index 3b65125f..a03fe830 100644 --- a/MrBigsock/Assets/Code/DestroyObject.cs +++ b/MrBigsock/Assets/Code/DestroyObject.cs @@ -5,23 +5,19 @@ using UnityEngine; namespace BigSock { - public class DestroyObject : MonoBehaviour - { + public class DestroyObject : MonoBehaviour { - private void OnCollisionEnter2D(Collision2D collision) - { - Destroy(this.gameObject); - } + private void OnCollisionEnter2D(Collision2D collision) { + Destroy(this.gameObject); + } - // Start is called before the first frame update - void Start() - { - - } + // Start is called before the first frame update + void Start() { - // Update is called once per frame - void Update() - { - } + } + + // Update is called once per frame + void Update() { + } } } diff --git a/MrBigsock/Assets/Code/EmptyCollider.cs b/MrBigsock/Assets/Code/EmptyCollider.cs index 0198f138..51d76f8e 100644 --- a/MrBigsock/Assets/Code/EmptyCollider.cs +++ b/MrBigsock/Assets/Code/EmptyCollider.cs @@ -4,27 +4,23 @@ using UnityEngine; using System; namespace BigSock { - public class EmptyCollider : MonoBehaviour - { - public event Action<Collider2D> OnColliderEnter2D_Action; - public event Action<Collider2D> OnColliderStay2D_Action; - public event Action<Collider2D> OnColliderExit2D_Action; - - private void OnTriggerEnter2D(Collider2D other) - { - //Debug.Log("enter"); - OnColliderEnter2D_Action?.Invoke(other); - } + public class EmptyCollider : MonoBehaviour { + public event Action<Collider2D> OnColliderEnter2D_Action; + public event Action<Collider2D> OnColliderStay2D_Action; + public event Action<Collider2D> OnColliderExit2D_Action; - private void OnTriggerStay2D(Collider2D other) - { - OnColliderStay2D_Action?.Invoke(other); - } + private void OnTriggerEnter2D(Collider2D other) { + //Debug.Log("enter"); + OnColliderEnter2D_Action?.Invoke(other); + } - private void OnTriggerExit2D(Collider2D other) - { - //Debug.Log("exit"); - OnColliderExit2D_Action?.Invoke(other); - } + private void OnTriggerStay2D(Collider2D other) { + OnColliderStay2D_Action?.Invoke(other); + } + + private void OnTriggerExit2D(Collider2D other) { + //Debug.Log("exit"); + OnColliderExit2D_Action?.Invoke(other); + } } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/FollowPlayer.cs b/MrBigsock/Assets/Code/FollowPlayer.cs index 28c604e8..28614c99 100644 --- a/MrBigsock/Assets/Code/FollowPlayer.cs +++ b/MrBigsock/Assets/Code/FollowPlayer.cs @@ -4,132 +4,113 @@ using Cinemachine; using UnityEngine; -namespace Bigsock -{ - public class FollowPlayer : MonoBehaviour - { - [SerializeField] NeighbourMapGenerator neighborMapGenerator; - [SerializeField] CinemachineConfiner2D cameraMap; - [SerializeField] GameObject victoryScreen; +namespace Bigsock { + public class FollowPlayer : MonoBehaviour { + [SerializeField] NeighbourMapGenerator neighborMapGenerator; + [SerializeField] CinemachineConfiner2D cameraMap; + [SerializeField] GameObject victoryScreen; - //Unity varibles - private GameObject[] boss; - private GameObject player; - private GameObject[] enemies; - private GameObject[] Chest; - private List<GameObject> chests; - private GameObject stair; + //Unity varibles + private GameObject[] boss; + private GameObject player; + private GameObject[] enemies; + private GameObject[] Chest; + private List<GameObject> chests; + private GameObject stair; - //Normal variables - private int levels = 0; - private static int LEVEL_CAP = 2; - private int roomNr = 0; - private bool stairs_down; - private int victoryHold = 0; + //Normal variables + private int levels = 0; + private static int LEVEL_CAP = 2; + private int roomNr = 0; + private bool stairs_down; + private int victoryHold = 0; - void Start() - { - chests = new List<GameObject>(); - player = GameObject.Find("BigSock"); - InitializeLevel(); - } + void Start() { + chests = new List<GameObject>(); + player = GameObject.Find("BigSock"); + InitializeLevel(); + } - void LateUpdate() - { - boss = GameObject.FindGameObjectsWithTag("Boss"); - enemies = GameObject.FindGameObjectsWithTag((roomNr).ToString()); - - if (boss.Length == 0 && levels < LEVEL_CAP) - { - if (!stair.activeInHierarchy) - { - levels++; - } - stair.SetActive(true); - stairs_down = stair.GetComponent<Stairs>().stairs_touch; - - } - if (levels == LEVEL_CAP && victoryHold == 0) - { - VictoryScreen(); - victoryHold++; - } + void LateUpdate() { + boss = GameObject.FindGameObjectsWithTag("Boss"); + enemies = GameObject.FindGameObjectsWithTag((roomNr).ToString()); - if (stairs_down) - { - ClearScene(); - player.transform.position = new Vector3(9,5,0); - InitializeLevel(); - } + if (boss.Length == 0 && levels < LEVEL_CAP) { + if (!stair.activeInHierarchy) { + levels++; + } + stair.SetActive(true); + stairs_down = stair.GetComponent<Stairs>().stairs_touch; - cameraMap.InvalidateCache(); + } + if (levels == LEVEL_CAP && victoryHold == 0) { + VictoryScreen(); + victoryHold++; + } - if (enemies.Length == 0) - { - chests[roomNr].SetActive(true); - if(roomNr + 1 < NeighbourMapGenerator.GetRoomListCount() - 1) - { - roomNr++; - } - } - if(boss.Length == 0) - { - chests[1 + roomNr].SetActive(true); - } - } + if (stairs_down) { + ClearScene(); + player.transform.position = new Vector3(9, 5, 0); + InitializeLevel(); + } - private void OnDestroy() - { - ClearScene(); - } + cameraMap.InvalidateCache(); - /* - *Deletes all game objects from the scene that is not the player - *and also resets all arrays that have been made*/ - private void ClearScene() - { - roomNr = 0; - foreach (GameObject c in chests) - { - DestroyImmediate(c); - } - chests.Clear(); - DestroyImmediate(stair); - NeighbourMapGenerator.ClearRoomList(); - TilemapGenerator.SetRoomIDZero(); - TilemapGenerator.resetMaps(); - } + if (enemies.Length == 0) { + chests[roomNr].SetActive(true); + if (roomNr + 1 < NeighbourMapGenerator.GetRoomListCount() - 1) { + roomNr++; + } + } + if (boss.Length == 0) { + chests[1 + roomNr].SetActive(true); + } + } - /* - *Initializes the victory screen*/ - private void VictoryScreen() - { - Time.timeScale = 0; - GameObject canvas = GameObject.Find("Canvas"); - if (canvas != null) - { - Instantiate(victoryScreen, canvas.transform); - } - } + private void OnDestroy() { + ClearScene(); + } - /* - *Creates a level and adds objects to the different arrays */ - private void InitializeLevel() - { - neighborMapGenerator.RunProceduralGeneration(); - Chest = GameObject.FindGameObjectsWithTag("Chest"); - stair = GameObject.Find("Stairs(Clone)"); - stairs_down = stair.GetComponent<Stairs>().stairs_touch; - foreach (GameObject c in Chest) - { - if (c != null) - { - c.SetActive(false); - chests.Add(c); - } - } - stairs_down = stair.GetComponent<Stairs>().stairs_touch; - stair.SetActive(false); - } - } + /* + *Deletes all game objects from the scene that is not the player + *and also resets all arrays that have been made*/ + private void ClearScene() { + roomNr = 0; + foreach (GameObject c in chests) { + DestroyImmediate(c); + } + chests.Clear(); + DestroyImmediate(stair); + NeighbourMapGenerator.ClearRoomList(); + TilemapGenerator.SetRoomIDZero(); + TilemapGenerator.resetMaps(); + } + + /* + *Initializes the victory screen*/ + private void VictoryScreen() { + Time.timeScale = 0; + GameObject canvas = GameObject.Find("Canvas"); + if (canvas != null) { + Instantiate(victoryScreen, canvas.transform); + } + } + + /* + *Creates a level and adds objects to the different arrays */ + private void InitializeLevel() { + neighborMapGenerator.RunProceduralGeneration(); + Chest = GameObject.FindGameObjectsWithTag("Chest"); + stair = GameObject.Find("Stairs(Clone)"); + stairs_down = stair.GetComponent<Stairs>().stairs_touch; + foreach (GameObject c in Chest) { + if (c != null) { + c.SetActive(false); + chests.Add(c); + } + } + stairs_down = stair.GetComponent<Stairs>().stairs_touch; + stair.SetActive(false); + } + } } diff --git a/MrBigsock/Assets/Code/InteractionSystem/Chest.cs b/MrBigsock/Assets/Code/InteractionSystem/Chest.cs index 8be16c43..b7153a66 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/Chest.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/Chest.cs @@ -8,42 +8,41 @@ using BigSock.Service; using BigSock.Item; namespace BigSock.Interact { - public class Chest : MonoBehaviour, IInteractable - { - [SerializeField] private string _prompt; - [SerializeField] private Animator animator; - [SerializeField] private string goldenChestOpen = "OpeningGoldChest"; - [SerializeField] private string goldenChestClose = "ClosingGoldChest"; - [SerializeField] private string idleGoldChest = "Idle"; - - public SpriteRenderer spriteRenderer; - public Sprite closedSprite; - public Sprite openedSprite; - public List<IItem> items; - - void Start() { - animator = gameObject.GetComponent<Animator>(); - items = ItemService.SINGLETON.Get3Random(); - } - - public List<IItem> GetChestItems() { - return items; - } - - public void ItemNotPicked() { - GetComponent<Animator>().Play(goldenChestClose); - } - - public string InteractionPrompt => _prompt; - - public bool Interact(Interactor interactor) { - if (spriteRenderer.sprite != openedSprite) { - var chestContents = PrefabService.SINGLETON.Instance("UI/ChestContents", GameObject.FindWithTag("MainCamera").transform.position+new Vector3(1000,600,0)); - chestContents.gameObject.GetComponent<ChestDisplay>().setChestObject(this.gameObject); - chestContents.transform.SetParent(GameObject.Find("Canvas").transform); - GetComponent<Animator>().Play(goldenChestOpen); - return true; - } else return false; - } - } + public class Chest : MonoBehaviour, IInteractable { + [SerializeField] private string _prompt; + [SerializeField] private Animator animator; + [SerializeField] private string goldenChestOpen = "OpeningGoldChest"; + [SerializeField] private string goldenChestClose = "ClosingGoldChest"; + [SerializeField] private string idleGoldChest = "Idle"; + + public SpriteRenderer spriteRenderer; + public Sprite closedSprite; + public Sprite openedSprite; + public List<IItem> items; + + void Start() { + animator = gameObject.GetComponent<Animator>(); + items = ItemService.SINGLETON.Get3Random(); + } + + public List<IItem> GetChestItems() { + return items; + } + + public void ItemNotPicked() { + GetComponent<Animator>().Play(goldenChestClose); + } + + public string InteractionPrompt => _prompt; + + public bool Interact(Interactor interactor) { + if (spriteRenderer.sprite != openedSprite) { + var chestContents = PrefabService.SINGLETON.Instance("UI/ChestContents", GameObject.FindWithTag("MainCamera").transform.position + new Vector3(1000, 600, 0)); + chestContents.gameObject.GetComponent<ChestDisplay>().setChestObject(this.gameObject); + chestContents.transform.SetParent(GameObject.Find("Canvas").transform); + GetComponent<Animator>().Play(goldenChestOpen); + return true; + } else return false; + } + } } diff --git a/MrBigsock/Assets/Code/InteractionSystem/Door.cs b/MrBigsock/Assets/Code/InteractionSystem/Door.cs index 604867d6..ee915167 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/Door.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/Door.cs @@ -4,38 +4,36 @@ using System.Collections.Generic; using UnityEngine; namespace BigSock.Interact { - public class Door : MonoBehaviour, IInteractable - { - [SerializeField] private string _prompt; - public SpriteRenderer spriteRenderer; - public Sprite newSprite; - private GameObject[] enemies; - private GameObject player; - private GameObject cameraPlayer; - private int i = TilemapGenerator.NextRoom(); - private GameObject boundary; - GameObject door; + public class Door : MonoBehaviour, IInteractable { + [SerializeField] private string _prompt; + public SpriteRenderer spriteRenderer; + public Sprite newSprite; + private GameObject[] enemies; + private GameObject player; + private GameObject cameraPlayer; + private int i = TilemapGenerator.NextRoom(); + private GameObject boundary; + GameObject door; - public string InteractionPrompt => _prompt; + public string InteractionPrompt => _prompt; - public bool Interact(Interactor interactor) { - if(i > 0)enemies = GameObject.FindGameObjectsWithTag((i - 1).ToString()); - else if (i == 0) enemies = GameObject.FindGameObjectsWithTag((i).ToString()); - if (enemies.Length == 0) - { - Debug.Log("Opening door!"); - spriteRenderer.sprite = newSprite; - player = GameObject.Find("BigSock"); - boundary = GameObject.Find("CameraBoundry"); - cameraPlayer = GameObject.Find("Main Camera"); - player.transform.position = TilemapGenerator.DoorLocaitonTransport(i); - cameraPlayer.transform.position = player.transform.position; - boundary.GetComponent<PolygonCollider2D>().SetPath(0, TilemapGenerator.GetRoomBoundary(i)); - door = GameObject.Find("ClosedDoor(Clone)"); - Destroy(door); - return true; - } - return false; - } - } + public bool Interact(Interactor interactor) { + if (i > 0) enemies = GameObject.FindGameObjectsWithTag((i - 1).ToString()); + else if (i == 0) enemies = GameObject.FindGameObjectsWithTag((i).ToString()); + if (enemies.Length == 0) { + Debug.Log("Opening door!"); + spriteRenderer.sprite = newSprite; + player = GameObject.Find("BigSock"); + boundary = GameObject.Find("CameraBoundry"); + cameraPlayer = GameObject.Find("Main Camera"); + player.transform.position = TilemapGenerator.DoorLocaitonTransport(i); + cameraPlayer.transform.position = player.transform.position; + boundary.GetComponent<PolygonCollider2D>().SetPath(0, TilemapGenerator.GetRoomBoundary(i)); + door = GameObject.Find("ClosedDoor(Clone)"); + Destroy(door); + return true; + } + return false; + } + } } diff --git a/MrBigsock/Assets/Code/InteractionSystem/IInteractable.cs b/MrBigsock/Assets/Code/InteractionSystem/IInteractable.cs index 0827a603..83af548a 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/IInteractable.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/IInteractable.cs @@ -3,12 +3,11 @@ using System.Collections.Generic; using UnityEngine; namespace BigSock.Interact { - public interface IInteractable - { - public string InteractionPrompt { get; } - public bool Interact(Interactor interactor) { - throw new System.NotImplementedException(); - } + public interface IInteractable { + public string InteractionPrompt { get; } + public bool Interact(Interactor interactor) { + throw new System.NotImplementedException(); + } - } + } } diff --git a/MrBigsock/Assets/Code/InteractionSystem/Interactor.cs b/MrBigsock/Assets/Code/InteractionSystem/Interactor.cs index 280030b7..9dd448f6 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/Interactor.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/Interactor.cs @@ -4,32 +4,29 @@ using UnityEngine; using UnityEngine.InputSystem; namespace BigSock.Interact { - public class Interactor : MonoBehaviour - { - [SerializeField] private Transform _interactionPoint; - [SerializeField] private float _interactionpointRadius = 0.5f; - [SerializeField] private LayerMask _interactableMask; + public class Interactor : MonoBehaviour { + [SerializeField] private Transform _interactionPoint; + [SerializeField] private float _interactionpointRadius = 0.5f; + [SerializeField] private LayerMask _interactableMask; - private readonly Collider2D[] _colliders = new Collider2D[3]; - [SerializeField] private int _numFound; + private readonly Collider2D[] _colliders = new Collider2D[3]; + [SerializeField] private int _numFound; - private void Update() { - _numFound = Physics2D.OverlapCircleNonAlloc(_interactionPoint.position, _interactionpointRadius, _colliders, _interactableMask); + private void Update() { + _numFound = Physics2D.OverlapCircleNonAlloc(_interactionPoint.position, _interactionpointRadius, _colliders, _interactableMask); - if (_numFound > 0) - { - var interactable = _colliders[0].GetComponent<IInteractable>(); + if (_numFound > 0) { + var interactable = _colliders[0].GetComponent<IInteractable>(); - if (interactable != null && Keyboard.current.eKey.wasPressedThisFrame) - { - interactable.Interact(this); - } - } - } + if (interactable != null && Keyboard.current.eKey.wasPressedThisFrame) { + interactable.Interact(this); + } + } + } - private void OnDrawGizmos() { - Gizmos.color = Color.red; - Gizmos.DrawWireSphere(_interactionPoint.position, _interactionpointRadius); - } - } + private void OnDrawGizmos() { + Gizmos.color = Color.red; + Gizmos.DrawWireSphere(_interactionPoint.position, _interactionpointRadius); + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/InteractionSystem/Stairs.cs b/MrBigsock/Assets/Code/InteractionSystem/Stairs.cs index 01e072dd..5700dd8b 100644 --- a/MrBigsock/Assets/Code/InteractionSystem/Stairs.cs +++ b/MrBigsock/Assets/Code/InteractionSystem/Stairs.cs @@ -5,23 +5,19 @@ using System.Collections.Generic; using UnityEngine; -namespace BigSock.Interact -{ - public class Stairs : MonoBehaviour, IInteractable - { - [SerializeField] private string _prompt; +namespace BigSock.Interact { + public class Stairs : MonoBehaviour, IInteractable { + [SerializeField] private string _prompt; - public string InteractionPrompt => _prompt; - public bool stairs_touch = false; + public string InteractionPrompt => _prompt; + public bool stairs_touch = false; - public bool Interact(Interactor interactor) - { - if (!stairs_touch) - { - stairs_touch = true; - return true; - } - return false; - } - } + public bool Interact(Interactor interactor) { + if (!stairs_touch) { + stairs_touch = true; + return true; + } + return false; + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Map/AbstractMapGen.cs b/MrBigsock/Assets/Code/Map/AbstractMapGen.cs index 51fc8431..931739a2 100644 --- a/MrBigsock/Assets/Code/Map/AbstractMapGen.cs +++ b/MrBigsock/Assets/Code/Map/AbstractMapGen.cs @@ -4,34 +4,29 @@ using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; -namespace Bigsock -{ - public abstract class AbstractMapGen : MonoBehaviour - { - [SerializeField] - protected TilemapGenerator tilemapGenerator = null; - [SerializeField] - protected int RoomCount; +namespace Bigsock { + public abstract class AbstractMapGen : MonoBehaviour { + [SerializeField] + protected TilemapGenerator tilemapGenerator = null; + [SerializeField] + protected int RoomCount; - //Depricated - public void GenerateMap() - { - //tilemapVisualizer.Clear(); - RunProceduralGeneration(); - } + //Depricated + public void GenerateMap() { + //tilemapVisualizer.Clear(); + RunProceduralGeneration(); + } - public void Generate() - { - //tilemapGenerator.Clear(); - RunProceduralGeneration(); - } + public void Generate() { + //tilemapGenerator.Clear(); + RunProceduralGeneration(); + } - public void ClearMap() - { - tilemapGenerator.Clear(RoomCount, true); - //tilemapVisualizer.Clear(); - } + public void ClearMap() { + tilemapGenerator.Clear(RoomCount, true); + //tilemapVisualizer.Clear(); + } - public abstract void RunProceduralGeneration(); - } + public abstract void RunProceduralGeneration(); + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Map/Data/NeigbourSO.cs b/MrBigsock/Assets/Code/Map/Data/NeigbourSO.cs index 851a5d59..2c7bca71 100644 --- a/MrBigsock/Assets/Code/Map/Data/NeigbourSO.cs +++ b/MrBigsock/Assets/Code/Map/Data/NeigbourSO.cs @@ -2,16 +2,14 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -namespace Bigsock -{ - [CreateAssetMenu(fileName = "NeigbourParameters_", menuName = "PCG/NeigbourData")] - public class NeigbourSO : ScriptableObject - { - [Range(25f, 100f)] - public int width; - [Range(10f, 100f)] - public int height; - public int smoothCount; - public bool empty, edgesAreWalls; - } +namespace Bigsock { + [CreateAssetMenu(fileName = "NeigbourParameters_", menuName = "PCG/NeigbourData")] + public class NeigbourSO : ScriptableObject { + [Range(25f, 100f)] + public int width; + [Range(10f, 100f)] + public int height; + public int smoothCount; + public bool empty, edgesAreWalls; + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Map/Data/TileSetSO.cs b/MrBigsock/Assets/Code/Map/Data/TileSetSO.cs index 5577ef0a..2592a0b4 100644 --- a/MrBigsock/Assets/Code/Map/Data/TileSetSO.cs +++ b/MrBigsock/Assets/Code/Map/Data/TileSetSO.cs @@ -3,14 +3,12 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; -namespace Bigsock -{ - [CreateAssetMenu(fileName = "TileSetParam_", menuName = "PCG/TileSetData")] - public class TileSetSO : ScriptableObject - { - public TileBase wallLeftTile, wallRightTile; - public TileBase[] wallBottomTile, wallTopTile, wallCornerTile, floorTile, door, wallStatue; - [Range(10, 50)] - public int floorRandom = 10, wallRandom = 10; - } +namespace Bigsock { + [CreateAssetMenu(fileName = "TileSetParam_", menuName = "PCG/TileSetData")] + public class TileSetSO : ScriptableObject { + public TileBase wallLeftTile, wallRightTile; + public TileBase[] wallBottomTile, wallTopTile, wallCornerTile, floorTile, door, wallStatue; + [Range(10, 50)] + public int floorRandom = 10, wallRandom = 10; + } } diff --git a/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs b/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs index 5d253d85..9a8be398 100644 --- a/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs +++ b/MrBigsock/Assets/Code/Map/NeighbourMapGenerator.cs @@ -3,51 +3,44 @@ using System.Collections.Generic; using System.Security.Cryptography; using UnityEngine; -namespace Bigsock -{ - public class NeighbourMapGenerator : AbstractMapGen - { - [SerializeField] - protected NeigbourSO[] mapParam; - [SerializeField] NeigbourSO BossRoom; - - private static List<int[,]> roomList = new List<int[,]>(); - - public override void RunProceduralGeneration() - { - roomList.Clear(); - - for (int i = 0; i <= RoomCount - 1; i++) - { - int randomMap = Random.Range(0, mapParam.Length); - int[,] map = tilemapGenerator.GenerateArray(mapParam[randomMap].width, mapParam[randomMap].height, mapParam[randomMap].empty); - roomList.Add(map); - tilemapGenerator.RenderMap(roomList[i],i, false); - tilemapGenerator.SpawnEnemies(map, 4 + i, i); - - } - int[,] bossMap = tilemapGenerator.GenerateArray(BossRoom.width, BossRoom.height, BossRoom.empty); - roomList.Add(bossMap); - tilemapGenerator.RenderMap(roomList[roomList.Count - 1],roomList.Count - 1, true); - tilemapGenerator.SpawnBoss(bossMap, roomList.Count - 1); - tilemapGenerator.SpawnStairs(bossMap, roomList.Count - 1); - - tilemapGenerator.polyCollider(roomList[0], 0); - } - - public static int[,] GetRoomList(int i) - { - return roomList[i]; - } - - public static int GetRoomListCount() - { - return roomList.Count; - } - - public static void ClearRoomList() - { - roomList.Clear(); - } - } +namespace Bigsock { + public class NeighbourMapGenerator : AbstractMapGen { + [SerializeField] + protected NeigbourSO[] mapParam; + [SerializeField] NeigbourSO BossRoom; + + private static List<int[,]> roomList = new List<int[,]>(); + + public override void RunProceduralGeneration() { + roomList.Clear(); + + for (int i = 0; i <= RoomCount - 1; i++) { + int randomMap = Random.Range(0, mapParam.Length); + int[,] map = tilemapGenerator.GenerateArray(mapParam[randomMap].width, mapParam[randomMap].height, mapParam[randomMap].empty); + roomList.Add(map); + tilemapGenerator.RenderMap(roomList[i], i, false); + tilemapGenerator.SpawnEnemies(map, 4 + i, i); + + } + int[,] bossMap = tilemapGenerator.GenerateArray(BossRoom.width, BossRoom.height, BossRoom.empty); + roomList.Add(bossMap); + tilemapGenerator.RenderMap(roomList[roomList.Count - 1], roomList.Count - 1, true); + tilemapGenerator.SpawnBoss(bossMap, roomList.Count - 1); + tilemapGenerator.SpawnStairs(bossMap, roomList.Count - 1); + + tilemapGenerator.polyCollider(roomList[0], 0); + } + + public static int[,] GetRoomList(int i) { + return roomList[i]; + } + + public static int GetRoomListCount() { + return roomList.Count; + } + + public static void ClearRoomList() { + roomList.Clear(); + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Map/TilemapGenerator.cs b/MrBigsock/Assets/Code/Map/TilemapGenerator.cs index 2cf2f94a..06f7f31e 100644 --- a/MrBigsock/Assets/Code/Map/TilemapGenerator.cs +++ b/MrBigsock/Assets/Code/Map/TilemapGenerator.cs @@ -5,366 +5,316 @@ using Unity.VisualScripting; using UnityEngine; using UnityEngine.Tilemaps; -namespace Bigsock -{ - public class TilemapGenerator : MonoBehaviour - { - [SerializeField] Tilemap[] FloorTilemap, WallBottom, WallTop, WallSide; - [SerializeField] TileSetSO tileSetSO; - [SerializeField] PolygonCollider2D polygonCollider; - [SerializeField] GameObject Door; - [SerializeField] GameObject[] Enemy; - [SerializeField] GameObject Boss; - [SerializeField] GameObject Stairs; - [SerializeField] GameObject Chest; - private int z_value = 0; - private static int roomID = 0; - - static List<Vector3Int> DoorLocations = new List<Vector3Int>(); - //static List<Vector2> MapBoudary = new List<Vector2>(); - static List<List<Vector2>> MapBoundaryList = new List<List<Vector2>>(); - - /* - Makes an array with numbers, where each number decides what type of tile will be on what spot on the floor*/ - public int[,] GenerateArray(int width, int height, bool empty) - { - int[,] map = new int[width, height]; - for (int x = 0; x < map.GetUpperBound(0); x++) - { - for (int y = 0; y < map.GetUpperBound(1); y++) - { - int fill = Random.Range(0, 100); - int num; - //Random number from how many tiles possible for floor, not basic - if (fill < tileSetSO.floorRandom) num = Random.Range(1, tileSetSO.floorTile.Length - 1); - else num = 0; //Basic floor - - map[x, y] = num; - } - } - return map; - } - - public void RenderMap(int[,] map, int roomNr, bool LastRoom) - { - int doorLocation = Random.Range(0, map.GetUpperBound(0) - 4); - //int doorLocation = Random.Range(0, 1); - bool doorInRoom = false; - int doorTop = Random.Range(0, 2); // 0 = bottom, 1 = top - int topWallVariable; - - //Clear the map - Clear(roomNr, false); - - //Loop thorugh width : floor - for (int x = 0; x < map.GetUpperBound(0); x++) - { - for (int y = 0; y < map.GetUpperBound(1); y++) - { - FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.floorTile[map[x,y]]); // 1 = tile, 0 = no tile - } - } - - //Walls - for (int x = 0; x <= map.GetUpperBound(0)-1 ; x++) - { - //Left wall - if(x == 0) - { - WallSide[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallLeftTile); - WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallBottomTile[0]); - for (int y = 1; y < (map.GetUpperBound(1) + 1); y++) WallSide[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallLeftTile); - WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1) +1, z_value), tileSetSO.wallTopTile[0]); - } - //Right wall - if (x == (map.GetUpperBound(0)- 1)){ - WallSide[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallRightTile); - WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallCornerTile[1]); - for (int y = 0; y < (map.GetUpperBound(1) + 1); y++) WallSide[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallRightTile); - WallTop[roomNr].SetTile(new Vector3Int(x, (map.GetUpperBound(1) + 1), z_value), tileSetSO.wallCornerTile[0]); - } - - //Check for start of wall - if (x != map.GetLowerBound(0) && x != (map.GetUpperBound(0) - 1)) - { - //Bottom wall - WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallBottomTile[0]); - //Top wall - WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1) + 1, z_value), tileSetSO.wallTopTile[0]); - } - - //Bottom wall middle part - if (Random.Range(0, 100) < tileSetSO.wallRandom) - { - WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1) - 1, z_value), tileSetSO.wallBottomTile[Random.Range(2, - tileSetSO.wallBottomTile.GetUpperBound(0))]); - } - else WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1) - 1, z_value), tileSetSO.wallBottomTile[1]); - - //Top wall middle part - if (Random.Range(0,100) < tileSetSO.wallRandom) - { - //Check that it is not near a corner or the start of the door location - if(x != map.GetUpperBound(0) - 1 && x != map.GetLowerBound(0) && x != doorLocation) - { - topWallVariable = Random.Range(2, tileSetSO.wallTopTile.GetUpperBound(0)); - if (topWallVariable == 2) - { - ChangeFloorTile(map, x, map.GetUpperBound(1) - 1, roomNr); - ChangeTopTile(map, x, map.GetUpperBound(1) + 1, roomNr); - } - } - //Everythin that is not the statue - else topWallVariable = Random.Range(3, tileSetSO.wallTopTile.GetUpperBound(0)); - - WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[topWallVariable]); - } - else WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); //Middle part of top wall - - int fast = 0; - //Check for where the door will be located : when there is no door - if (x == doorLocation && !doorInRoom && !LastRoom) - { - bool doorPlaced = false; - for (int x1 = 0; x1 < 4; x1++) - { - //Makes the door on the bottom wall - if (doorTop == 0) - { - //Door - if (!doorPlaced) - { - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1), z_value), tileSetSO.door[x1]); - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1) - 1, z_value), tileSetSO.door[x1 + 4]); - //Door prefab - Instantiate(Door, new Vector3(WallBottom[roomNr].transform.position.x + x + 2, WallBottom[roomNr].transform.position.y, - z_value), Quaternion.identity); - DoorLocations.Add(new Vector3Int((int)WallBottom[roomNr].transform.position.x + x + 2, - (int)WallBottom[roomNr].transform.position.y, z_value)); - FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 1, map.GetLowerBound(1) - 1, z_value), tileSetSO.floorTile[0]); - FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 2, map.GetLowerBound(1) - 1, z_value), tileSetSO.floorTile[0]); - doorPlaced = true; - } - if(x1 == 3) - { - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1), z_value), tileSetSO.door[x1]); - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1) - 1, z_value), tileSetSO.door[x1 + 4]); - } - - if(x1 > 0 && x1 < 3) WallBottom[roomNr].SetTile(new Vector3Int(x + x1,map.GetLowerBound(1) + 1, z_value), - tileSetSO.door[x1 + 7]); //Makes top of door - - //Top Wall opposite of the door : Wall - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.wallTopTile[0]); - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); - } - //Makes the door on the top wall - else - { - if (!doorPlaced) - { - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.door[x1]); - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.door[x1 + 4]); - //Door prefab - Instantiate(Door, new Vector3(WallTop[roomNr].transform.position.x + x + 2, - WallTop[roomNr].transform.position.y + map.GetUpperBound(1) + 1, z_value), Quaternion.identity); - DoorLocations.Add(new Vector3Int((int)WallTop[roomNr].transform.position.x + x + 2, - (int)WallTop[roomNr].transform.position.y, z_value)); - FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 1, map.GetUpperBound(1), z_value), tileSetSO.floorTile[0]); - FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 2, map.GetUpperBound(1), z_value), tileSetSO.floorTile[0]); - doorPlaced = true; - } - if (x1 == 3) - { - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.door[x1]); - WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.door[x1 + 4]); - } - - if (x1 > 0 && x1 < 3) WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 2, z_value), - tileSetSO.door[x1 + 7]); //Makes top of door - - //Bottom Wall opposite of the door : Wall - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0), z_value), tileSetSO.wallBottomTile[0]); - WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0) - 1, z_value), tileSetSO.wallBottomTile[1]); - } - } - fast++; - doorInRoom = true; - x += 3; //Jump x over the door location - } - else if(fast == 0 && LastRoom) - { - DoorLocations.Add(new Vector3Int((int)WallTop[roomNr].transform.position.x + x + 2, - (int)WallTop[roomNr].transform.position.y, z_value)); - fast++; - } - } - spawnChest(map, roomNr); - SetMapBoundary(map, roomNr); - } - - - /* - Gives out the corner points of the room to know how to set the boundries in the world */ - public void SetMapBoundary(int[,] map, int roomNr) - { - List<Vector2> MapBoudary = new List<Vector2>(); - MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); - MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); - MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); - MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); - MapBoundaryList.Add(MapBoudary); - } - - /* - Returns the spesific MapBoundry from a list*/ - public static List<Vector2> GetRoomBoundary(int i) - { - return MapBoundaryList[i]; - } - - /* - Returns the ID of the next room*/ - public static int NextRoom() - { - return roomID++; - } - - public static void SetRoomIDZero() { - roomID = 1; - } - - public static void resetMaps() - { - DoorLocations.Clear(); - MapBoundaryList.Clear(); - } - - /* - Returns the ID of the previous room*/ - public static int LastRoom() - { - return roomID--; - } - - /* - Spawns enemies inside the boundry of a spesific room by giving it the space the floor ocopay*/ - public void SpawnEnemies(int[,] map, int enemies, int roomNr) - { - foreach (var item in Enemy) - { - item.tag = roomNr.ToString(); - } - - - for (int i = 0; i < enemies; i++) - { - int enemyRandom = Random.Range(0, Enemy.Length); - int randomLocation_x = Random.Range(1, map.GetUpperBound(0) - 1); - if (randomLocation_x == DoorLocations[roomNr].x) randomLocation_x += 1; - int randomLocation_y = Random.Range(map.GetLowerBound(1) + 2, map.GetUpperBound(1) - 1); - if (randomLocation_x == DoorLocations[roomNr].y) randomLocation_y += 1; - Instantiate(Enemy[enemyRandom], new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + randomLocation_x, - (int)FloorTilemap[roomNr].transform.position.y + randomLocation_y, 0), Quaternion.identity); - } - } - - public void SpawnBoss(int[,] bossRoom, int roomNr) - { - Boss.tag = "Boss"; - Instantiate(Boss, new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + bossRoom.GetUpperBound(0)/2, - (int)FloorTilemap[roomNr].transform.position.y + bossRoom.GetUpperBound(1) / 2, 0), Quaternion.identity); - } - - /* - Sets new points for where the polygon collider for a room is goint to be set*/ - public void polyCollider(int[,] map, int roomNr) - { - polygonCollider.pathCount = 1; - - List<Vector2> vectors = new List<Vector2>(); - - vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); - vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); - vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); - vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), - FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); - - polygonCollider.SetPath(0, vectors); - } - - public static Vector3Int DoorLocaitonTransport(int door) - { - return new Vector3Int(DoorLocations[door].x + 1, DoorLocations[door].y + 3, DoorLocations[door].z); - } - - /* - Changes the wall on the top of the map to a different tile*/ - private void ChangeTopTile(int[,] map, int x, int y, int roomNr) - { - WallTop[roomNr].SetTile(new Vector3Int(x, y, z_value), null); - WallTop[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallStatue[0]); - } - - public void ChangeFloorTile(int[,] map, int x, int y, int roomNr) - { - FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), null); - FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallStatue[1]); - } - - //Takes in our map and tilemap, setting null tiles where needed - public static void UpdateMap(int[,] map, Tilemap tilemap) - { - for (int x = 0; x < map.GetUpperBound(0); x++) - { - for (int y = 0; y < map.GetUpperBound(1); y++) - { - if (map[x, y] == 0) tilemap.SetTile(new Vector3Int(x, y, 0), null); - } - } - } - - //Removes current paint on tiles - public void Clear(int roomNr, bool all) - { - if (all) - { - for (int i = 0; i < roomNr; i++) - { - FloorTilemap[i].ClearAllTiles(); - WallBottom[i].ClearAllTiles(); - WallSide[i].ClearAllTiles(); - WallTop[i].ClearAllTiles(); - } - } - else - { - FloorTilemap[roomNr].ClearAllTiles(); - WallBottom[roomNr].ClearAllTiles(); - WallSide[roomNr].ClearAllTiles(); - WallTop[roomNr].ClearAllTiles(); - } - } - - public void SpawnStairs(int[,] bossRoom, int roomNr) - { - Instantiate(Stairs, new Vector3(FloorTilemap[roomNr].transform.position.x + bossRoom.GetUpperBound(0) / 2 + 0.5f, - FloorTilemap[roomNr].transform.position.y + bossRoom.GetUpperBound(1) - 3 + 0.5f, 0), Quaternion.identity); - } - - //Spawns a chest in the middle of the room - public void spawnChest(int[,] room, int roomNr) - { - Chest.tag = "Chest"; - Instantiate(Chest, new Vector3(FloorTilemap[roomNr].transform.position.x + room.GetUpperBound(0) / 2, - FloorTilemap[roomNr].transform.position.y + room.GetUpperBound(1) / 2, 0), Quaternion.identity); - } - } +namespace Bigsock { + public class TilemapGenerator : MonoBehaviour { + [SerializeField] Tilemap[] FloorTilemap, WallBottom, WallTop, WallSide; + [SerializeField] TileSetSO tileSetSO; + [SerializeField] PolygonCollider2D polygonCollider; + [SerializeField] GameObject Door; + [SerializeField] GameObject[] Enemy; + [SerializeField] GameObject Boss; + [SerializeField] GameObject Stairs; + [SerializeField] GameObject Chest; + private int z_value = 0; + private static int roomID = 0; + + static List<Vector3Int> DoorLocations = new List<Vector3Int>(); + //static List<Vector2> MapBoudary = new List<Vector2>(); + static List<List<Vector2>> MapBoundaryList = new List<List<Vector2>>(); + + /* + Makes an array with numbers, where each number decides what type of tile will be on what spot on the floor*/ + public int[,] GenerateArray(int width, int height, bool empty) { + int[,] map = new int[width, height]; + for (int x = 0; x < map.GetUpperBound(0); x++) { + for (int y = 0; y < map.GetUpperBound(1); y++) { + int fill = Random.Range(0, 100); + int num; + //Random number from how many tiles possible for floor, not basic + if (fill < tileSetSO.floorRandom) num = Random.Range(1, tileSetSO.floorTile.Length - 1); + else num = 0; //Basic floor + + map[x, y] = num; + } + } + return map; + } + + public void RenderMap(int[,] map, int roomNr, bool LastRoom) { + int doorLocation = Random.Range(0, map.GetUpperBound(0) - 4); + //int doorLocation = Random.Range(0, 1); + bool doorInRoom = false; + int doorTop = Random.Range(0, 2); // 0 = bottom, 1 = top + int topWallVariable; + + //Clear the map + Clear(roomNr, false); + + //Loop thorugh width : floor + for (int x = 0; x < map.GetUpperBound(0); x++) { + for (int y = 0; y < map.GetUpperBound(1); y++) { + FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.floorTile[map[x, y]]); // 1 = tile, 0 = no tile + } + } + + //Walls + for (int x = 0; x <= map.GetUpperBound(0) - 1; x++) { + //Left wall + if (x == 0) { + WallSide[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallLeftTile); + WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallBottomTile[0]); + for (int y = 1; y < (map.GetUpperBound(1) + 1); y++) WallSide[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallLeftTile); + WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1) + 1, z_value), tileSetSO.wallTopTile[0]); + } + //Right wall + if (x == (map.GetUpperBound(0) - 1)) { + WallSide[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallRightTile); + WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallCornerTile[1]); + for (int y = 0; y < (map.GetUpperBound(1) + 1); y++) WallSide[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallRightTile); + WallTop[roomNr].SetTile(new Vector3Int(x, (map.GetUpperBound(1) + 1), z_value), tileSetSO.wallCornerTile[0]); + } + + //Check for start of wall + if (x != map.GetLowerBound(0) && x != (map.GetUpperBound(0) - 1)) { + //Bottom wall + WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1), z_value), tileSetSO.wallBottomTile[0]); + //Top wall + WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1) + 1, z_value), tileSetSO.wallTopTile[0]); + } + + //Bottom wall middle part + if (Random.Range(0, 100) < tileSetSO.wallRandom) { + WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1) - 1, z_value), tileSetSO.wallBottomTile[Random.Range(2, + tileSetSO.wallBottomTile.GetUpperBound(0))]); + } else WallBottom[roomNr].SetTile(new Vector3Int(x, map.GetLowerBound(1) - 1, z_value), tileSetSO.wallBottomTile[1]); + + //Top wall middle part + if (Random.Range(0, 100) < tileSetSO.wallRandom) { + //Check that it is not near a corner or the start of the door location + if (x != map.GetUpperBound(0) - 1 && x != map.GetLowerBound(0) && x != doorLocation) { + topWallVariable = Random.Range(2, tileSetSO.wallTopTile.GetUpperBound(0)); + if (topWallVariable == 2) { + ChangeFloorTile(map, x, map.GetUpperBound(1) - 1, roomNr); + ChangeTopTile(map, x, map.GetUpperBound(1) + 1, roomNr); + } + } + //Everythin that is not the statue + else topWallVariable = Random.Range(3, tileSetSO.wallTopTile.GetUpperBound(0)); + + WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[topWallVariable]); + } else WallTop[roomNr].SetTile(new Vector3Int(x, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); //Middle part of top wall + + int fast = 0; + //Check for where the door will be located : when there is no door + if (x == doorLocation && !doorInRoom && !LastRoom) { + bool doorPlaced = false; + for (int x1 = 0; x1 < 4; x1++) { + //Makes the door on the bottom wall + if (doorTop == 0) { + //Door + if (!doorPlaced) { + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1), z_value), tileSetSO.door[x1]); + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1) - 1, z_value), tileSetSO.door[x1 + 4]); + //Door prefab + Instantiate(Door, new Vector3(WallBottom[roomNr].transform.position.x + x + 2, WallBottom[roomNr].transform.position.y, + z_value), Quaternion.identity); + DoorLocations.Add(new Vector3Int((int)WallBottom[roomNr].transform.position.x + x + 2, + (int)WallBottom[roomNr].transform.position.y, z_value)); + FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 1, map.GetLowerBound(1) - 1, z_value), tileSetSO.floorTile[0]); + FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 2, map.GetLowerBound(1) - 1, z_value), tileSetSO.floorTile[0]); + doorPlaced = true; + } + if (x1 == 3) { + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1), z_value), tileSetSO.door[x1]); + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1) - 1, z_value), tileSetSO.door[x1 + 4]); + } + + if (x1 > 0 && x1 < 3) WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(1) + 1, z_value), + tileSetSO.door[x1 + 7]); //Makes top of door + + //Top Wall opposite of the door : Wall + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.wallTopTile[0]); + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.wallTopTile[1]); + } + //Makes the door on the top wall + else { + if (!doorPlaced) { + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.door[x1]); + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.door[x1 + 4]); + //Door prefab + Instantiate(Door, new Vector3(WallTop[roomNr].transform.position.x + x + 2, + WallTop[roomNr].transform.position.y + map.GetUpperBound(1) + 1, z_value), Quaternion.identity); + DoorLocations.Add(new Vector3Int((int)WallTop[roomNr].transform.position.x + x + 2, + (int)WallTop[roomNr].transform.position.y, z_value)); + FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 1, map.GetUpperBound(1), z_value), tileSetSO.floorTile[0]); + FloorTilemap[roomNr].SetTile(new Vector3Int(x + x1 + 2, map.GetUpperBound(1), z_value), tileSetSO.floorTile[0]); + doorPlaced = true; + } + if (x1 == 3) { + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 1, z_value), tileSetSO.door[x1]); + WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1), z_value), tileSetSO.door[x1 + 4]); + } + + if (x1 > 0 && x1 < 3) WallTop[roomNr].SetTile(new Vector3Int(x + x1, map.GetUpperBound(1) + 2, z_value), + tileSetSO.door[x1 + 7]); //Makes top of door + + //Bottom Wall opposite of the door : Wall + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0), z_value), tileSetSO.wallBottomTile[0]); + WallBottom[roomNr].SetTile(new Vector3Int(x + x1, map.GetLowerBound(0) - 1, z_value), tileSetSO.wallBottomTile[1]); + } + } + fast++; + doorInRoom = true; + x += 3; //Jump x over the door location + } else if (fast == 0 && LastRoom) { + DoorLocations.Add(new Vector3Int((int)WallTop[roomNr].transform.position.x + x + 2, + (int)WallTop[roomNr].transform.position.y, z_value)); + fast++; + } + } + spawnChest(map, roomNr); + SetMapBoundary(map, roomNr); + } + + + /* + Gives out the corner points of the room to know how to set the boundries in the world */ + public void SetMapBoundary(int[,] map, int roomNr) { + List<Vector2> MapBoudary = new List<Vector2>(); + MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); + MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); + MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); + MapBoudary.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); + MapBoundaryList.Add(MapBoudary); + } + + /* + Returns the spesific MapBoundry from a list*/ + public static List<Vector2> GetRoomBoundary(int i) { + return MapBoundaryList[i]; + } + + /* + Returns the ID of the next room*/ + public static int NextRoom() { + return roomID++; + } + + public static void SetRoomIDZero() { + roomID = 1; + } + + public static void resetMaps() { + DoorLocations.Clear(); + MapBoundaryList.Clear(); + } + + /* + Returns the ID of the previous room*/ + public static int LastRoom() { + return roomID--; + } + + /* + Spawns enemies inside the boundry of a spesific room by giving it the space the floor ocopay*/ + public void SpawnEnemies(int[,] map, int enemies, int roomNr) { + foreach (var item in Enemy) { + item.tag = roomNr.ToString(); + } + + + for (int i = 0; i < enemies; i++) { + int enemyRandom = Random.Range(0, Enemy.Length); + int randomLocation_x = Random.Range(1, map.GetUpperBound(0) - 1); + if (randomLocation_x == DoorLocations[roomNr].x) randomLocation_x += 1; + int randomLocation_y = Random.Range(map.GetLowerBound(1) + 2, map.GetUpperBound(1) - 1); + if (randomLocation_x == DoorLocations[roomNr].y) randomLocation_y += 1; + Instantiate(Enemy[enemyRandom], new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + randomLocation_x, + (int)FloorTilemap[roomNr].transform.position.y + randomLocation_y, 0), Quaternion.identity); + } + } + + public void SpawnBoss(int[,] bossRoom, int roomNr) { + Boss.tag = "Boss"; + Instantiate(Boss, new Vector3Int((int)FloorTilemap[roomNr].transform.position.x + bossRoom.GetUpperBound(0) / 2, + (int)FloorTilemap[roomNr].transform.position.y + bossRoom.GetUpperBound(1) / 2, 0), Quaternion.identity); + } + + /* + Sets new points for where the polygon collider for a room is goint to be set*/ + public void polyCollider(int[,] map, int roomNr) { + polygonCollider.pathCount = 1; + + List<Vector2> vectors = new List<Vector2>(); + + vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); + vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetLowerBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); + vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetUpperBound(1) + 1.2f)); + vectors.Add(new Vector2(FloorTilemap[roomNr].transform.position.x + map.GetUpperBound(0), + FloorTilemap[roomNr].transform.position.y + map.GetLowerBound(1) - 1)); + + polygonCollider.SetPath(0, vectors); + } + + public static Vector3Int DoorLocaitonTransport(int door) { + return new Vector3Int(DoorLocations[door].x + 1, DoorLocations[door].y + 3, DoorLocations[door].z); + } + + /* + Changes the wall on the top of the map to a different tile*/ + private void ChangeTopTile(int[,] map, int x, int y, int roomNr) { + WallTop[roomNr].SetTile(new Vector3Int(x, y, z_value), null); + WallTop[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallStatue[0]); + } + + public void ChangeFloorTile(int[,] map, int x, int y, int roomNr) { + FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), null); + FloorTilemap[roomNr].SetTile(new Vector3Int(x, y, z_value), tileSetSO.wallStatue[1]); + } + + //Takes in our map and tilemap, setting null tiles where needed + public static void UpdateMap(int[,] map, Tilemap tilemap) { + for (int x = 0; x < map.GetUpperBound(0); x++) { + for (int y = 0; y < map.GetUpperBound(1); y++) { + if (map[x, y] == 0) tilemap.SetTile(new Vector3Int(x, y, 0), null); + } + } + } + + //Removes current paint on tiles + public void Clear(int roomNr, bool all) { + if (all) { + for (int i = 0; i < roomNr; i++) { + FloorTilemap[i].ClearAllTiles(); + WallBottom[i].ClearAllTiles(); + WallSide[i].ClearAllTiles(); + WallTop[i].ClearAllTiles(); + } + } else { + FloorTilemap[roomNr].ClearAllTiles(); + WallBottom[roomNr].ClearAllTiles(); + WallSide[roomNr].ClearAllTiles(); + WallTop[roomNr].ClearAllTiles(); + } + } + + public void SpawnStairs(int[,] bossRoom, int roomNr) { + Instantiate(Stairs, new Vector3(FloorTilemap[roomNr].transform.position.x + bossRoom.GetUpperBound(0) / 2 + 0.5f, + FloorTilemap[roomNr].transform.position.y + bossRoom.GetUpperBound(1) - 3 + 0.5f, 0), Quaternion.identity); + } + + //Spawns a chest in the middle of the room + public void spawnChest(int[,] room, int roomNr) { + Chest.tag = "Chest"; + Instantiate(Chest, new Vector3(FloorTilemap[roomNr].transform.position.x + room.GetUpperBound(0) / 2, + FloorTilemap[roomNr].transform.position.y + room.GetUpperBound(1) / 2, 0), Quaternion.identity); + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index e17bf5c1..68f88e75 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -13,8 +13,7 @@ using BigSock.Service; namespace BigSock { // Takes and handles input and movement for a player character - public partial class PlayerController : Character - { + public partial class PlayerController : Character { public const int SKILL_POINTS_PR_LVL = 3; // Skill points to gain pr level up. public const int SKILL_POINTS_START = 0; // Skill points to start with. @@ -23,11 +22,11 @@ namespace BigSock { public const int ABILITY_COUNT = 4; // Number of abilities. public UtilBar utilBar; - + public float collisionOffset = 0.05f; public ContactFilter2D movementFilter; - + public GameObject attack; Vector2 movementInput; @@ -49,7 +48,7 @@ namespace BigSock { private List<List<KeyCode>> _keyMapping = new List<List<KeyCode>> { new List<KeyCode>{KeyCode.Space, KeyCode.Mouse0}, new List<KeyCode>{KeyCode.Z}, - new List<KeyCode>{KeyCode.C, KeyCode.Mouse1}, + new List<KeyCode>{KeyCode.C, KeyCode.Mouse1}, new List<KeyCode>{KeyCode.LeftShift}, }; @@ -61,8 +60,7 @@ namespace BigSock { public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now; - public PlayerController() - { + public PlayerController() { IFrameDuration = new TimeSpan(0, 0, 0, 0, 250); //TryPickUpItem(ItemService.SINGLETON.Get(201)); //TryPickUpItem(ItemService.SINGLETON.Get(105)); @@ -76,9 +74,9 @@ namespace BigSock { protected void SetAbilities(List<IAbility> neo) { var res = new List<AbilityEntity>(); - for(int i = 0; i < neo.Count; ++i) + for (int i = 0; i < neo.Count; ++i) res.Add(new AbilityEntity(neo[i], i, _keyMapping[i])); - + _abilities = res; // Update the UI to reflect the new abilities. @@ -89,8 +87,7 @@ namespace BigSock { } // Start is called before the first frame update - protected override void Start() - { + protected override void Start() { base.Start(); @@ -135,41 +132,41 @@ namespace BigSock { } - + private void FixedUpdate() { - if(canMove) { - // If movement input is not 0, try to move - if(movementInput != Vector2.zero){ - - bool success = TryMove(movementInput); - - if(!success) { - success = TryMove(new Vector2(movementInput.x, 0)); - } + if (canMove) { + // If movement input is not 0, try to move + if (movementInput != Vector2.zero) { - if(!success) { - success = TryMove(new Vector2(0, movementInput.y)); - } - - animator.SetBool("isMoving", success); - } else { - animator.SetBool("isMoving", false); + bool success = TryMove(movementInput); + + if (!success) { + success = TryMove(new Vector2(movementInput.x, 0)); } - // Set direction of sprite to movement direction - var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); - var pos = transform.position; - var temp = (mouse - pos); - //temp.z = 0; - //direction = temp.normalized; - - if(temp.x < 0) { - spriteRenderer.flipX = true; - } else if (temp.x > 0) { - spriteRenderer.flipX = false; + if (!success) { + success = TryMove(new Vector2(0, movementInput.y)); } + + animator.SetBool("isMoving", success); + } else { + animator.SetBool("isMoving", false); + } + + // Set direction of sprite to movement direction + var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); + var pos = transform.position; + var temp = (mouse - pos); + //temp.z = 0; + //direction = temp.normalized; + + if (temp.x < 0) { + spriteRenderer.flipX = true; + } else if (temp.x > 0) { + spriteRenderer.flipX = false; + } } - + } @@ -184,8 +181,8 @@ namespace BigSock { var par = GetAbilityParam(Camera.main.ScreenToWorldPoint(Input.mousePosition)); // Check input on each key, stop if one was a success. - foreach(var key in ability.Keys) - if(CheckAbilityInput(key, ability)) break; + foreach (var key in ability.Keys) + if (CheckAbilityInput(key, ability)) break; // Update the UI. AbilityUI?.SetCharge(ability.Index, ability.ChargePercent); @@ -199,7 +196,7 @@ namespace BigSock { switch (ability.Ability.FireType) { // Standard: Press to fire. case FireType.Standard: - if (Input.GetKeyDown(key)) { + if (Input.GetKeyDown(key)) { ability.Ability.Use(par); return true; } @@ -214,14 +211,14 @@ namespace BigSock { // Charge: Fire when let go. case FireType.Charge: // If pressed down: Store start time. - if(Input.GetKeyDown(key)) { + if (Input.GetKeyDown(key)) { // Only start charging if the ability is ready. - if(ability.Ability.Ready) ability.ChargeStarted = Time.time; + if (ability.Ability.Ready) ability.ChargeStarted = Time.time; return true; } // If let go: Activate - else if(Input.GetKeyUp(key)) { - if(ability.IsCharging) { + else if (Input.GetKeyUp(key)) { + if (ability.IsCharging) { par.ChargeTime = ability.ChargeTime; var t = ability.Ability.Use(par); if (!t) { @@ -240,8 +237,7 @@ namespace BigSock { } - private void Update() - { + private void Update() { // Regenerate mana & stamina. Regenerate(); @@ -259,7 +255,7 @@ namespace BigSock { //} // Check and update all abilities. - foreach(var ability in _abilities) { + foreach (var ability in _abilities) { CheckAbilityInput(ability); } // Check ability 1. @@ -290,19 +286,16 @@ namespace BigSock { //!! Code for testing the new item stuff. - if (Input.GetKeyDown(KeyCode.M)) - { + if (Input.GetKeyDown(KeyCode.M)) { var item = ItemService.SINGLETON.GetRandom(); // new ItemRunningShoes(); TryPickUpItem(item); } // Code for opening the menu. - if (Input.GetKeyDown(KeyCode.I)) - { + if (Input.GetKeyDown(KeyCode.I)) { GameObject canvas = GameObject.Find("Canvas"); GameObject oldPlayerMenu = GameObject.Find("PlayerMenu(Clone)"); - if (canvas != null && oldPlayerMenu == null) - { + if (canvas != null && oldPlayerMenu == null) { var playerMenu = PrefabService.SINGLETON.Instance("UI/PlayerMenu", canvas.transform); var invMen = playerMenu.transform.GetChild(1).transform.GetChild(0).GetComponent<InventoryPanel>(); var statMen = playerMenu.transform.GetChild(1).transform.GetChild(1).GetComponent<StatPanel>(); @@ -312,12 +305,10 @@ namespace BigSock { } // Code for opening control scheme - if (Input.GetKeyDown(KeyCode.L)) - { + if (Input.GetKeyDown(KeyCode.L)) { GameObject canvas = GameObject.Find("Canvas"); GameObject oldControlScheme = GameObject.Find("ControlScheme(Clone)"); - if (canvas != null && oldControlScheme == null) - { + if (canvas != null && oldControlScheme == null) { var controlScheme = PrefabService.SINGLETON.Instance("UI/ControlScheme", canvas.transform); } } @@ -342,7 +333,7 @@ namespace BigSock { ?.WithStamina(maxValue: (int)Stats.MaxStamina); } - + /* Regenerates mana and stamina. */ @@ -353,50 +344,50 @@ namespace BigSock { } private bool TryMove_OLD(Vector2 direction) { - if(direction != Vector2.zero) { - // Check for potential collisions - int count = rb.Cast( - direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions - movementFilter, // The settings that determine where a collision can occur on such as layers to collide with - castCollisions, // List of collisions to store the found collisions into after the Cast is finished - (float) MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset - - if(count == 0){ - rb.MovePosition(rb.position + direction * (float) MovementSpeed * Time.fixedDeltaTime); - return true; - } else { - return false; - } + if (direction != Vector2.zero) { + // Check for potential collisions + int count = rb.Cast( + direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions + movementFilter, // The settings that determine where a collision can occur on such as layers to collide with + castCollisions, // List of collisions to store the found collisions into after the Cast is finished + (float)MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset + + if (count == 0) { + rb.MovePosition(rb.position + direction * (float)MovementSpeed * Time.fixedDeltaTime); + return true; } else { - // Can't move if there's no direction to move in - return false; + return false; } - - // + } else { + // Can't move if there's no direction to move in + return false; + } + + // } void OnMove(InputValue movementValue) { - movementInput = movementValue.Get<Vector2>(); + movementInput = movementValue.Get<Vector2>(); } public void LockMovement() { - canMove = false; + canMove = false; } public void UnlockMovement() { - canMove = true; + canMove = true; } /* Method for what to do when the character takes damage. */ - protected override void AfterDamage(IAttackStats attack) { + protected override void AfterDamage(IAttackStats attack) { base.AfterDamage(attack); utilBar?.WithHealth(Convert.ToInt32(HP)); } - protected override void AfterHeal() { + protected override void AfterHeal() { utilBar?.WithHealth(Convert.ToInt32(HP)); } @@ -412,8 +403,8 @@ namespace BigSock { */ private void CheckXp() { // If the character has leveled up. - if(xp > maxXp) { - level += 1; + if (xp > maxXp) { + level += 1; xp -= maxXp; maxXp = (level + 1) * 100; utilBar?.WithXP(maxValue: (int)maxXp); @@ -427,13 +418,11 @@ namespace BigSock { */ } - public void OnDestroy() - { + public void OnDestroy() { Time.timeScale = 0; GameObject canvas = GameObject.Find("Canvas"); - - if (canvas != null) - { + + if (canvas != null) { PrefabService.SINGLETON.Instance("UI/EndScreen", canvas.transform); } } @@ -444,7 +433,7 @@ namespace BigSock { Skills related code. */ public partial class PlayerController { - + /* The number of skill points the user has at their disposal. @@ -459,13 +448,13 @@ namespace BigSock { /* The maximum amount of points the user can spend on each skill. */ - public Skills MaxSkills { get; set; } = new Skills{ - HP = 10, - SP = 10, - MP = 10, - Damage = 10, - Speed = 10, - Luck = 10, + public Skills MaxSkills { get; set; } = new Skills { + HP = 10, + SP = 10, + MP = 10, + Damage = 10, + Speed = 10, + Luck = 10, Concentration = 10, }; diff --git a/MrBigsock/Assets/Code/Slime/SlimeController.cs b/MrBigsock/Assets/Code/Slime/SlimeController.cs index b12f7086..3c820d53 100644 --- a/MrBigsock/Assets/Code/Slime/SlimeController.cs +++ b/MrBigsock/Assets/Code/Slime/SlimeController.cs @@ -32,7 +32,7 @@ namespace BigSock { The state the slime is in. */ public SlimeState State { get; protected set; } = SlimeState.Idle; - + /* The location of the target when charging started. @@ -43,7 +43,7 @@ namespace BigSock { The next time the slime can change its state. */ public DateTime NextTimeStateCanChange { get; private set; } = DateTime.Now; - + /* Minimum time the slime should idle before it can charge. */ @@ -62,7 +62,7 @@ namespace BigSock { */ public double LeapForce => MovementSpeed * 10; - + //void Start() { // rb = GetComponent<Rigidbody2D>(); // m_Animator = gameObject.GetComponent<Animator>(); @@ -81,9 +81,9 @@ namespace BigSock { protected override void Update() { - if(State == SlimeState.Idle) { + if (State == SlimeState.Idle) { // If it has a target and has idled long enough. - if(target != null && DateTime.Now >= NextTimeStateCanChange) { + if (target != null && DateTime.Now >= NextTimeStateCanChange) { // Store target location. TargetLocation = target.position; @@ -92,11 +92,9 @@ namespace BigSock { NextTimeStateCanChange = DateTime.Now + CHARGE_WAIT_TIME; m_Animator.SetTrigger("idle"); } - } - - else if(State == SlimeState.Charging) { + } else if (State == SlimeState.Charging) { // If it has charged long enough. - if(DateTime.Now >= NextTimeStateCanChange) { + if (DateTime.Now >= NextTimeStateCanChange) { // Set momentum var pos = TargetLocation;//target.position; var temp = (pos - rb.transform.position); @@ -109,11 +107,9 @@ namespace BigSock { State = SlimeState.Leaping; NextTimeStateCanChange = DateTime.Now + LEAP_WAIT_TIME; } - } - - else if(State == SlimeState.Leaping) { + } else if (State == SlimeState.Leaping) { // If it has charged long enough. - if(DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { + if (DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { // Update the state. State = SlimeState.Idle; NextTimeStateCanChange = DateTime.Now + IDLE_WAIT_TIME; @@ -124,13 +120,13 @@ namespace BigSock { } - + /* Try to move in a given direction. */ protected override bool TryMove(Vector2 direction) { - if(direction != Vector2.zero) { - rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + if (direction != Vector2.zero) { + rb.AddForce((float)LeapForce * direction, ForceMode2D.Impulse); return true; } return false; @@ -142,7 +138,7 @@ namespace BigSock { /* Attack */ - public partial class SlimeController { + public partial class SlimeController { //private void Attack_OnColliderEnter2D(Collider2D other) { // if (other.gameObject.tag == "Player") @@ -180,7 +176,7 @@ namespace BigSock { /* Movement */ - public partial class SlimeController { + public partial class SlimeController { protected override void Move_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { @@ -193,10 +189,10 @@ namespace BigSock { protected override void Move_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); - target = null; - } + target = null; + } } - + } /* diff --git a/MrBigsock/Assets/Code/UI/AbilityCluster.cs b/MrBigsock/Assets/Code/UI/AbilityCluster.cs index bda6f286..2f037faf 100644 --- a/MrBigsock/Assets/Code/UI/AbilityCluster.cs +++ b/MrBigsock/Assets/Code/UI/AbilityCluster.cs @@ -4,46 +4,38 @@ using UnityEngine; using UnityEngine.UI; using BigSock.Service; -namespace BigSock.UI -{ - public class AbilityCluster : MonoBehaviour - { - private const string ABILITYELEMENT = "UI/Ability"; - private List<AbilityElement> abilityList; +namespace BigSock.UI { + public class AbilityCluster : MonoBehaviour { + private const string ABILITYELEMENT = "UI/Ability"; + private List<AbilityElement> abilityList; - public void SetElements(int elementAmount) - { - abilityList = new List<AbilityElement>(); - ResetElements(); - for (int i = 0; i < elementAmount; ++i) - { - abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>()); - } - } + public void SetElements(int elementAmount) { + abilityList = new List<AbilityElement>(); + ResetElements(); + for (int i = 0; i < elementAmount; ++i) { + abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>()); + } + } - //Clears all elements in ability cluster. - public void ResetElements() - { - abilityList.Clear(); - var layout = this.GetComponent<HorizontalLayoutGroup>(); - for (int i = 0; i < layout.transform.childCount; i++) - { - Destroy(layout.transform.GetChild(i).gameObject); - } - } + //Clears all elements in ability cluster. + public void ResetElements() { + abilityList.Clear(); + var layout = this.GetComponent<HorizontalLayoutGroup>(); + for (int i = 0; i < layout.transform.childCount; i++) { + Destroy(layout.transform.GetChild(i).gameObject); + } + } - public void SetCooldown(int index, float amount) - { - abilityList[index].WithCooldown(amount); - } + public void SetCooldown(int index, float amount) { + abilityList[index].WithCooldown(amount); + } - public void SetCharge(int index, float amount) - { - abilityList[index].WithCharge(amount); - } - public void SetAbility(int index, AbilityEntity ability) { - abilityList[index].WithAbility(ability); - } + public void SetCharge(int index, float amount) { + abilityList[index].WithCharge(amount); + } + public void SetAbility(int index, AbilityEntity ability) { + abilityList[index].WithAbility(ability); + } - } + } } diff --git a/MrBigsock/Assets/Code/UI/AbilityElement.cs b/MrBigsock/Assets/Code/UI/AbilityElement.cs index ff8207e7..e549f0fd 100644 --- a/MrBigsock/Assets/Code/UI/AbilityElement.cs +++ b/MrBigsock/Assets/Code/UI/AbilityElement.cs @@ -4,50 +4,45 @@ using UnityEngine; using UnityEngine.UI; -namespace BigSock.UI -{ - public class AbilityElement : MonoBehaviour - { - private Slider chargeSlider, cooldownSlider; - private Image _sprite; - - public AbilityElement WithCharge(float? value = null, float? maxValue = null) - { - if (value != null) chargeSlider.value = value.Value; - - if (maxValue != null) chargeSlider.maxValue = maxValue.Value; - return this; - } - - public AbilityElement WithCooldown(float? value = null, float? maxValue = null) - { - if (value != null) cooldownSlider.value = value.Value; - - if (maxValue != null) cooldownSlider.maxValue = maxValue.Value; - return this; - } - - - public AbilityElement WithAbility(AbilityEntity ability) { - _sprite ??= transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>(); - - if (_sprite != null) - _sprite.overrideSprite = ability.Ability.Icon ?? _sprite.overrideSprite; - return this; - } - - - // Start is called before the first frame update - void Start() { - chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); - cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); - _sprite ??= transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>(); - } - - // Update is called once per frame - void Update() - { - - } - } +namespace BigSock.UI { + public class AbilityElement : MonoBehaviour { + private Slider chargeSlider, cooldownSlider; + private Image _sprite; + + public AbilityElement WithCharge(float? value = null, float? maxValue = null) { + if (value != null) chargeSlider.value = value.Value; + + if (maxValue != null) chargeSlider.maxValue = maxValue.Value; + return this; + } + + public AbilityElement WithCooldown(float? value = null, float? maxValue = null) { + if (value != null) cooldownSlider.value = value.Value; + + if (maxValue != null) cooldownSlider.maxValue = maxValue.Value; + return this; + } + + + public AbilityElement WithAbility(AbilityEntity ability) { + _sprite ??= transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>(); + + if (_sprite != null) + _sprite.overrideSprite = ability.Ability.Icon ?? _sprite.overrideSprite; + return this; + } + + + // Start is called before the first frame update + void Start() { + chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); + cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); + _sprite ??= transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>(); + } + + // Update is called once per frame + void Update() { + + } + } } diff --git a/MrBigsock/Assets/Code/UI/ChestDisplay.cs b/MrBigsock/Assets/Code/UI/ChestDisplay.cs index b28b01df..2a07607e 100644 --- a/MrBigsock/Assets/Code/UI/ChestDisplay.cs +++ b/MrBigsock/Assets/Code/UI/ChestDisplay.cs @@ -11,83 +11,82 @@ using BigSock.Interact; using UnityEditor; namespace BigSock.UI { - public class ChestDisplay : MonoBehaviour - { - public Button closeButton; - public List<IItem> items; - public List<Button> buttons; - public GameObject other; - public GameObject chest; - - PlayerController player; - - void Start() { - var itemButtonLocation = transform.Find("ItemBox").Find("ItemBoxBackground"); - buttons = new List<Button>(); - - // Gets button gameobjects and adds onClick listener - for (int i = 0; i < 3; i++) { - var button = itemButtonLocation.transform.Find("ButtonItem"+(i+1).ToString()).GetComponent<Button>(); - int j = i; - button.onClick.AddListener(delegate {ItemPicked(j); }); - buttons.Add(button); - } - - // The X button :) - closeButton = transform.Find("CloseButton").GetComponent<Button>(); - closeButton.onClick.AddListener(manuallyCloseWindow); - - // list of random items - items = chest.transform.GetComponent<Chest>().GetChestItems(); - - // Sets Item icon and name - for (int i = 0; i < buttons.Count; i++) { - buttons[i].gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(items[i].Id).Icon; - buttons[i].gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(items[i].Id).Name; - } - - this.other = GameObject.FindWithTag("Player"); - player = other.GetComponent<PlayerController>(); - - if (player.Inventory.AddItem(null) == -1) { - for (int i = 0; i < buttons.Count; i++) { - buttons[i].interactable = false; - } - transform.Find("Banner").Find("BannerBackground").Find("BannerExtraText").GetComponent<TMPro.TMP_Text>().text = "Inventory is full, free up some space to select an item"; - } - } - - public void ShowItemDescription(GameObject button) { - string[] buttonNumber = button.name.Split("ButtonItem"); - button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = items[int.Parse(buttonNumber[1])-1].GetToolTip(); - button.transform.Find("Item").GetComponent<Image>().color = Color.clear; - } - - public void HideItemDescription(GameObject button) { - button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = ""; - button.transform.Find("Item").GetComponent<Image>().color = Color.white; - } - - private void Update() { - if (Input.GetKeyDown(KeyCode.Escape)){ //|| Input.GetKeyDown(KeyCode.Mouse1)) { - manuallyCloseWindow(); + public class ChestDisplay : MonoBehaviour { + public Button closeButton; + public List<IItem> items; + public List<Button> buttons; + public GameObject other; + public GameObject chest; + + PlayerController player; + + void Start() { + var itemButtonLocation = transform.Find("ItemBox").Find("ItemBoxBackground"); + buttons = new List<Button>(); + + // Gets button gameobjects and adds onClick listener + for (int i = 0; i < 3; i++) { + var button = itemButtonLocation.transform.Find("ButtonItem" + (i + 1).ToString()).GetComponent<Button>(); + int j = i; + button.onClick.AddListener(delegate { ItemPicked(j); }); + buttons.Add(button); + } + + // The X button :) + closeButton = transform.Find("CloseButton").GetComponent<Button>(); + closeButton.onClick.AddListener(manuallyCloseWindow); + + // list of random items + items = chest.transform.GetComponent<Chest>().GetChestItems(); + + // Sets Item icon and name + for (int i = 0; i < buttons.Count; i++) { + buttons[i].gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(items[i].Id).Icon; + buttons[i].gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(items[i].Id).Name; + } + + this.other = GameObject.FindWithTag("Player"); + player = other.GetComponent<PlayerController>(); + + if (player.Inventory.AddItem(null) == -1) { + for (int i = 0; i < buttons.Count; i++) { + buttons[i].interactable = false; } - } - - private void manuallyCloseWindow() { - chest.transform.GetComponent<Chest>().ItemNotPicked(); - Destroy(this.gameObject); - } - - // Gets the chest element the display belongs to - public void setChestObject(GameObject chestInstance) { - chest = chestInstance; - } - - void ItemPicked(int number) { - player.TryPickUpItem(ItemService.SINGLETON.Get(items[number].Id)); - - Destroy(this.gameObject); - } - } + transform.Find("Banner").Find("BannerBackground").Find("BannerExtraText").GetComponent<TMPro.TMP_Text>().text = "Inventory is full, free up some space to select an item"; + } + } + + public void ShowItemDescription(GameObject button) { + string[] buttonNumber = button.name.Split("ButtonItem"); + button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = items[int.Parse(buttonNumber[1]) - 1].GetToolTip(); + button.transform.Find("Item").GetComponent<Image>().color = Color.clear; + } + + public void HideItemDescription(GameObject button) { + button.transform.Find("ItemDescription").GetComponent<TMPro.TMP_Text>().text = ""; + button.transform.Find("Item").GetComponent<Image>().color = Color.white; + } + + private void Update() { + if (Input.GetKeyDown(KeyCode.Escape)) { //|| Input.GetKeyDown(KeyCode.Mouse1)) { + manuallyCloseWindow(); + } + } + + private void manuallyCloseWindow() { + chest.transform.GetComponent<Chest>().ItemNotPicked(); + Destroy(this.gameObject); + } + + // Gets the chest element the display belongs to + public void setChestObject(GameObject chestInstance) { + chest = chestInstance; + } + + void ItemPicked(int number) { + player.TryPickUpItem(ItemService.SINGLETON.Get(items[number].Id)); + + Destroy(this.gameObject); + } + } } diff --git a/MrBigsock/Assets/Code/UI/ChestShowItemDesc.cs b/MrBigsock/Assets/Code/UI/ChestShowItemDesc.cs index 23bf66db..c618ec12 100644 --- a/MrBigsock/Assets/Code/UI/ChestShowItemDesc.cs +++ b/MrBigsock/Assets/Code/UI/ChestShowItemDesc.cs @@ -6,22 +6,19 @@ using UnityEngine.EventSystems; using BigSock.UI; namespace BigSock.UI { -public class ChestShowItemDesc : EventTrigger -{ + public class ChestShowItemDesc : EventTrigger { -public override void OnPointerEnter( PointerEventData data ) - { - gameObject.transform.parent.gameObject.transform.parent.transform.parent.gameObject.transform.GetComponent<ChestDisplay>().ShowItemDescription(this.gameObject); - //gameObject.transform.GetComponentInParent<GameObject>().GetComponentInParent<ChestDisplay>().ShowItemDescription(this.gameObject); - } + public override void OnPointerEnter(PointerEventData data) { + gameObject.transform.parent.gameObject.transform.parent.transform.parent.gameObject.transform.GetComponent<ChestDisplay>().ShowItemDescription(this.gameObject); + //gameObject.transform.GetComponentInParent<GameObject>().GetComponentInParent<ChestDisplay>().ShowItemDescription(this.gameObject); + } -public override void OnPointerExit( PointerEventData data ) - { - gameObject.transform.parent.gameObject.transform.parent.transform.parent.gameObject.transform.GetComponent<ChestDisplay>().HideItemDescription(this.gameObject); - //gameObject.transform.GetComponentInParent<GameObject>().GetComponentInParent<ChestDisplay>().ShowItemDescription(this.gameObject); - } + public override void OnPointerExit(PointerEventData data) { + gameObject.transform.parent.gameObject.transform.parent.transform.parent.gameObject.transform.GetComponent<ChestDisplay>().HideItemDescription(this.gameObject); + //gameObject.transform.GetComponentInParent<GameObject>().GetComponentInParent<ChestDisplay>().ShowItemDescription(this.gameObject); + } -} + } } diff --git a/MrBigsock/Assets/Code/UI/ControlScheme.cs b/MrBigsock/Assets/Code/UI/ControlScheme.cs index 2c1f2f59..46ff1898 100644 --- a/MrBigsock/Assets/Code/UI/ControlScheme.cs +++ b/MrBigsock/Assets/Code/UI/ControlScheme.cs @@ -2,27 +2,22 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -namespace BigSock.UI -{ - public class ControlScheme : MonoBehaviour - { +namespace BigSock.UI { + public class ControlScheme : MonoBehaviour { - float originalTime; - public void Start() - { - originalTime = Time.timeScale; - Time.timeScale = 0; - } + float originalTime; + public void Start() { + originalTime = Time.timeScale; + Time.timeScale = 0; + } - public void OnDestroy() - { - Time.timeScale = originalTime; - } - public void ExitMenu() - { - Destroy(gameObject); + public void OnDestroy() { + Time.timeScale = originalTime; + } + public void ExitMenu() { + Destroy(gameObject); - } - } + } + } } diff --git a/MrBigsock/Assets/Code/UI/EndScreen.cs b/MrBigsock/Assets/Code/UI/EndScreen.cs index 673314ad..6e1478bb 100644 --- a/MrBigsock/Assets/Code/UI/EndScreen.cs +++ b/MrBigsock/Assets/Code/UI/EndScreen.cs @@ -3,35 +3,28 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; -namespace BigSock.UI -{ - public class EndScreen : MonoBehaviour - { +namespace BigSock.UI { + public class EndScreen : MonoBehaviour { - public void Start() - { - Time.timeScale = 0; - GameObject menu = GameObject.Find("PlayerMenu(Clone)"); - if (menu != null) - { - Destroy(menu.gameObject); - } - } + public void Start() { + Time.timeScale = 0; + GameObject menu = GameObject.Find("PlayerMenu(Clone)"); + if (menu != null) { + Destroy(menu.gameObject); + } + } - public void OnDestroy() - { - Time.timeScale = 1; - } + public void OnDestroy() { + Time.timeScale = 1; + } - public void GiveUp() - { - Application.Quit(); - } + public void GiveUp() { + Application.Quit(); + } - public void TryAgain() - { - Destroy(gameObject); - SceneManager.LoadScene("MainMenu"); - } - } + public void TryAgain() { + Destroy(gameObject); + SceneManager.LoadScene("MainMenu"); + } + } } diff --git a/MrBigsock/Assets/Code/UI/EndScreenDed.cs b/MrBigsock/Assets/Code/UI/EndScreenDed.cs index ddcf30a7..31fa9d7c 100644 --- a/MrBigsock/Assets/Code/UI/EndScreenDed.cs +++ b/MrBigsock/Assets/Code/UI/EndScreenDed.cs @@ -3,16 +3,13 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; -public class EndScreenDed : MonoBehaviour -{ - public string mainMenu; - public void backToMain() - { - SceneManager.LoadScene(mainMenu); - } +public class EndScreenDed : MonoBehaviour { + public string mainMenu; + public void backToMain() { + SceneManager.LoadScene(mainMenu); + } - public void QuitGame() - { - Application.Quit(); - } + public void QuitGame() { + Application.Quit(); + } } diff --git a/MrBigsock/Assets/Code/UI/HPBar.cs b/MrBigsock/Assets/Code/UI/HPBar.cs index 518f60e2..2a3d6db7 100644 --- a/MrBigsock/Assets/Code/UI/HPBar.cs +++ b/MrBigsock/Assets/Code/UI/HPBar.cs @@ -3,21 +3,20 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -namespace BigSock.UI{ +namespace BigSock.UI { - public class HPBar : MonoBehaviour -{ + public class HPBar : MonoBehaviour { - public Slider slider; - - public void SetHealth(int health){ - slider.value = health; - } + public Slider slider; - public void SetMaxHealth(int health){ - slider.maxValue = health; - } -} + public void SetHealth(int health) { + slider.value = health; + } + + public void SetMaxHealth(int health) { + slider.maxValue = health; + } + } } diff --git a/MrBigsock/Assets/Code/UI/HpBarEnemy.cs b/MrBigsock/Assets/Code/UI/HpBarEnemy.cs index b206451b..5f068f87 100644 --- a/MrBigsock/Assets/Code/UI/HpBarEnemy.cs +++ b/MrBigsock/Assets/Code/UI/HpBarEnemy.cs @@ -4,25 +4,24 @@ using UnityEngine; using UnityEngine.UI; using TMPro; -namespace BigSock.UI{ - - public class HpBarEnemy : MonoBehaviour -{ - - public Slider slider; - - - - protected void Start(){ - slider = GetComponent<Slider>(); - } - - public void SetHPEnemy(float hp){ - slider.value = hp; - } - - public void SetMaxHpEnemy(float hp){ - slider.maxValue = hp; - } -} +namespace BigSock.UI { + + public class HpBarEnemy : MonoBehaviour { + + public Slider slider; + + + + protected void Start() { + slider = GetComponent<Slider>(); + } + + public void SetHPEnemy(float hp) { + slider.value = hp; + } + + public void SetMaxHpEnemy(float hp) { + slider.maxValue = hp; + } + } } \ No newline at end of file diff --git a/MrBigsock/Assets/Code/UI/InvTrash.cs b/MrBigsock/Assets/Code/UI/InvTrash.cs index 67cf0351..96af097c 100644 --- a/MrBigsock/Assets/Code/UI/InvTrash.cs +++ b/MrBigsock/Assets/Code/UI/InvTrash.cs @@ -3,13 +3,10 @@ using System.Collections; using UnityEngine; using UnityEngine.EventSystems; -namespace BigSock.UI -{ - public class InvTrash : MonoBehaviour, IDropHandler - { +namespace BigSock.UI { + public class InvTrash : MonoBehaviour, IDropHandler { public Inventory inventory; - public void OnDrop(PointerEventData eventData) - { + public void OnDrop(PointerEventData eventData) { // Get the item prefab that was dropped. var itemPref = eventData?.pointerDrag?.GetComponent<ItemPref>(); @@ -19,7 +16,7 @@ namespace BigSock.UI // Try to move the item in the inventory. var didMove = inventory.DropItem( itemPref.item, itemPref.itemSlot.inventoryType, - itemPref.itemSlot.position) ; + itemPref.itemSlot.position); // If we successfully moved the item in the inventory: update the gui. if (didMove) itemPref.itemSlot.item = null; diff --git a/MrBigsock/Assets/Code/UI/InventoryPanel.cs b/MrBigsock/Assets/Code/UI/InventoryPanel.cs index 10bf9c0a..06313222 100644 --- a/MrBigsock/Assets/Code/UI/InventoryPanel.cs +++ b/MrBigsock/Assets/Code/UI/InventoryPanel.cs @@ -9,10 +9,8 @@ using BigSock.Item; using BigSock.Service; -namespace BigSock.UI -{ - public class InventoryPanel : MonoBehaviour - { +namespace BigSock.UI { + public class InventoryPanel : MonoBehaviour { public PlayerController player; public const string INVSLOT = "UI/Inventoryslot"; public const string ITEM = "UI/Item"; @@ -22,7 +20,7 @@ namespace BigSock.UI public GridLayoutGroup gridAccessory; public GridLayoutGroup gridEquipment; - public TextMeshProUGUI toolTip; + public TextMeshProUGUI toolTip; public void Start() { @@ -36,12 +34,11 @@ namespace BigSock.UI Generates the GUI elements for the player's inventory. */ public void GenerateInv() { - if(player == null) return; + if (player == null) return; var inventory = player.Inventory; var trash = transform.Find("Trash")?.GetComponent<InvTrash>(); - if(trash != null) - { + if (trash != null) { trash.inventory = inventory; } diff --git a/MrBigsock/Assets/Code/UI/ItemPref.cs b/MrBigsock/Assets/Code/UI/ItemPref.cs index 4b15eef0..33211a25 100644 --- a/MrBigsock/Assets/Code/UI/ItemPref.cs +++ b/MrBigsock/Assets/Code/UI/ItemPref.cs @@ -8,10 +8,8 @@ using UnityEngine.EventSystems; using BigSock.Item; -namespace BigSock.UI -{ - public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IPointerClickHandler - { +namespace BigSock.UI { + public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IPointerClickHandler { public IItem item; public ItemSlot itemSlot; private RectTransform rectTransform; @@ -24,19 +22,19 @@ namespace BigSock.UI // Change the sprite if the item has one. var sprite = item?.Icon; - if(sprite != null) + if (sprite != null) GetComponent<UnityEngine.UI.Image>().overrideSprite = sprite; } private void Awake() { } - + /* Moves the item to be centered on it's ItemSlot */ public void ResetPosition() { - if(itemSlot != null) transform.position = itemSlot.transform.position; + if (itemSlot != null) transform.position = itemSlot.transform.position; } /* @@ -45,16 +43,16 @@ namespace BigSock.UI */ public void Place(ItemSlot slot) { // Cannot pass it null. - if(slot == null) throw new ArgumentNullException(nameof(slot)); + if (slot == null) throw new ArgumentNullException(nameof(slot)); // Inform our current slot that we've moved. - if(itemSlot != null) itemSlot.item = null; - + if (itemSlot != null) itemSlot.item = null; + itemSlot = slot; slot.item = this; ResetPosition(); } - + /* When the item is getting dragged, make it semi-transparent. */ @@ -75,7 +73,7 @@ namespace BigSock.UI */ public void OnEndDrag(PointerEventData eventData) { ResetPosition(); - + canvasGroup.alpha = 1f; canvasGroup.blocksRaycasts = true; } @@ -89,9 +87,9 @@ namespace BigSock.UI (OnPointerClick only triggers if you press and release on the same object) */ public void OnPointerClick(PointerEventData eventData) { - if(itemSlot != null && item != null) + if (itemSlot != null && item != null) itemSlot.DisplayToolTip(); - } + } } } diff --git a/MrBigsock/Assets/Code/UI/ItemSlot.cs b/MrBigsock/Assets/Code/UI/ItemSlot.cs index c611d059..4ba29cc2 100644 --- a/MrBigsock/Assets/Code/UI/ItemSlot.cs +++ b/MrBigsock/Assets/Code/UI/ItemSlot.cs @@ -7,10 +7,8 @@ using UnityEngine.EventSystems; using BigSock.Item; -namespace BigSock.UI -{ - public class ItemSlot : MonoBehaviour, IDropHandler - { +namespace BigSock.UI { + public class ItemSlot : MonoBehaviour, IDropHandler { public InventoryType inventoryType; public int position; public ItemPref item; @@ -30,10 +28,10 @@ namespace BigSock.UI - This is to move the item to the item slot when it starts - This has to be this way because the item slot is hoisted in the corner until this point. */ - if(!firstRan && transform.hasChanged) { + if (!firstRan && transform.hasChanged) { transform.hasChanged = false; firstRan = true; - + item?.ResetPosition(); } } @@ -46,15 +44,15 @@ namespace BigSock.UI var itemPref = eventData?.pointerDrag?.GetComponent<ItemPref>(); // Cancel if we didn't move an item prefab, or it was empty. - if(itemPref?.item == null) return; + if (itemPref?.item == null) return; // Try to move the item in the inventory. var didMove = inventory.MoveItem( - itemPref.item, itemPref.itemSlot.inventoryType, - itemPref.itemSlot.position, inventoryType, + itemPref.item, itemPref.itemSlot.inventoryType, + itemPref.itemSlot.position, inventoryType, position ); - + // If we successfully moved the item in the inventory: update the gui. if (didMove) itemPref.Place(this); @@ -71,11 +69,11 @@ namespace BigSock.UI */ public void DisplayToolTip() { // We must have an item. - if(item?.item == null) return; + if (item?.item == null) return; // Find the inventory pannel we belong to. var inventoryPanel = transform.parent?.parent?.GetComponent<InventoryPanel>(); - if(inventoryPanel == null) return; + if (inventoryPanel == null) return; // Set the tooltip. inventoryPanel.SetToolTip(item.item.GetToolTip()); diff --git a/MrBigsock/Assets/Code/UI/MainMenuScript.cs b/MrBigsock/Assets/Code/UI/MainMenuScript.cs index b4d307a4..5fa1178d 100644 --- a/MrBigsock/Assets/Code/UI/MainMenuScript.cs +++ b/MrBigsock/Assets/Code/UI/MainMenuScript.cs @@ -3,36 +3,30 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; -namespace BigSock.UI{ +namespace BigSock.UI { -public class MainMenuScript : MonoBehaviour + public class MainMenuScript : MonoBehaviour { -{ + public string firstLevel; - public string firstLevel; - - public void StartGame() - { - SceneManager.LoadScene(firstLevel); - Time.timeScale = 1; - } + public void StartGame() { + SceneManager.LoadScene(firstLevel); + Time.timeScale = 1; + } - public void OpenOptions() - { + public void OpenOptions() { - } + } - public void CloseOptions() - { + public void CloseOptions() { - } + } - public void QuitGame() - { - Application.Quit(); - } -} + public void QuitGame() { + Application.Quit(); + } + } } diff --git a/MrBigsock/Assets/Code/UI/PlayerMenu.cs b/MrBigsock/Assets/Code/UI/PlayerMenu.cs index 93eab945..000ecc8c 100644 --- a/MrBigsock/Assets/Code/UI/PlayerMenu.cs +++ b/MrBigsock/Assets/Code/UI/PlayerMenu.cs @@ -2,32 +2,26 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -namespace BigSock.UI -{ - public class PlayerMenu : MonoBehaviour - { - - public void Start() - { - - Time.timeScale = 0; - } - public void ExitMenu() - { - Destroy(gameObject); - - } +namespace BigSock.UI { + public class PlayerMenu : MonoBehaviour { - public void OnDestroy() - { - Time.timeScale = 1; - } + public void Start() { - public void Die() - { - GameObject player = GameObject.Find("BigSock"); - Destroy(player.gameObject); - } - } + Time.timeScale = 0; + } + public void ExitMenu() { + Destroy(gameObject); + + } + + public void OnDestroy() { + Time.timeScale = 1; + } + + public void Die() { + GameObject player = GameObject.Find("BigSock"); + Destroy(player.gameObject); + } + } } diff --git a/MrBigsock/Assets/Code/UI/StatPanel.cs b/MrBigsock/Assets/Code/UI/StatPanel.cs index 47f20a18..c1a0b834 100644 --- a/MrBigsock/Assets/Code/UI/StatPanel.cs +++ b/MrBigsock/Assets/Code/UI/StatPanel.cs @@ -4,239 +4,206 @@ using TMPro; using UnityEngine; using UnityEngine.UI; -namespace BigSock.UI -{ - public class StatPanel : MonoBehaviour - { - - - //Variables for game objects. - public PlayerController player; - public Slider hpSlider, mpSlider, spSlider, dmgSlider, speedSlider, luckSlider, concSlider; - public Button hpUp, hpDown, mpUp, mpDown, spUp, spDown, dmgUp, dmgDown, speedUp, speedDown, luckUp, luckDown, concUp, concDown, save; - public GameObject pointIndicator; - - //Holds text component of text mesh pro object. - private TextMeshProUGUI pointIndicatorText; - - //Used to show the player how many points they have left. - public int xpPoints; - - - private CharacterStats stats; - private Skills skills; - private Skills skillsTemp; - private Skills maxSkill; - private CharacterStats increase; - - private void Start() - { - pointIndicatorText = pointIndicator.GetComponent<TextMeshProUGUI>(); - GetNewStats(); - - - - hpUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.HP + skillsTemp.HP < maxSkill.HP) - { - xpPoints--; - skillsTemp.HP++; - stats.Apply(increase, Skill.HP, 1); - hpSlider.value = skills.HP + skillsTemp.HP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - hpDown.onClick.AddListener(() => - { - if (skillsTemp.HP > 0) - { - xpPoints++; - skillsTemp.HP--; - stats.Apply(increase, Skill.HP, -1); - hpSlider.value = skillsTemp.HP + skills.HP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - mpUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.MP + skillsTemp.MP < maxSkill.MP) - { - xpPoints--; - skillsTemp.MP++; - stats.Apply(increase, Skill.MP, 1); - mpSlider.value = skills.MP + skillsTemp.MP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - mpDown.onClick.AddListener(() => - { - if (skillsTemp.MP > 0) - { - xpPoints++; - skillsTemp.MP--; - stats.Apply(increase, Skill.MP, -1); - mpSlider.value = skillsTemp.MP + skills.MP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - spUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.SP + skillsTemp.SP < maxSkill.SP) - { - xpPoints--; - skillsTemp.SP++; - stats.Apply(increase, Skill.SP, 1); - spSlider.value = skills.SP + skillsTemp.SP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - spDown.onClick.AddListener(() => - { - if (skillsTemp.SP > 0) - { - xpPoints++; - skillsTemp.SP--; - stats.Apply(increase, Skill.SP, -1); - spSlider.value = skillsTemp.SP + skills.SP; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - dmgUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.Damage + skillsTemp.Damage < maxSkill.Damage) - { - xpPoints--; - skillsTemp.Damage++; - stats.Apply(increase, Skill.Damage, 1); - dmgSlider.value = skills.Damage + skillsTemp.Damage; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - dmgDown.onClick.AddListener(() => - { - if (skillsTemp.Damage > 0) - { - xpPoints++; - skillsTemp.Damage--; - stats.Apply(increase, Skill.Damage, -1); - dmgSlider.value = skillsTemp.Damage + skills.Damage; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - speedUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.Speed + skillsTemp.Speed < maxSkill.Speed) - { - xpPoints--; - skillsTemp.Speed++; - stats.Apply(increase, Skill.Speed, 1); - speedSlider.value = skills.Speed + skillsTemp.Speed; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - speedDown.onClick.AddListener(() => - { - if (skillsTemp.Speed > 0) - { - xpPoints++; - skillsTemp.Speed--; - stats.Apply(increase, Skill.Speed, -1); - speedSlider.value = skillsTemp.Speed + skills.Speed; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - luckUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.Luck + skillsTemp.Luck < maxSkill.Luck) - { - xpPoints--; - skillsTemp.Luck++; - stats.Apply(increase, Skill.Luck, 1); - luckSlider.value = skills.Luck + skillsTemp.Luck; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - luckDown.onClick.AddListener(() => - { - if (skillsTemp.Luck > 0) - { - xpPoints++; - skillsTemp.Luck--; - stats.Apply(increase, Skill.Luck, -1); - luckSlider.value = skillsTemp.Luck + skills.Luck; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - concUp.onClick.AddListener(() => - { - if (xpPoints > 0 && skills.Concentration + skillsTemp.Concentration < maxSkill.Concentration) - { - xpPoints--; - skillsTemp.Concentration++; - stats.Apply(increase, Skill.Concentration, 1); - concSlider.value = skills.Concentration + skillsTemp.Concentration; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - concDown.onClick.AddListener(() => - { - if (skillsTemp.Concentration > 0) - { - xpPoints++; - skillsTemp.Concentration--; - stats.Apply(increase, Skill.Concentration, -1); - concSlider.value = skillsTemp.Concentration + skills.Concentration; - pointIndicatorText.text = xpPoints.ToString(); - } - }); - - - save.onClick.AddListener(Save); - } - private void Save() - { - player.Skills = skills.Increase(skillsTemp); - player.BaseStats = stats; - player.SkillPoints = xpPoints; - player.UpdateModifiers(); - GetNewStats(); - } - - private void GetNewStats() - { - xpPoints = player.SkillPoints; - skills = player.Skills; - skillsTemp = new Skills(); - maxSkill = player.MaxSkills; - increase = player.StatIncreasePrSkillLevel; - stats = (CharacterStats)player.BaseStats.Add(new CharacterStats()); - - hpSlider.maxValue = maxSkill.HP; - spSlider.maxValue = maxSkill.SP; - mpSlider.maxValue = maxSkill.MP; - dmgSlider.maxValue = maxSkill.Damage; - speedSlider.maxValue = maxSkill.Speed; - luckSlider.maxValue = maxSkill.Luck; - concSlider.maxValue = maxSkill.Concentration; - - hpSlider.value = skills.HP; - spSlider.value = skills.SP; - mpSlider.value = skills.MP; - dmgSlider.value = skills.Damage; - speedSlider.value = skills.Speed; - luckSlider.value = skills.Luck; - concSlider.value = skills.Concentration; - - pointIndicatorText.text = xpPoints.ToString(); - } - } +namespace BigSock.UI { + public class StatPanel : MonoBehaviour { + + + //Variables for game objects. + public PlayerController player; + public Slider hpSlider, mpSlider, spSlider, dmgSlider, speedSlider, luckSlider, concSlider; + public Button hpUp, hpDown, mpUp, mpDown, spUp, spDown, dmgUp, dmgDown, speedUp, speedDown, luckUp, luckDown, concUp, concDown, save; + public GameObject pointIndicator; + + //Holds text component of text mesh pro object. + private TextMeshProUGUI pointIndicatorText; + + //Used to show the player how many points they have left. + public int xpPoints; + + + private CharacterStats stats; + private Skills skills; + private Skills skillsTemp; + private Skills maxSkill; + private CharacterStats increase; + + private void Start() { + pointIndicatorText = pointIndicator.GetComponent<TextMeshProUGUI>(); + GetNewStats(); + + + + hpUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.HP + skillsTemp.HP < maxSkill.HP) { + xpPoints--; + skillsTemp.HP++; + stats.Apply(increase, Skill.HP, 1); + hpSlider.value = skills.HP + skillsTemp.HP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + hpDown.onClick.AddListener(() => { + if (skillsTemp.HP > 0) { + xpPoints++; + skillsTemp.HP--; + stats.Apply(increase, Skill.HP, -1); + hpSlider.value = skillsTemp.HP + skills.HP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + mpUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.MP + skillsTemp.MP < maxSkill.MP) { + xpPoints--; + skillsTemp.MP++; + stats.Apply(increase, Skill.MP, 1); + mpSlider.value = skills.MP + skillsTemp.MP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + mpDown.onClick.AddListener(() => { + if (skillsTemp.MP > 0) { + xpPoints++; + skillsTemp.MP--; + stats.Apply(increase, Skill.MP, -1); + mpSlider.value = skillsTemp.MP + skills.MP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + spUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.SP + skillsTemp.SP < maxSkill.SP) { + xpPoints--; + skillsTemp.SP++; + stats.Apply(increase, Skill.SP, 1); + spSlider.value = skills.SP + skillsTemp.SP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + spDown.onClick.AddListener(() => { + if (skillsTemp.SP > 0) { + xpPoints++; + skillsTemp.SP--; + stats.Apply(increase, Skill.SP, -1); + spSlider.value = skillsTemp.SP + skills.SP; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + dmgUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.Damage + skillsTemp.Damage < maxSkill.Damage) { + xpPoints--; + skillsTemp.Damage++; + stats.Apply(increase, Skill.Damage, 1); + dmgSlider.value = skills.Damage + skillsTemp.Damage; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + dmgDown.onClick.AddListener(() => { + if (skillsTemp.Damage > 0) { + xpPoints++; + skillsTemp.Damage--; + stats.Apply(increase, Skill.Damage, -1); + dmgSlider.value = skillsTemp.Damage + skills.Damage; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + speedUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.Speed + skillsTemp.Speed < maxSkill.Speed) { + xpPoints--; + skillsTemp.Speed++; + stats.Apply(increase, Skill.Speed, 1); + speedSlider.value = skills.Speed + skillsTemp.Speed; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + speedDown.onClick.AddListener(() => { + if (skillsTemp.Speed > 0) { + xpPoints++; + skillsTemp.Speed--; + stats.Apply(increase, Skill.Speed, -1); + speedSlider.value = skillsTemp.Speed + skills.Speed; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + luckUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.Luck + skillsTemp.Luck < maxSkill.Luck) { + xpPoints--; + skillsTemp.Luck++; + stats.Apply(increase, Skill.Luck, 1); + luckSlider.value = skills.Luck + skillsTemp.Luck; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + luckDown.onClick.AddListener(() => { + if (skillsTemp.Luck > 0) { + xpPoints++; + skillsTemp.Luck--; + stats.Apply(increase, Skill.Luck, -1); + luckSlider.value = skillsTemp.Luck + skills.Luck; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + concUp.onClick.AddListener(() => { + if (xpPoints > 0 && skills.Concentration + skillsTemp.Concentration < maxSkill.Concentration) { + xpPoints--; + skillsTemp.Concentration++; + stats.Apply(increase, Skill.Concentration, 1); + concSlider.value = skills.Concentration + skillsTemp.Concentration; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + concDown.onClick.AddListener(() => { + if (skillsTemp.Concentration > 0) { + xpPoints++; + skillsTemp.Concentration--; + stats.Apply(increase, Skill.Concentration, -1); + concSlider.value = skillsTemp.Concentration + skills.Concentration; + pointIndicatorText.text = xpPoints.ToString(); + } + }); + + + save.onClick.AddListener(Save); + } + private void Save() { + player.Skills = skills.Increase(skillsTemp); + player.BaseStats = stats; + player.SkillPoints = xpPoints; + player.UpdateModifiers(); + GetNewStats(); + } + + private void GetNewStats() { + xpPoints = player.SkillPoints; + skills = player.Skills; + skillsTemp = new Skills(); + maxSkill = player.MaxSkills; + increase = player.StatIncreasePrSkillLevel; + stats = (CharacterStats)player.BaseStats.Add(new CharacterStats()); + + hpSlider.maxValue = maxSkill.HP; + spSlider.maxValue = maxSkill.SP; + mpSlider.maxValue = maxSkill.MP; + dmgSlider.maxValue = maxSkill.Damage; + speedSlider.maxValue = maxSkill.Speed; + luckSlider.maxValue = maxSkill.Luck; + concSlider.maxValue = maxSkill.Concentration; + + hpSlider.value = skills.HP; + spSlider.value = skills.SP; + mpSlider.value = skills.MP; + dmgSlider.value = skills.Damage; + speedSlider.value = skills.Speed; + luckSlider.value = skills.Luck; + concSlider.value = skills.Concentration; + + pointIndicatorText.text = xpPoints.ToString(); + } + } } diff --git a/MrBigsock/Assets/Code/UI/TabButton.cs b/MrBigsock/Assets/Code/UI/TabButton.cs index 3286d045..7d7a0a60 100644 --- a/MrBigsock/Assets/Code/UI/TabButton.cs +++ b/MrBigsock/Assets/Code/UI/TabButton.cs @@ -5,37 +5,31 @@ using UnityEngine.UI; using UnityEngine.EventSystems; -namespace BigSock.UI -{ - [RequireComponent(typeof(Image))] - public class TabButton : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler - { - public TabGroup tabGroup; - - public Image background; - - public void OnPointerClick(PointerEventData eventData) - { - tabGroup.OnTabSelected(this); - } - - public void OnPointerEnter(PointerEventData eventData) - { - tabGroup.OnTabEnter(this); - } - - public void OnPointerExit(PointerEventData eventData) - { - tabGroup.OnTabExit(this); - } - - // Start is called before the first frame update - void Start() - { - background = GetComponent<Image>(); - tabGroup.Subscribe(this); - } - - } +namespace BigSock.UI { + [RequireComponent(typeof(Image))] + public class TabButton : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler { + public TabGroup tabGroup; + + public Image background; + + public void OnPointerClick(PointerEventData eventData) { + tabGroup.OnTabSelected(this); + } + + public void OnPointerEnter(PointerEventData eventData) { + tabGroup.OnTabEnter(this); + } + + public void OnPointerExit(PointerEventData eventData) { + tabGroup.OnTabExit(this); + } + + // Start is called before the first frame update + void Start() { + background = GetComponent<Image>(); + tabGroup.Subscribe(this); + } + + } } diff --git a/MrBigsock/Assets/Code/UI/TabGroup.cs b/MrBigsock/Assets/Code/UI/TabGroup.cs index 6229d29b..919cac12 100644 --- a/MrBigsock/Assets/Code/UI/TabGroup.cs +++ b/MrBigsock/Assets/Code/UI/TabGroup.cs @@ -4,69 +4,56 @@ using UnityEngine; using UnityEngine.UI; -namespace BigSock.UI -{ - public class TabGroup : MonoBehaviour - { - - private List<TabButton> tabButtons; - private TabButton selectedTab; - public List<GameObject> objectsToSwap; - - - public void Subscribe(TabButton button) - { - if(tabButtons == null) - { - tabButtons = new List<TabButton>(); - } - - tabButtons.Add(button); - } - - public void OnTabEnter(TabButton button) - { - ResetTabs(); - if(selectedTab == null || button != selectedTab) { - button.GetComponent<Image>().color = new Color32(200, 200, 200, 255); - } - - } - - public void OnTabExit(TabButton button) - { - ResetTabs(); - } - - public void OnTabSelected(TabButton button) - { - selectedTab = button; - ResetTabs(); - button.GetComponent<Image>().color = new Color32(255, 255, 255, 255); - - int index = button.transform.GetSiblingIndex(); - for(int i=0; i<objectsToSwap.Count; i++) - { - if(i == index) - { - objectsToSwap[i].SetActive(true); - } - else - { - objectsToSwap[i].SetActive(false); - } - } - } - - public void ResetTabs() - { - foreach(TabButton button in tabButtons) - { - if(selectedTab != null && button == selectedTab) { continue; } - button.GetComponent<Image>().color = new Color32(160, 160, 160, 255); - } - } - } +namespace BigSock.UI { + public class TabGroup : MonoBehaviour { + + private List<TabButton> tabButtons; + private TabButton selectedTab; + public List<GameObject> objectsToSwap; + + + public void Subscribe(TabButton button) { + if (tabButtons == null) { + tabButtons = new List<TabButton>(); + } + + tabButtons.Add(button); + } + + public void OnTabEnter(TabButton button) { + ResetTabs(); + if (selectedTab == null || button != selectedTab) { + button.GetComponent<Image>().color = new Color32(200, 200, 200, 255); + } + + } + + public void OnTabExit(TabButton button) { + ResetTabs(); + } + + public void OnTabSelected(TabButton button) { + selectedTab = button; + ResetTabs(); + button.GetComponent<Image>().color = new Color32(255, 255, 255, 255); + + int index = button.transform.GetSiblingIndex(); + for (int i = 0; i < objectsToSwap.Count; i++) { + if (i == index) { + objectsToSwap[i].SetActive(true); + } else { + objectsToSwap[i].SetActive(false); + } + } + } + + public void ResetTabs() { + foreach (TabButton button in tabButtons) { + if (selectedTab != null && button == selectedTab) { continue; } + button.GetComponent<Image>().color = new Color32(160, 160, 160, 255); + } + } + } } diff --git a/MrBigsock/Assets/Code/UI/UtilBar.cs b/MrBigsock/Assets/Code/UI/UtilBar.cs index 515faf77..92c5b59e 100644 --- a/MrBigsock/Assets/Code/UI/UtilBar.cs +++ b/MrBigsock/Assets/Code/UI/UtilBar.cs @@ -3,54 +3,53 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -namespace BigSock.UI{ - - public class UtilBar : MonoBehaviour -{ - - public Slider hpSlider; - public Slider manaSlider; - public Slider staminaSlider; - public Slider xpSlider; - public Gradient gradient; - public Image hpFill; - - - public UtilBar WithHealth(int? value = null, int? maxValue = null){ - if(value != null) hpSlider.value = value.Value; - - if(maxValue != null) hpSlider.maxValue = maxValue.Value; - - hpFill.color = gradient.Evaluate(hpSlider.normalizedValue); - - return this; - } - - public UtilBar WithMana(int? value = null, int? maxValue = null){ - if(value != null) manaSlider.value = value.Value; - - if(maxValue != null) manaSlider.maxValue = maxValue.Value; - return this; - } - - public UtilBar WithStamina(int? value = null, int? maxValue = null){ - if(value != null) staminaSlider.value = value.Value; - - if(maxValue != null) staminaSlider.maxValue = maxValue.Value; - return this; - } - - public UtilBar WithXP(int? value = null, int? maxValue = null){ - if(value != null) xpSlider.value = value.Value; - - if(maxValue != null) xpSlider.maxValue = maxValue.Value; - return this; - } - - - - - - -} +namespace BigSock.UI { + + public class UtilBar : MonoBehaviour { + + public Slider hpSlider; + public Slider manaSlider; + public Slider staminaSlider; + public Slider xpSlider; + public Gradient gradient; + public Image hpFill; + + + public UtilBar WithHealth(int? value = null, int? maxValue = null) { + if (value != null) hpSlider.value = value.Value; + + if (maxValue != null) hpSlider.maxValue = maxValue.Value; + + hpFill.color = gradient.Evaluate(hpSlider.normalizedValue); + + return this; + } + + public UtilBar WithMana(int? value = null, int? maxValue = null) { + if (value != null) manaSlider.value = value.Value; + + if (maxValue != null) manaSlider.maxValue = maxValue.Value; + return this; + } + + public UtilBar WithStamina(int? value = null, int? maxValue = null) { + if (value != null) staminaSlider.value = value.Value; + + if (maxValue != null) staminaSlider.maxValue = maxValue.Value; + return this; + } + + public UtilBar WithXP(int? value = null, int? maxValue = null) { + if (value != null) xpSlider.value = value.Value; + + if (maxValue != null) xpSlider.maxValue = maxValue.Value; + return this; + } + + + + + + + } } diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index 54424647..d6832ce4 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -9,8 +9,7 @@ using BigSock.Service; namespace BigSock { - public class AttackMovement : MonoBehaviour - { + public class AttackMovement : MonoBehaviour { public float speed = 10.0f; bool moved = false; //Vector3 direction; @@ -29,7 +28,7 @@ namespace BigSock { The character that activated the attack. */ //public Character Actor { get; set; } - + /* The attack stats of the attack. */ @@ -42,15 +41,12 @@ namespace BigSock { // Start is called before the first frame update - void Start() - { + void Start() { } // Update is called once per frame - void Update() - { - if (!moved) - { + void Update() { + if (!moved) { startingPos = transform.position; moved = true; } @@ -61,19 +57,18 @@ namespace BigSock { var traveled = Vector2.Distance(transform.position, startingPos); // If we traveled passed our range: destroy this obj. - if(traveled > Stats.Range) { + if (traveled > Stats.Range) { PrefabService.SINGLETON.Destroy(gameObject); } } - - - void OnCollisionEnter2D(Collision2D collision) - { + + + void OnCollisionEnter2D(Collision2D collision) { //print($"[AttackMovement.OnCollisionEnter2D()] {collision.transform.position}"); var target = collision.gameObject.GetComponent<Character>(); - if(target != null) { + if (target != null) { //var attack = new AttackStats{ // Damage = Damage, @@ -92,10 +87,10 @@ namespace BigSock { // //Actor.TargetHit(target, attack); //} - if(target.TakeDamage(Stats)) { - + if (target.TakeDamage(Stats)) { + } - } + } } diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index cdbafa05..29676e9c 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -14,7 +14,7 @@ namespace BigSock { protected List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); protected Transform target; protected Animator m_Animator; - protected float distance; + protected float distance; protected float canAttack; @@ -27,7 +27,7 @@ namespace BigSock { //Rigidbody2D rb; // private Collider2D_Proxy secondCollider; - + protected override void Start() { base.Start(); @@ -51,18 +51,17 @@ namespace BigSock { protected virtual void RotateAnimation(Vector2 direction) { - if (direction.x > 0.01f){ + if (direction.x > 0.01f) { gameObject.GetComponent<SpriteRenderer>().flipX = false; - } - else if (direction.x < -0.01f){ + } else if (direction.x < -0.01f) { gameObject.GetComponent<SpriteRenderer>().flipX = true; } } protected virtual void Update() { Regenerate(); - - if (target != null && !isInMelee){ + + if (target != null && !isInMelee) { /* //walk float step = speed * Time.deltaTime; @@ -72,43 +71,42 @@ namespace BigSock { //roter RotateAnimation(); */ - + TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); - } - else{ + } else { } } - public override bool TakeDamage(AttackStats attack){ + public override bool TakeDamage(AttackStats attack) { var d = base.TakeDamage(attack); - if(HpBarEnemy == null) print("Error feil funk ikke"); + if (HpBarEnemy == null) print("Error feil funk ikke"); HpBarEnemy?.SetMaxHpEnemy(this.MaxHP); HpBarEnemy?.SetHPEnemy(this.HP); return d; } - + } /* Attack */ - public partial class EnemyController { + public partial class EnemyController { protected virtual void Attack_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") isInMelee = true; } - + protected virtual void Attack_OnColliderStay2D(Collider2D other) { var player = other.gameObject.GetComponent<PlayerController>(); - if(player != null) { + if (player != null) { // Create attack object. - var attack = (AttackStats) new AttackStats{ + var attack = (AttackStats)new AttackStats { Damage = Damage, Knockback = KnockbackForce, Range = 0, @@ -118,13 +116,13 @@ namespace BigSock { }.Calculate(Stats); // Get the player to take the damage. - if(player.TakeDamage(attack)){ + if (player.TakeDamage(attack)) { //rb position - player position //Vector2 difference = (other.transform.position - transform.position).normalized; //player.KnockBack(KnockbackForce, difference); //animer nå ? } - } + } } protected virtual void Attack_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") @@ -136,30 +134,30 @@ namespace BigSock { /* Move */ - public partial class EnemyController { + public partial class EnemyController { protected virtual void Move_OnColliderEnter2D(Collider2D other) { //Debug.Log("enter"); - if (other.gameObject.tag == "Player"){ + if (other.gameObject.tag == "Player") { //Debug.Log("enter if"); - + m_Animator.SetTrigger("walk"); target = other.transform; } } protected virtual void Move_OnColliderStay2D(Collider2D other) { - + } protected virtual void Move_OnColliderExit2D(Collider2D other) { - if (other.gameObject.tag == "Player"){ + if (other.gameObject.tag == "Player") { m_Animator.SetTrigger("idle"); target = other.transform; - target = null; - } + target = null; + } } - + } } diff --git a/MrBigsock/Assets/Code/orc/Enemy_orc_range.cs b/MrBigsock/Assets/Code/orc/Enemy_orc_range.cs index b542f4b3..26d6f174 100644 --- a/MrBigsock/Assets/Code/orc/Enemy_orc_range.cs +++ b/MrBigsock/Assets/Code/orc/Enemy_orc_range.cs @@ -13,7 +13,7 @@ namespace BigSock { The state */ public State State { get; protected set; } = State.Idle; - + public GameObject attack; protected IAttack _testAttack; /* @@ -25,7 +25,7 @@ namespace BigSock { The next time the state can change. */ public DateTime NextTimeStateCanChange { get; private set; } = DateTime.Now; - + /* Minimum idle time. */ @@ -41,18 +41,18 @@ namespace BigSock { protected Animator m_Animator_bow; - protected override void Start(){ - base.Start(); - _testAttack = (IAttack) AbilityService.SINGLETON.Get(103); - m_Animator_bow = gameObject.transform.GetChild (2).GetComponent<Animator>(); + protected override void Start() { + base.Start(); + _testAttack = (IAttack)AbilityService.SINGLETON.Get(103); + m_Animator_bow = gameObject.transform.GetChild(2).GetComponent<Animator>(); - } + } protected override void Update() { - if(State == State.Idle) { + if (State == State.Idle) { // If it has a target and has idled long enough. - if(target != null && DateTime.Now >= NextTimeStateCanChange && isInMelee) { + if (target != null && DateTime.Now >= NextTimeStateCanChange && isInMelee) { // Store target location. TargetLocation = target.position; @@ -61,18 +61,16 @@ namespace BigSock { NextTimeStateCanChange = DateTime.Now + CHARGE_WAIT_TIME; m_Animator.SetTrigger("walk"); } - if(target != null && !isInMelee){ + if (target != null && !isInMelee) { TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); } - } - - else if(State == State.Charging) { + } else if (State == State.Charging) { // If it has charged long enough. m_Animator_bow.SetTrigger("attack"); - if(DateTime.Now >= NextTimeStateCanChange && target != null) { + if (DateTime.Now >= NextTimeStateCanChange && target != null) { m_Animator_bow.SetTrigger("none"); - + // Object w/ parameters for abilities. var par = GetAbilityParam(target.position); //var par = new AbilityParam{ @@ -80,22 +78,20 @@ namespace BigSock { // TargetPos = target.position, // MovementDir = moveDir, //}; - + _testAttack.Use(par); - + State = State.Attacking; NextTimeStateCanChange = DateTime.Now + ATTACK_WAIT_TIME; } - if(target != null && !isInMelee){ + if (target != null && !isInMelee) { TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); } - } - - else if(State == State.Attacking) { + } else if (State == State.Attacking) { // If it has charged long enough. - if(DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { + if (DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { // Update the state. - + State = State.Idle; NextTimeStateCanChange = DateTime.Now + IDLE_WAIT_TIME; m_Animator.SetTrigger("idle"); @@ -110,7 +106,7 @@ namespace BigSock { /* Movement */ - public partial class Enemy_orc_range { + public partial class Enemy_orc_range { protected override void Move_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { @@ -123,15 +119,15 @@ namespace BigSock { protected override void Move_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); - target = null; - } + target = null; + } } - + } /* Attack */ - public partial class Enemy_orc_range { + public partial class Enemy_orc_range { protected override void Attack_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { @@ -141,7 +137,7 @@ namespace BigSock { } } - protected override void Attack_OnColliderStay2D(Collider2D other){ + protected override void Attack_OnColliderStay2D(Collider2D other) { } @@ -149,10 +145,10 @@ namespace BigSock { protected override void Attack_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); - isInMelee = false; - } + isInMelee = false; + } } - + } /* diff --git a/MrBigsock/Assets/Code/skeleton/Enemy_skeleton_range.cs b/MrBigsock/Assets/Code/skeleton/Enemy_skeleton_range.cs index 98f85aeb..12786332 100644 --- a/MrBigsock/Assets/Code/skeleton/Enemy_skeleton_range.cs +++ b/MrBigsock/Assets/Code/skeleton/Enemy_skeleton_range.cs @@ -13,7 +13,7 @@ namespace BigSock { The state */ public State State { get; protected set; } = State.Idle; - + public GameObject attack; protected IAttack _testAttack; /* @@ -25,7 +25,7 @@ namespace BigSock { The next time the state can change. */ public DateTime NextTimeStateCanChange { get; private set; } = DateTime.Now; - + /* Minimum idle time. */ @@ -41,17 +41,17 @@ namespace BigSock { protected Animator m_Animator_bow; - protected override void Start(){ - base.Start(); - _testAttack = (IAttack) AbilityService.SINGLETON.Get(103); + protected override void Start() { + base.Start(); + _testAttack = (IAttack)AbilityService.SINGLETON.Get(103); - } + } protected override void Update() { - if(State == State.Idle) { + if (State == State.Idle) { // If it has a target and has idled long enough. - if(target != null && DateTime.Now >= NextTimeStateCanChange && isInMelee) { + if (target != null && DateTime.Now >= NextTimeStateCanChange && isInMelee) { // Store target location. TargetLocation = target.position; @@ -61,16 +61,14 @@ namespace BigSock { NextTimeStateCanChange = DateTime.Now + CHARGE_WAIT_TIME; //m_Animator.SetTrigger("walk"); } - if(target != null && !isInMelee){ + if (target != null && !isInMelee) { TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); } - } - - else if(State == State.Charging) { + } else if (State == State.Charging) { // If it has charged long enough. - - if(DateTime.Now >= NextTimeStateCanChange && target != null) { - + + if (DateTime.Now >= NextTimeStateCanChange && target != null) { + // Object w/ parameters for abilities. var par = GetAbilityParam(target.position); //var par = new AbilityParam{ @@ -80,21 +78,19 @@ namespace BigSock { //}; _testAttack.Use(par); - + State = State.Attacking; NextTimeStateCanChange = DateTime.Now + ATTACK_WAIT_TIME; } - if(target != null && !isInMelee){ + if (target != null && !isInMelee) { m_Animator.SetTrigger("walk"); TryMove((new Vector2(target.position.x, target.position.y) - rb.position).normalized); } - } - - else if(State == State.Attacking) { + } else if (State == State.Attacking) { // If it has charged long enough. - if(DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { + if (DateTime.Now >= NextTimeStateCanChange || rb.velocity == Vector2.zero) { // Update the state. - + State = State.Idle; NextTimeStateCanChange = DateTime.Now + IDLE_WAIT_TIME; m_Animator.SetTrigger("idle"); @@ -109,7 +105,7 @@ namespace BigSock { /* Movement */ - public partial class Enemy_skeleton_range { + public partial class Enemy_skeleton_range { protected override void Move_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { @@ -122,15 +118,15 @@ namespace BigSock { protected override void Move_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); - target = null; - } + target = null; + } } - + } /* Attack */ - public partial class Enemy_skeleton_range { + public partial class Enemy_skeleton_range { protected override void Attack_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { @@ -140,7 +136,7 @@ namespace BigSock { } } - protected override void Attack_OnColliderStay2D(Collider2D other){ + protected override void Attack_OnColliderStay2D(Collider2D other) { } @@ -148,15 +144,15 @@ namespace BigSock { protected override void Attack_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); - isInMelee = false; - } + isInMelee = false; + } } - + } /* The different states the skeleton can be in. */ - - + + } diff --git a/MrBigsock/Packages/packages-lock.json b/MrBigsock/Packages/packages-lock.json index f7cc4843..3b65785c 100644 --- a/MrBigsock/Packages/packages-lock.json +++ b/MrBigsock/Packages/packages-lock.json @@ -1,11 +1,11 @@ { "dependencies": { "com.unity.2d.animation": { - "version": "7.0.7", + "version": "7.0.6", "depth": 1, "source": "registry", "dependencies": { - "com.unity.2d.common": "6.0.4", + "com.unity.2d.common": "6.0.3", "com.unity.2d.sprite": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.uielements": "1.0.0" @@ -13,7 +13,7 @@ "url": "https://packages.unity.com" }, "com.unity.2d.common": { - "version": "6.0.4", + "version": "6.0.3", "depth": 2, "source": "registry", "dependencies": { @@ -39,12 +39,12 @@ "url": "https://packages.unity.com" }, "com.unity.2d.psdimporter": { - "version": "6.0.5", + "version": "6.0.4", "depth": 1, "source": "registry", "dependencies": { - "com.unity.2d.animation": "7.0.7", - "com.unity.2d.common": "6.0.4", + "com.unity.2d.animation": "7.0.6", + "com.unity.2d.common": "6.0.3", "com.unity.2d.sprite": "1.0.0" }, "url": "https://packages.unity.com" @@ -56,12 +56,12 @@ "dependencies": {} }, "com.unity.2d.spriteshape": { - "version": "7.0.6", + "version": "7.0.5", "depth": 1, "source": "registry", "dependencies": { "com.unity.mathematics": "1.1.0", - "com.unity.2d.common": "6.0.4", + "com.unity.2d.common": "6.0.3", "com.unity.2d.path": "5.0.2", "com.unity.modules.physics2d": "1.0.0" }, @@ -123,11 +123,11 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.2d.animation": "7.0.7", + "com.unity.2d.animation": "7.0.6", "com.unity.2d.pixel-perfect": "5.0.1", - "com.unity.2d.psdimporter": "6.0.5", + "com.unity.2d.psdimporter": "6.0.4", "com.unity.2d.sprite": "1.0.0", - "com.unity.2d.spriteshape": "7.0.6", + "com.unity.2d.spriteshape": "7.0.5", "com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap.extras": "2.2.3" } -- GitLab