aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Actors/Actor.cs30
-rw-r--r--Assets/Scripts/LevelController.cs46
2 files changed, 63 insertions, 13 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index 9a4b338..6b82060 100644
--- a/Assets/Scripts/Actors/Actor.cs
+++ b/Assets/Scripts/Actors/Actor.cs
@@ -15,6 +15,7 @@ namespace MontanaJohns.Actors
[SerializeField] protected float gravityScale = 1.5f;
[SerializeField] protected Stats baseStats = Stats.DefaultBaseStats();
[SerializeField] protected Transform groundCheckPoint;
+ [SerializeField] protected float invulnTime = 0f;
protected Rigidbody2D _rigidBody;
protected SpriteRenderer _renderer;
@@ -32,6 +33,8 @@ namespace MontanaJohns.Actors
public Stats stats;
public int health;
+ public bool invuln;
+
protected virtual void Awake()
{
_rigidBody = GetComponent<Rigidbody2D>();
@@ -39,10 +42,7 @@ namespace MontanaJohns.Actors
_renderer = GetComponent<SpriteRenderer>();
_animator = GetComponent<Animator>();
groundLayers = LayerMask.GetMask("Grapple", "Ground");
- }
- protected virtual void Start()
- {
_rigidBody.freezeRotation = true;
_rigidBody.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
_rigidBody.gravityScale = gravityScale;
@@ -53,6 +53,11 @@ namespace MontanaJohns.Actors
jumpCount = stats.maxJumps;
}
+ protected virtual void Start()
+ {
+
+ }
+
protected virtual void FixedUpdate()
{
if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers))
@@ -137,18 +142,29 @@ namespace MontanaJohns.Actors
public virtual void TakeDamage(int damage)
{
- health -= damage;
- StartCoroutine(DamageAnimation());
+ StartCoroutine(Damage(damage));
+ }
+
+ private IEnumerator Damage(int damage)
+ {
+ if(!invuln)
+ {
+ invuln = true;
+ health -= damage;
+ StartCoroutine(DamageAnimation());
+ yield return new WaitForSeconds(invulnTime);
+ invuln = false;
+ }
}
- IEnumerator DamageAnimation()
+ private IEnumerator DamageAnimation()
{
_renderer.color = Color.red;
yield return new WaitForSeconds(0.5f);
_renderer.color = Color.white;
}
- IEnumerator Falling()
+ private IEnumerator Falling()
{
_animator.SetBool("airborn", true);
diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs
index 7c7355e..1b8bd47 100644
--- a/Assets/Scripts/LevelController.cs
+++ b/Assets/Scripts/LevelController.cs
@@ -1,12 +1,15 @@
using System.Collections;
using System.Collections.Generic;
+using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelController : MonoBehaviour
{
[SerializeField] GameObject treasure;
- // Start is called before the first frame update
+ [SerializeField] List<GameObject> enemies;
+
+ private string clone = "(Clone)";
public void StartGame()
{
@@ -15,13 +18,44 @@ public class LevelController : MonoBehaviour
public void ResetLevel()
{
+ //Destroy
Destroy(GameObject.Find("Boulder(Clone)"));
Destroy(GameObject.Find("BoobyTrapSpawnPoint(Clone)"));
- var currentTreasure = GameObject.Find("Treasure");
- if(currentTreasure)
- Destroy(currentTreasure);
- else
- Destroy(GameObject.Find("Treasure(Clone)"));
+ CloneDestroy("Treasure");
+ DestroyList(enemies);
+
+ //Instantiate
Instantiate(treasure);
+ InstantiateList(enemies);
+ }
+
+ private void CloneDestroy(string objectName)
+ {
+ var obj = GameObject.Find(objectName);
+ if (obj)
+ Destroy(obj);
+ else
+ {
+ obj = GameObject.Find(objectName + clone);
+ if (obj)
+ Destroy(GameObject.Find(objectName + clone));
+ }
+ }
+
+ private void DestroyList(List<GameObject> gameObjects)
+ {
+ foreach(GameObject obj in gameObjects)
+ {
+ CloneDestroy(obj.name);
+ }
+ }
+
+ private void InstantiateList(List<GameObject> gameObjects)
+ {
+ foreach (GameObject obj in gameObjects)
+ {
+ PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction);
+ Instantiate(obj);
+ }
}
}