aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorNeil Kollack <nkollack@gmail.com>2022-04-26 19:17:37 -0500
committerGitHub <noreply@github.com>2022-04-26 19:17:37 -0500
commit0ea77030722b86890551dc9291811438c087d6d5 (patch)
tree814c89e07359a20c2bf8c09388316e34344a8087 /Assets/Scripts
parent41e8678c463b7606dfaf292d67d05244ff044878 (diff)
parentc12394b098bdeaf6f02177fab5964eb501cb3a39 (diff)
Merge pull request #7 from MontanaJohns/developHEADmain
Final Project Submission
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Actors/Actor.cs55
-rw-r--r--Assets/Scripts/Actors/Enemy.cs43
-rw-r--r--Assets/Scripts/Actors/Player.cs13
-rw-r--r--Assets/Scripts/Core/Stats.cs3
-rw-r--r--Assets/Scripts/Cursor.cs15
-rw-r--r--Assets/Scripts/Items/Whip.cs13
-rw-r--r--Assets/Scripts/LevelController.cs1
-rw-r--r--Assets/Scripts/RespawnPoint.cs12
8 files changed, 130 insertions, 25 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs
index eb8185e..53ea50b 100644
--- a/Assets/Scripts/Actors/Actor.cs
+++ b/Assets/Scripts/Actors/Actor.cs
@@ -33,6 +33,7 @@ namespace MontanaJohns.Actors
protected Vector2 acceleration;
protected bool invuln;
protected float hangCount;
+ protected float previousInput;
public Stats stats;
public int health;
@@ -71,10 +72,32 @@ namespace MontanaJohns.Actors
}
}
- public virtual void Move(float input)
+ public virtual void Move(float input, float maxSpeedModifier = 0f)
{
- var target = new Vector2(input * stats.speedMultiplier * 10, _rigidBody.velocity.y);
- _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
+
+
+ var maxSpeed = stats.maxSpeed + maxSpeedModifier;
+ _rigidBody.AddForce(new Vector2(input * stats.speedMultiplier, 0), ForceMode2D.Impulse);
+
+ if (!isGrappling)
+ {
+ if (input == 0 || input < 0 && previousInput > 0 || input > 0 && previousInput < 0)
+ {
+ var target = new Vector2(0, _rigidBody.velocity.y);
+ _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
+ }
+ }
+
+ if (input < 0 && Mathf.Abs(_rigidBody.velocity.x) > maxSpeed)
+ _rigidBody.velocity = new Vector2(-maxSpeed, _rigidBody.velocity.y);
+ else if (input > 0 && Mathf.Abs(_rigidBody.velocity.x) > maxSpeed)
+ _rigidBody.velocity = new Vector2(maxSpeed, _rigidBody.velocity.y);
+
+ if (IsGrounded() && input == 0)
+ _rigidBody.gravityScale = 0f;
+ else
+ _rigidBody.gravityScale = gravityScale;
+
_animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 1);
isMoving = Mathf.Abs(_rigidBody.velocity.x) > 1;
@@ -94,18 +117,34 @@ namespace MontanaJohns.Actors
transform.GetChild(i).rotation = rot;
}
}
+ previousInput = input;
+ }
+ public virtual void MoveY(float inputX, float inputY, float doNotExceed, float maxSpeedModifier = 0f)
+ {
+ if(_rigidBody.position.y <= doNotExceed)
+ {
+ var maxSpeed = stats.maxSpeed + maxSpeedModifier;
+ _rigidBody.AddForce(new Vector2(0, inputY * stats.speedMultiplier), ForceMode2D.Impulse);
+
+ if (inputY < 0 && Mathf.Abs(_rigidBody.velocity.y) > maxSpeed)
+ _rigidBody.velocity = new Vector2(_rigidBody.velocity.x, -maxSpeed);
+ else if (inputY > 0 && Mathf.Abs(_rigidBody.velocity.y) > maxSpeed)
+ _rigidBody.velocity = new Vector2(_rigidBody.velocity.x, maxSpeed);
+ }
}
- public virtual void MoveY(float input)
+
+ public virtual bool IsGrounded()
{
- var target = new Vector2(_rigidBody.velocity.x, input * stats.speedMultiplier * 10);
- _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f);
+ if (Physics2D.OverlapCircle(groundCheckPoint1.position, 0.2f, groundLayers) || Physics2D.OverlapCircle(groundCheckPoint2.position, 0.2f, groundLayers))
+ return true;
+ return false;
}
public virtual void Jump()
{
if (isGrappling)
Use();
- if(Physics2D.OverlapCircle(groundCheckPoint1.position, 0.2f, groundLayers) || Physics2D.OverlapCircle(groundCheckPoint2.position, 0.2f, groundLayers))
+ if(IsGrounded())
{
jumpCount = stats.maxJumps;
hangCount = hangTime;
@@ -161,7 +200,7 @@ namespace MontanaJohns.Actors
public virtual void Grapple(float xInput, float yInput, Vector2 grapplePoint)
{
Move(xInput);
- MoveY(yInput);
+ MoveY(xInput, yInput, grapplePoint.y);
}
public virtual void TakeDamage(int damage)
diff --git a/Assets/Scripts/Actors/Enemy.cs b/Assets/Scripts/Actors/Enemy.cs
index d7d699e..fb11e45 100644
--- a/Assets/Scripts/Actors/Enemy.cs
+++ b/Assets/Scripts/Actors/Enemy.cs
@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
+using UnityEngine.InputSystem;
namespace MontanaJohns.Actors
{
@@ -10,18 +11,31 @@ namespace MontanaJohns.Actors
protected float attackRate = 0.5f;
protected float nextAttackTime = 0f;
- bool playerSeen;
+ private bool playerSeen;
+ private PlayerInput playerInput;
+ private InputAction jump;
protected override void Awake()
{
base.Awake();
player = GameObject.FindGameObjectWithTag("Player");
+ playerInput = player.GetComponent<PlayerInput>();
+
+ jump = playerInput.currentActionMap.FindAction("Jump");
+ jump.started += context => Jump();
}
// Update is called once per frame
void Update()
{
- if(!playerSeen)
+ CheckHealth();
+ }
+
+ protected override void FixedUpdate()
+ {
+ // Temp override while missing falling logic/animations
+ //base.FixedUpdate();
+ if (!playerSeen)
{
if (Mathf.Abs(player.transform.position.x - transform.position.x) <= 50 && Mathf.Abs(player.transform.position.y - transform.position.y) <= 15)
playerSeen = true;
@@ -31,12 +45,6 @@ namespace MontanaJohns.Actors
MoveTowardsPlayer();
Attack();
}
- CheckHealth();
- }
-
- protected override void FixedUpdate()
- {
- // Temp override while missing falling logic/animations
}
void MoveTowardsPlayer()
@@ -59,6 +67,25 @@ namespace MontanaJohns.Actors
}
}
+ public override void Jump()
+ {
+ if (groundCheckPoint1 == null || groundCheckPoint2 == null) return;
+ if (Physics2D.OverlapCircle(groundCheckPoint1.position, 0.2f, groundLayers) || Physics2D.OverlapCircle(groundCheckPoint2.position, 0.2f, groundLayers))
+ {
+ jumpCount = stats.maxJumps;
+ hangCount = hangTime;
+ }
+ else
+ {
+ hangCount -= Time.deltaTime;
+ }
+ if (jumpCount > 0 && hangCount > 0f)
+ {
+ jumpCount--;
+ _rigidBody.AddForce(Vector2.up * stats.jumpForce);
+ }
+ }
+
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Projectile")
diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs
index 8535a41..4adcfd9 100644
--- a/Assets/Scripts/Actors/Player.cs
+++ b/Assets/Scripts/Actors/Player.cs
@@ -32,7 +32,7 @@ namespace MontanaJohns.Actors
jump.started += context => Jump();
use.started += context => Use();
- attack.started += context => Fire();
+ //attack.started += context => Fire();
cancel.started += context => Cancel();
}
@@ -48,7 +48,13 @@ namespace MontanaJohns.Actors
protected void Update()
{
((IFollowable)this).Follow();
- if(isGrappling)
+ DeathCheck();
+ }
+
+ protected override void FixedUpdate()
+ {
+ base.FixedUpdate();
+ if (isGrappling)
{
base.Grapple(move.ReadValue<Vector2>().x, move.ReadValue<Vector2>().y, (Vector2)grapplePoint);
}
@@ -58,7 +64,6 @@ namespace MontanaJohns.Actors
if (isMoving && !_animator.GetBool("airborn") && !_audio.isPlaying("RunningOnGrass")) _audio.Play("RunningOnGrass");
else if (!isMoving || _animator.GetBool("airborn")) _audio.Stop("RunningOnGrass");
}
- DeathCheck();
}
protected void DeathCheck()
@@ -66,6 +71,8 @@ namespace MontanaJohns.Actors
if(health <= 0)
{
MainCamera.GetComponent<LevelController>().ResetLevel();
+ if (isGrappling)
+ Use();
ResetStats();
health = stats.maxHealth;
transform.position = spawnPoint;
diff --git a/Assets/Scripts/Core/Stats.cs b/Assets/Scripts/Core/Stats.cs
index aac6fe7..29c1804 100644
--- a/Assets/Scripts/Core/Stats.cs
+++ b/Assets/Scripts/Core/Stats.cs
@@ -22,6 +22,7 @@ namespace MontanaJohns.Core
{
[SerializeField] public int maxHealth;
[SerializeField] public float speedMultiplier;
+ [SerializeField] public float maxSpeed;
[SerializeField] public int maxJumps;
[SerializeField] public float jumpForce;
[SerializeField] public int damage;
@@ -35,6 +36,7 @@ namespace MontanaJohns.Core
maxJumps = x.maxJumps + y.maxJumps,
jumpForce = x.jumpForce + y.jumpForce,
damage = x.damage + y.damage,
+ maxSpeed = x.maxSpeed + y.maxSpeed,
};
}
@@ -44,6 +46,7 @@ namespace MontanaJohns.Core
{
maxHealth = 3,
speedMultiplier = 1,
+ maxSpeed = 25f,
maxJumps = 1,
jumpForce = 500f,
damage = 0,
diff --git a/Assets/Scripts/Cursor.cs b/Assets/Scripts/Cursor.cs
index 43b0ea6..be46246 100644
--- a/Assets/Scripts/Cursor.cs
+++ b/Assets/Scripts/Cursor.cs
@@ -8,17 +8,24 @@ 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()
+ private 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);
+ SetCursor(cursorTexture, hotSpot);
else
- UnityEngine.Cursor.SetCursor(null, Vector2.zero, cursorMode);
+ SetCursor(null, hotSpot);
+ }
+
+ private void SetCursor(Texture2D cursorTexture, Vector2 hotSpot)
+ {
+ if(Application.platform == RuntimePlatform.WebGLPlayer)
+ UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.ForceSoftware);
+ else
+ UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto);
}
}
diff --git a/Assets/Scripts/Items/Whip.cs b/Assets/Scripts/Items/Whip.cs
index b482f8d..5e33043 100644
--- a/Assets/Scripts/Items/Whip.cs
+++ b/Assets/Scripts/Items/Whip.cs
@@ -50,6 +50,10 @@ namespace MontanaJohns.Items
StartCoroutine(WhipSmack(collisionGameObject));
}
}
+ else
+ {
+ StartCoroutine(WhipSmack(clickLocation));
+ }
return null;
}
else
@@ -69,5 +73,14 @@ namespace MontanaJohns.Items
Destroy(currentHook);
ropeExists = false;
}
+
+ private IEnumerator WhipSmack(Vector2 location)
+ {
+ currentHook = Instantiate(hookNoSwing, location, Quaternion.identity);
+ FindObjectOfType<AudioManager>().Play("WhipSwoosh");
+ yield return new WaitForSeconds(0.1f);
+ Destroy(currentHook);
+ ropeExists = false;
+ }
}
} \ No newline at end of file
diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs
index 7113fe8..d79bc3b 100644
--- a/Assets/Scripts/LevelController.cs
+++ b/Assets/Scripts/LevelController.cs
@@ -65,7 +65,6 @@ public class LevelController : MonoBehaviour
{
foreach (GameObject obj in gameObjects)
{
- PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction);
Instantiate(obj);
}
}
diff --git a/Assets/Scripts/RespawnPoint.cs b/Assets/Scripts/RespawnPoint.cs
index 6396128..2a1e52e 100644
--- a/Assets/Scripts/RespawnPoint.cs
+++ b/Assets/Scripts/RespawnPoint.cs
@@ -7,12 +7,22 @@ public class RespawnPoint : MonoBehaviour
{
[SerializeField] private Sprite activatedSprite;
+ private AudioManager _audio;
+ private bool activated;
+
+ private void Start()
+ {
+ _audio = FindObjectOfType<AudioManager>();
+ }
+
private void OnTriggerEnter2D(Collider2D collision)
{
- if (collision.gameObject.tag == "Player")
+ if (collision.gameObject.tag == "Player" && !activated)
{
+ activated = true;
collision.gameObject.GetComponent<Player>().spawnPoint = transform.position;
gameObject.GetComponent<SpriteRenderer>().sprite = activatedSprite;
+ _audio.Play("Checkpoint");
}
}
}