aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Actors/Actor.cs10
-rw-r--r--Assets/Scripts/Actors/Player.cs26
-rw-r--r--Assets/Scripts/BoobyTrap.cs16
-rw-r--r--Assets/Scripts/BoobyTrap.cs.meta11
-rw-r--r--Assets/Scripts/BottomlessPit.cs22
-rw-r--r--Assets/Scripts/BottomlessPit.cs.meta11
-rw-r--r--Assets/Scripts/Cursor.cs24
-rw-r--r--Assets/Scripts/Cursor.cs.meta11
-rw-r--r--Assets/Scripts/RespawnPoint.cs18
-rw-r--r--Assets/Scripts/RespawnPoint.cs.meta11
-rw-r--r--Assets/Scripts/Traps/TimedTrap.cs16
11 files changed, 166 insertions, 10 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index bcee7a3..2e98974 100644
--- a/Assets/Scripts/Actors/Actor.cs
+++ b/Assets/Scripts/Actors/Actor.cs
@@ -14,7 +14,6 @@ namespace MontanaJohns.Actors
{
[SerializeField] protected float gravityScale = 1.5f;
[SerializeField] protected Stats baseStats = Stats.DefaultBaseStats();
- [SerializeField] protected LayerMask groundLayer;
[SerializeField] protected Transform groundCheckPoint;
protected Rigidbody2D _rigidBody;
@@ -26,8 +25,8 @@ namespace MontanaJohns.Actors
protected Active activeItem;
protected bool isGrappling;
protected Vector2? grapplePoint = null;
+ protected LayerMask groundLayers;
Collection<Item> items;
- bool isFalling;
public int health;
protected int jumpCount;
@@ -39,6 +38,7 @@ namespace MontanaJohns.Actors
_transform = GetComponent<Transform>();
_renderer = GetComponent<SpriteRenderer>();
_animator = GetComponent<Animator>();
+ groundLayers = LayerMask.GetMask("Grapple", "Ground");
}
protected virtual void Start()
@@ -55,7 +55,7 @@ namespace MontanaJohns.Actors
protected virtual void FixedUpdate()
{
- if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayer))
+ if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers))
{
_animator.SetTrigger("fall");
StartCoroutine(Falling());
@@ -66,7 +66,7 @@ namespace MontanaJohns.Actors
{
var target = new Vector2(input * stats.speedMultiplier * 10, _rigidBody.velocity.y);
_rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
- _animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 0.001);
+ _animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 1);
if (_rigidBody.velocity.x < -0.001)
_renderer.flipX = true;
@@ -127,7 +127,7 @@ namespace MontanaJohns.Actors
{
_animator.SetBool("airborn", true);
- while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayer))
+ while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers))
{
yield return new WaitForFixedUpdate();
}
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 3192338..3537aa7 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -10,10 +10,11 @@ namespace MontanaJohns.Actors
{
public Transform ActorTransform => _transform;
public Camera MainCamera => _camera;
+ public Vector3 spawnPoint;
- Camera _camera;
- PlayerInput playerInput;
- InputAction use, move, jump;
+ private Camera _camera;
+ private PlayerInput playerInput;
+ private InputAction use, move, jump;
protected override void Awake()
{
@@ -34,7 +35,8 @@ namespace MontanaJohns.Actors
base.Start();
GameObject loadedItem = (GameObject)Instantiate(Resources.Load("ActiveItems/Whip"));
activeItem = loadedItem.GetComponent<Whip>();
- stats = baseStats + activeItem.stats;
+ ResetStats();
+ spawnPoint = transform.position;
}
protected void Update()
@@ -48,6 +50,22 @@ namespace MontanaJohns.Actors
{
base.Move(move.ReadValue<Vector2>().x);
}
+ DeathCheck();
+ }
+
+ protected void DeathCheck()
+ {
+ if(health <= 0)
+ {
+ ResetStats();
+ health = stats.maxHealth;
+ transform.position = spawnPoint;
+ }
+ }
+
+ protected void ResetStats()
+ {
+ stats = baseStats + activeItem.stats;
}
}
} \ No newline at end of file
diff --git a/Assets/Scripts/BoobyTrap.cs b/Assets/Scripts/BoobyTrap.cs
new file mode 100644
index 0000000..72fc6ce
--- /dev/null
+++ b/Assets/Scripts/BoobyTrap.cs
@@ -0,0 +1,16 @@
+using MontanaJohns.Actors;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class BoobyTrap : MonoBehaviour
+{
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ if (collision.gameObject.tag == "Player")
+ {
+ gameObject.GetComponent<SpriteRenderer>().sprite = null;
+ //TODO spawn the boulder
+ }
+ }
+}
diff --git a/Assets/Scripts/BoobyTrap.cs.meta b/Assets/Scripts/BoobyTrap.cs.meta
new file mode 100644
index 0000000..b9c5011
--- /dev/null
+++ b/Assets/Scripts/BoobyTrap.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 042e1a970c0394244831fbd869ab4c75
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/BottomlessPit.cs b/Assets/Scripts/BottomlessPit.cs
new file mode 100644
index 0000000..01ee211
--- /dev/null
+++ b/Assets/Scripts/BottomlessPit.cs
@@ -0,0 +1,22 @@
+using MontanaJohns.Actors;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class BottomlessPit : MonoBehaviour
+{
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ if (LayerMask.LayerToName(collision.gameObject.layer) == "Enemy" || LayerMask.LayerToName(collision.gameObject.layer) == "Player")
+ {
+ if(collision.gameObject.tag == "Player")
+ {
+ collision.gameObject.GetComponent<Actor>().TakeDamage(999);
+ }
+ else
+ {
+ Destroy(collision.gameObject);
+ }
+ }
+ }
+}
diff --git a/Assets/Scripts/BottomlessPit.cs.meta b/Assets/Scripts/BottomlessPit.cs.meta
new file mode 100644
index 0000000..0ac28b0
--- /dev/null
+++ b/Assets/Scripts/BottomlessPit.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: cd271f6c6a321314083dd4f135146a28
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Cursor.cs b/Assets/Scripts/Cursor.cs
new file mode 100644
index 0000000..43b0ea6
--- /dev/null
+++ b/Assets/Scripts/Cursor.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+public class Cursor : MonoBehaviour
+{
+ [SerializeField] private Texture2D cursorTexture;
+ [SerializeField] private float disableDistance = 20f;
+
+ private CursorMode cursorMode = CursorMode.Auto;
+ private Vector2 hotSpot = Vector2.zero;
+
+ // Update is called once per frame
+ void Update()
+ {
+ Vector2 mousePos = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
+ float distance = Vector2.Distance(mousePos, gameObject.transform.position);
+ if (distance > disableDistance)
+ UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
+ else
+ UnityEngine.Cursor.SetCursor(null, Vector2.zero, cursorMode);
+ }
+}
diff --git a/Assets/Scripts/Cursor.cs.meta b/Assets/Scripts/Cursor.cs.meta
new file mode 100644
index 0000000..4642bb7
--- /dev/null
+++ b/Assets/Scripts/Cursor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1fd5ff2b3d72a6544921535ca83cfcf1
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/RespawnPoint.cs b/Assets/Scripts/RespawnPoint.cs
new file mode 100644
index 0000000..6396128
--- /dev/null
+++ b/Assets/Scripts/RespawnPoint.cs
@@ -0,0 +1,18 @@
+using MontanaJohns.Actors;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class RespawnPoint : MonoBehaviour
+{
+ [SerializeField] private Sprite activatedSprite;
+
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ if (collision.gameObject.tag == "Player")
+ {
+ collision.gameObject.GetComponent<Player>().spawnPoint = transform.position;
+ gameObject.GetComponent<SpriteRenderer>().sprite = activatedSprite;
+ }
+ }
+}
diff --git a/Assets/Scripts/RespawnPoint.cs.meta b/Assets/Scripts/RespawnPoint.cs.meta
new file mode 100644
index 0000000..665dbad
--- /dev/null
+++ b/Assets/Scripts/RespawnPoint.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 103552dc60ef9184c805529099d548b7
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Traps/TimedTrap.cs b/Assets/Scripts/Traps/TimedTrap.cs
index 1cae196..9413b82 100644
--- a/Assets/Scripts/Traps/TimedTrap.cs
+++ b/Assets/Scripts/Traps/TimedTrap.cs
@@ -6,11 +6,13 @@ public class TimedTrap : TrapDamage
[Header("TimedTrap")]
[SerializeField] protected float activationDelay;
[SerializeField] protected float activeTime;
+ [SerializeField] protected float offset;
protected Animator animator;
protected SpriteRenderer sr;
protected bool triggered;
protected bool active;
+ protected bool isOffset;
protected void Awake()
{
@@ -18,11 +20,17 @@ public class TimedTrap : TrapDamage
sr = GetComponent<SpriteRenderer>();
}
+ private void Start()
+ {
+ StartCoroutine(Offset());
+ }
+
protected void Update()
{
if (!triggered)
{
- StartCoroutine(Activate());
+ if(isOffset)
+ StartCoroutine(Activate());
}
}
@@ -55,4 +63,10 @@ public class TimedTrap : TrapDamage
active = false;
animator.SetBool("activated", false);
}
+
+ protected IEnumerator Offset()
+ {
+ yield return new WaitForSeconds(offset);
+ isOffset = true;
+ }
}