aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Actors/Player.cs1
-rw-r--r--Assets/Scripts/BoobyTrap.cs15
-rw-r--r--Assets/Scripts/Boulder.cs45
-rw-r--r--Assets/Scripts/Boulder.cs.meta11
-rw-r--r--Assets/Scripts/LevelController.cs17
-rw-r--r--Assets/Scripts/LevelController.cs.meta11
6 files changed, 98 insertions, 2 deletions
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 3537aa7..1b2155a 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -57,6 +57,7 @@ namespace MontanaJohns.Actors
{
if(health <= 0)
{
+ MainCamera.GetComponent<LevelController>().ResetLevel();
ResetStats();
health = stats.maxHealth;
transform.position = spawnPoint;
diff --git a/Assets/Scripts/BoobyTrap.cs b/Assets/Scripts/BoobyTrap.cs
index 72fc6ce..2ce736c 100644
--- a/Assets/Scripts/BoobyTrap.cs
+++ b/Assets/Scripts/BoobyTrap.cs
@@ -5,12 +5,23 @@ using UnityEngine;
public class BoobyTrap : MonoBehaviour
{
+ [SerializeField] GameObject boobyTrap;
+ [SerializeField] GameObject spawnPoint;
+
+ bool triggered;
+
+ private void Start()
+ {
+ Instantiate(spawnPoint);
+ }
+
private void OnTriggerEnter2D(Collider2D collision)
{
- if (collision.gameObject.tag == "Player")
+ if (collision.gameObject.tag == "Player" && !triggered)
{
+ triggered = true;
gameObject.GetComponent<SpriteRenderer>().sprite = null;
- //TODO spawn the boulder
+ Instantiate(boobyTrap, spawnPoint.transform.position, Quaternion.identity);
}
}
}
diff --git a/Assets/Scripts/Boulder.cs b/Assets/Scripts/Boulder.cs
new file mode 100644
index 0000000..5aa2beb
--- /dev/null
+++ b/Assets/Scripts/Boulder.cs
@@ -0,0 +1,45 @@
+using MontanaJohns.Actors;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Boulder : MonoBehaviour
+{
+ [SerializeField] float speed;
+ [SerializeField] float maxSpeed;
+
+ private GameObject player;
+ private Rigidbody2D rb;
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ player = GameObject.FindGameObjectWithTag("Player");
+ rb = transform.GetComponent<Rigidbody2D>();
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+ if (player.transform.position.x < transform.position.x)
+ {
+ transform.Rotate(0, 0, 1);
+ }
+ else
+ {
+ transform.Rotate(0, 0, -1);
+ }
+ transform.position = Vector2.MoveTowards(transform.position, new Vector2(player.transform.position.x, 0), speed * Time.deltaTime);
+ if(rb.velocity.x >= maxSpeed)
+ rb.velocity = new Vector2(maxSpeed, rb.velocity.y);
+ }
+
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ if (collision.gameObject.tag == "Player")
+ {
+ collision.GetComponent<Actor>().TakeDamage(999);
+ }
+ }
+}
diff --git a/Assets/Scripts/Boulder.cs.meta b/Assets/Scripts/Boulder.cs.meta
new file mode 100644
index 0000000..d053a76
--- /dev/null
+++ b/Assets/Scripts/Boulder.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 760b14f92dafdd34381066ba181a1f93
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs
new file mode 100644
index 0000000..6d91d71
--- /dev/null
+++ b/Assets/Scripts/LevelController.cs
@@ -0,0 +1,17 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class LevelController : MonoBehaviour
+{
+ [SerializeField] GameObject treasure;
+ // Start is called before the first frame update
+
+ public void ResetLevel()
+ {
+ Destroy(GameObject.Find("Boulder(Clone)"));
+ Destroy(GameObject.Find("BoobyTrapSpawnPoint(Clone)"));
+ Destroy(GameObject.Find("Treasure"));
+ Instantiate(treasure);
+ }
+}
diff --git a/Assets/Scripts/LevelController.cs.meta b/Assets/Scripts/LevelController.cs.meta
new file mode 100644
index 0000000..b672ba6
--- /dev/null
+++ b/Assets/Scripts/LevelController.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 37b6adf04336a564cb72facb6e18b968
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: