Commit 49af132d authored by Eby Komenan's avatar Eby Komenan

modified: Assets/Scripts/Birb/Jump.cs

	modified:   Assets/Scripts/Util/HazardSlow.cs
parent 95935f37
using UnityEngine; using UnityEngine;
using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -14,7 +15,6 @@ public class Jump : AbstractBehavior { ...@@ -14,7 +15,6 @@ public class Jump : AbstractBehavior {
get{return jumpRequested;} get{return jumpRequested;}
} }
bool jumpRequested; bool jumpRequested;
bool jumpBlocked;
int airJumpsMade = 0; int airJumpsMade = 0;
Walk walk; Walk walk;
...@@ -27,6 +27,8 @@ public class Jump : AbstractBehavior { ...@@ -27,6 +27,8 @@ public class Jump : AbstractBehavior {
void Update() { void Update() {
if (!jumpRequested && inputState.GetButtonPressed(inputButtons[0])) { if (!jumpRequested && inputState.GetButtonPressed(inputButtons[0])) {
jumpRequested = true; jumpRequested = true;
if(jumpHeight==0)
animator.SetTrigger("jump failed");
} }
float jumpState; float jumpState;
Vector2 vel = body.velocity; Vector2 vel = body.velocity;
...@@ -36,7 +38,7 @@ public class Jump : AbstractBehavior { ...@@ -36,7 +38,7 @@ public class Jump : AbstractBehavior {
jumpState = 0; jumpState = 0;
} }
jumpState = Mathf.Sqrt(jumpState); jumpState = Mathf.Sqrt(jumpState);
animator.SetFloat("jump state", jumpState); animator.SetFloat ("jump state", jumpState);
// reset air jumps when on ground // reset air jumps when on ground
if (collisionState.onGround) { if (collisionState.onGround) {
airJumpsMade = 0; airJumpsMade = 0;
...@@ -44,7 +46,7 @@ public class Jump : AbstractBehavior { ...@@ -44,7 +46,7 @@ public class Jump : AbstractBehavior {
} }
void FixedUpdate() { void FixedUpdate() {
if (jumpRequested) { if (jumpRequested) {
Activate(); Activate();
jumpRequested = false; jumpRequested = false;
} }
...@@ -53,11 +55,6 @@ public class Jump : AbstractBehavior { ...@@ -53,11 +55,6 @@ public class Jump : AbstractBehavior {
public void Activate() { public void Activate() {
if (collisionState.onGround) { if (collisionState.onGround) {
// ground jump // ground jump
<<<<<<< HEAD
airJumpsMade = 0;
=======
>>>>>>> d984067ea55e6a0191c6cb7033212e7268955de1
Vector2 vel = body.velocity; Vector2 vel = body.velocity;
vel.y = GetJumpVelocity(jumpHeight); vel.y = GetJumpVelocity(jumpHeight);
body.velocity = vel; body.velocity = vel;
...@@ -89,8 +86,9 @@ public class Jump : AbstractBehavior { ...@@ -89,8 +86,9 @@ public class Jump : AbstractBehavior {
return Mathf.Sqrt(-2 * gravity * height); return Mathf.Sqrt(-2 * gravity * height);
} }
void OnCollisionEnter2D(Collision2D other) void OnCollisionEnter2D(Collision2D other)
{ {
airJumpsMade = 0; airJumpsMade = 0;
} }
}
}
\ No newline at end of file
...@@ -6,10 +6,15 @@ public class HazardSlow : AbstractBehavior { ...@@ -6,10 +6,15 @@ public class HazardSlow : AbstractBehavior {
//Remember to give prefabs that have this script a "slowHazard" tag. //Remember to give prefabs that have this script a "slowHazard" tag.
float slowfactor; float slowfactor;
public float slowedSpeed; public float slowedSpeed;
float jumpHeightHold; //Holds the jumpHeight current value.
float wallJumpHeightHold; //Holds the wallJumpHeight current value.
bool valuesHeld;
void Awake() void Awake()
{ {
slowfactor = 2.0f; slowfactor = 2.0f;
valuesHeld = false;
} }
void OnTriggerEnter2D(Collider2D other){ void OnTriggerEnter2D(Collider2D other){
...@@ -17,7 +22,15 @@ public class HazardSlow : AbstractBehavior { ...@@ -17,7 +22,15 @@ public class HazardSlow : AbstractBehavior {
if(other.tag=="Player"){ if(other.tag=="Player"){
other.GetComponent<Walk>().speed /= slowfactor; other.GetComponent<Walk>().speed /= slowfactor;
other.GetComponent<Jump> ().enabled = false; //other.GetComponent<Jump> ().enabled = false;
if (!valuesHeld) {
jumpHeightHold = other.GetComponent<Jump> ().jumpHeight;
wallJumpHeightHold = other.GetComponent<Jump> ().wallJumpHeight;
valuesHeld = true;
}
other.GetComponent<Jump> ().jumpHeight = 0;
other.GetComponent<Jump> ().wallJumpHeight = 0;
} }
} }
void OnTriggerExit2D(Collider2D other){ void OnTriggerExit2D(Collider2D other){
...@@ -25,7 +38,9 @@ public class HazardSlow : AbstractBehavior { ...@@ -25,7 +38,9 @@ public class HazardSlow : AbstractBehavior {
if(other.tag=="Player"){ if(other.tag=="Player"){
other.GetComponent<Walk>().speed *= slowfactor; other.GetComponent<Walk>().speed *= slowfactor;
other.GetComponent<Jump>().enabled = true; //other.GetComponent<Jump>().enabled = true;
other.GetComponent<Jump> ().jumpHeight = jumpHeightHold;
other.GetComponent<Jump> ().wallJumpHeight = wallJumpHeightHold;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment