blocking in some more tile stuff!

This commit is contained in:
allylikesfrogs
2023-05-06 12:25:29 -07:00
parent 075b140ac1
commit 09758c732c
4 changed files with 95751 additions and 1061 deletions

View File

@@ -57,8 +57,8 @@ public class PlayerBehavior : MonoBehaviour
AudioSource audioSource;
void Awake()
{ // initialize
void Awake() {
// initialize
_rb = GetComponent<Rigidbody2D>();
gameUI = GameObject.FindGameObjectWithTag("GameUICanvas").GetComponent<GameUIController>();
@@ -72,54 +72,44 @@ public class PlayerBehavior : MonoBehaviour
playerIsAlive = true;
}
void Start()
{
void Start() {
gameUI.UpdateInstrumentUI();
currentDash = dashTime;
}
void Update()
{
if (playerIsAlive)
{
if (this.cymbalActiveTime < 0)
{
void Update() {
if (playerIsAlive) {
if (this.cymbalActiveTime < 0) {
this.gameUI.ToggleCymbal(true);
}
this.cymbalActiveTime -= Time.deltaTime;
// throw tambourine
unlockedTambourine = StateController.Instance.HasTambourine();
if (playerInput.actions["ThrowTambourine"].WasPressedThisFrame())
{
if (playerInput.actions["ThrowTambourine"].WasPressedThisFrame()) {
ThrowTambourine();
}
// grapple
tambourine = GameObject.FindGameObjectWithTag("tambourine");
if (playerInput.actions["Grapple"].WasPressedThisFrame())
{
if (playerInput.actions["Grapple"].WasPressedThisFrame()) {
AttemptGrapple();
}
if (playerInput.actions["Grapple"].WasReleasedThisFrame() && grapplingRope.isGrappling)
{
if (playerInput.actions["Grapple"].WasReleasedThisFrame() && grapplingRope.isGrappling) {
LetGoOfGrapple();
}
// clarinet
unlockedClarinet = StateController.Instance.HasClarinet();
if (unlockedClarinet)
{
if (playerInput.actions["ClarinetDive"].WasPressedThisFrame() && !isInWater && !playerController.IsGrounded() && !isDash)
{
if (unlockedClarinet) {
if (playerInput.actions["ClarinetDive"].WasPressedThisFrame() && !isInWater && !playerController.IsGrounded() && !isDash) {
isDash = true;
this.gameUI.ToggleClarinet(false);
playerInput.DeactivateInput();
currentDash = 0.0f;
}
if (!playerController.IsGrounded() && isDash && (currentDash < dashTime))
{
if (!playerController.IsGrounded() && isDash && (currentDash < dashTime)) {
if (!forceAdded) {
dashVec = new Vector2(1f * forward, -1f) * dashForce;
_rb.AddForce(dashVec, ForceMode2D.Impulse);
@@ -128,8 +118,8 @@ public class PlayerBehavior : MonoBehaviour
currentDash += Time.deltaTime;
}
else if ((currentDash >= dashTime)) // dash ends
{
else if ((currentDash >= dashTime)) {
// dash ends
if (!isInWater) {
isDash = false;
this.gameUI.ToggleClarinet(true);
@@ -150,10 +140,8 @@ public class PlayerBehavior : MonoBehaviour
}
}
if (StateController.Instance.HasCymbal())
{
if (this.playerInput.actions["CymbalCrash"].WasPressedThisFrame())
{
if (StateController.Instance.HasCymbal()) {
if (this.playerInput.actions["CymbalCrash"].WasPressedThisFrame()) {
// Play the sound
this.gameUI.ToggleCymbal(false);
// this.audioSource.clip = cymbalSound;
@@ -170,35 +158,28 @@ public class PlayerBehavior : MonoBehaviour
}
}
void Animate()
{
void Animate() {
// start walking
if (playerInput.actions["Move"].WasPressedThisFrame())
{
if (playerInput.actions["Move"].WasPressedThisFrame()) {
animator.SetBool("Walking", true);
}
// return to idle animation
if (playerInput.actions["Move"].WasReleasedThisFrame())
{
if (playerInput.actions["Move"].WasReleasedThisFrame()) {
animator.SetBool("Walking", false);
}
}
void OnMove(InputValue value)
{
if (playerIsAlive)
{
void OnMove(InputValue value) {
if (playerIsAlive) {
_hInput = value.Get<Vector2>().x;
if (_hInput < 0)
{
if (forward != -1)
{ // if character hasnt already flipped
if (_hInput < 0) {
if (forward != -1) {
// if character hasnt already flipped
FlipRenderer();
}
forward = -1;
}
else if (_hInput > 0)
{
else if (_hInput > 0) {
if (forward != 1)
{ // if character hasnt already flipped
FlipRenderer();
@@ -209,69 +190,54 @@ public class PlayerBehavior : MonoBehaviour
}
void FlipRenderer()
{
void FlipRenderer() {
GetComponent<SpriteRenderer>().flipX = !GetComponent<SpriteRenderer>().flipX;
}
void ThrowTambourine()
{
if (unlockedTambourine && hasTambourine && !grapplingRope.isGrappling)
{
void ThrowTambourine() {
if (unlockedTambourine && hasTambourine && !grapplingRope.isGrappling) {
launcher.ThrowTambourine(forward);
SetHasTambourine(false);
}
}
public void SetHasTambourine(bool state)
{
public void SetHasTambourine(bool state) {
hasTambourine = state;
gameUI.ToggleTambourine(state);
}
void AttemptGrapple()
{
if (tambourine != null)
{ // grapple to tambourine
if (!grapplingRope.isGrappling && tambourine.GetComponent<TambourineBehavior>().pinned)
{
void AttemptGrapple() {
if (tambourine != null) { // grapple to tambourine
if (!grapplingRope.isGrappling && tambourine.GetComponent<TambourineBehavior>().pinned) {
grapplingGun.GrappleToTambourine(tambourine);
grapplingRope.isGrappling = true;
}
}
else
{
if (grappleSurface != null)
{
else {
if (grappleSurface != null) {
grapplingGun.GrappleToSurface(grappleSurface.transform.position);
grapplingRope.isGrappling = true;
}
}
}
void LetGoOfGrapple()
{
void LetGoOfGrapple() {
bool currentlyPaused = StateController.Instance.isPaused;
if (grapplingRope.isGrappling && !currentlyPaused)
{
if (grapplingRope.isGrappling && !currentlyPaused) {
print("currently paused is " + currentlyPaused + ", releasing grapple");
if (tambourine != null)
{
if (tambourine != null) {
tambourine.GetComponent<TambourineBehavior>().DestroySelf();
}
grapplingGun.ReleaseGrapple();
}
}
void Bounce()
{
void Bounce() {
Vector2 reflect;
if (Mathf.Abs(saveVelocity.y) < 1f && hasBounced)
{
if (Mathf.Abs(saveVelocity.y) < 1f && hasBounced) {
reflect = Vector2.zero;
}
else
{
else {
reflect = new Vector2(saveVelocity.x * reflectForce, -(saveVelocity.y) * reflectForce);
//reflect = new Vector2(saveVelocity.x * 1.1f, -(saveVelocity.y) * reflectForce);
hasBounced = true;
@@ -281,57 +247,46 @@ public class PlayerBehavior : MonoBehaviour
isDash = false;
}
void Water()
{
void Water() {
print("water dash " + isDash);
if(isDash)
{
if(isDash) {
saveVelocity = _rb.velocity / velocityCut;
if (isDash) {
dashVec = new Vector2(1f * forward, -1f) * (dashForce / velocityCut);
_rb.AddForce(dashVec, ForceMode2D.Force);
}
}
else
{
else {
playerController.FloatGravity(waterGravity);
}
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
void OnTriggerEnter2D(Collider2D col) {
if (col.tag == "grappleSurface") {
grappleSurface = col.gameObject;
}
else if (col.tag == "instaDeath")
{
else if (col.tag == "instaDeath") {
print("player fell in spikes");
StartCoroutine(DestroyPlayer());
}
else if (col.tag == "spawnPoint")
{
else if (col.tag == "spawnPoint") {
StateController.Instance.spawnPoint.GetComponent<SpawnPointBehavior>().DeactivateSpawnPoint();
col.GetComponent<SpawnPointBehavior>().ActivateSpawnPoint();
}
else if (col.tag == "Trumpet")
{
else if (col.tag == "Trumpet") {
this.playerController.in_range = true;
this.playerController.enemy = col.transform.parent.gameObject;
}
else if (col.tag == "water")
{
else if (col.tag == "water") {
isInWater = true;
Water();
}
else if (col.tag == "bouncePad")
{
else if (col.tag == "bouncePad") {
// Assign the player's velocity to zero so that the player can
// bounce on the same jump pad
this.playerController.RB.velocity = Vector2.zero;
Bouncepad pad = col.GetComponent<Bouncepad>();
switch (pad.Direction())
{
switch (pad.Direction()) {
case Bouncepad.Facing.Left:
this.playerController.RB.AddForce(
new Vector2(-pad.bounceForce, pad.verticalModifier * pad.bounceForce),
@@ -348,19 +303,15 @@ public class PlayerBehavior : MonoBehaviour
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
void OnTriggerExit2D(Collider2D col) {
if (col.tag == "grappleSurface") {
grappleSurface = null;
}
else if (col.tag == "Trumpet")
{
else if (col.tag == "Trumpet") {
this.playerController.in_range = false;
this.playerController.enemy = null;
}
else if (col.tag == "water")
{
else if (col.tag == "water") {
isInWater = false;
isDash = false;
hasBounced = false;
@@ -370,26 +321,20 @@ public class PlayerBehavior : MonoBehaviour
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "ProjectileEnemy")
{
if (collision.transform.position.y < transform.position.y)
{
void OnCollisionEnter2D(Collision2D collision) {
if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "ProjectileEnemy") {
if (collision.transform.position.y < transform.position.y) {
_rb.AddForce(Vector2.up * 8, ForceMode2D.Impulse);
collision.gameObject.GetComponent<EnemyPatrol>().DefeatEnemy();
}
else
{
else {
StartCoroutine(DestroyPlayer());
print("enemy defeated player");
}
}
else if (collision.gameObject.tag == "Projectile")
{
else if (collision.gameObject.tag == "Projectile") {
Destroy(collision.gameObject);
if (this.cymbalActiveTime > 0)
{
if (this.cymbalActiveTime > 0) {
Vector2 projVel = collision.gameObject.GetComponent<Rigidbody2D>().velocity;
collision.gameObject.GetComponent<Rigidbody2D>().velocity =
new Vector2(
@@ -397,30 +342,24 @@ public class PlayerBehavior : MonoBehaviour
-projVel.y
);
}
else
{
else {
StartCoroutine(DestroyPlayer());
}
}
//stupid stuff for claude's house
else if (collision.gameObject.tag == "SirJacques")
{
else if (collision.gameObject.tag == "SirJacques") {
Destroy(collision.gameObject);
}
else if (collision.gameObject.tag == "Door")
{
else if (collision.gameObject.tag == "Door") {
StateController.Instance.RespawnPlayer();
}
else if (collision.gameObject.tag == "bouncy")
{
else if (collision.gameObject.tag == "bouncy") {
Bounce();
}
}
IEnumerator DestroyPlayer()
{
if (playerIsAlive)
{
IEnumerator DestroyPlayer() {
if (playerIsAlive) {
print("destroyPlayer called");
playerIsAlive = false;
audioSource.clip = deathSound;
@@ -435,15 +374,13 @@ public class PlayerBehavior : MonoBehaviour
// this.stateController.SetDeathCanvasActive(true);
if (grapplingRope.isGrappling)
{
if (grapplingRope.isGrappling) {
LetGoOfGrapple();
}
// destroy all tambourines
GameObject[] currentTambourines = GameObject.FindGameObjectsWithTag("tambourine");
foreach (GameObject tambourine in currentTambourines)
{
foreach (GameObject tambourine in currentTambourines) {
tambourine.GetComponent<TambourineBehavior>().DestroySelf();
// Destroy(tambourine);
}