Commit fad88ade authored by Tanner Grehawick's avatar Tanner Grehawick

add player model to player prefab, begin refactor

parent c0020750
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -29,14 +29,16 @@ public class Jump : AbstractBehavior {
public void Activate() {
if (collisionState.onGround) {
// ground jump
airJumpsMade = 0;
Vector2 vel = body.velocity;
vel.y = GetJumpVelocity(jumpHeight);
body.velocity = vel;
}
else if (collisionState.onWall) {
// wall jump
Vector2 vel = Vector2.up * GetJumpVelocity(wallJumpHeight);
if (collisionState.onWallLeft) {
if (collisionState.onWallLeft) {
vel += Vector2.right * wallJumpHorizontalSpeed;
inputState.direction = Directions.Right;
}
......@@ -44,10 +46,10 @@ public class Jump : AbstractBehavior {
vel -= Vector2.right * wallJumpHorizontalSpeed;
inputState.direction = Directions.Left;
}
print(vel);
body.velocity = vel;
}
else if (airJumpsMade < airJumpCount) {
// air jump
Vector2 vel = body.velocity;
vel.y = GetJumpVelocity(airJumpHeight);
body.velocity = vel;
......
......@@ -17,8 +17,18 @@ public class ButtonState{
public class InputState : MonoBehaviour {
[HideInInspector]
public Directions direction = Directions.Right;
private Directions _direction;
public Directions direction {
get {
return _direction;
}
set {
_direction = value;
Vector3 scale = transform.localScale;
scale.x = Mathf.Abs(scale.x) * ((int) value);
transform.localScale = scale;
}
}
private Dictionary<Buttons,ButtonState> buttonStates = new Dictionary<Buttons, ButtonState>();
......
......@@ -10,7 +10,6 @@ public class Walk : AbstractBehavior {
public float wallClingTime; //time you will 'stick' to the wall after pressing the opposite direction
public float clingSpeed = 0.1f;
private float xScale;
public float realSpeed;
public bool wallSliding = false;
......@@ -22,7 +21,6 @@ public class Walk : AbstractBehavior {
// Use this for initialization
void Start() {
xScale = body.transform.localScale.x;
}
// Update is called once per frame
......@@ -33,7 +31,7 @@ public class Walk : AbstractBehavior {
rightInt = 0;
leftInt = 0;
if (inputState.GetButtonValue(right))
rightInt = 1;
else
......@@ -52,7 +50,7 @@ public class Walk : AbstractBehavior {
realSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
realSpeed = Mathf.Clamp(realSpeed + speed * (rightInt + leftInt), -speed, speed);
}
else
......@@ -67,9 +65,9 @@ public class Walk : AbstractBehavior {
body.velocity = new Vector2(realSpeed, body.velocity.y);
} else if (!collisionState.onWall || body.velocity.y > 0) //in air and not sliding
{
wallSliding = false;
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
......@@ -86,7 +84,7 @@ public class Walk : AbstractBehavior {
}
}
/*else //air deceleration while pressing nothing, I don't like this - may be removed
{
{
if (airSpeed != 0)
{
airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
......@@ -102,7 +100,7 @@ public class Walk : AbstractBehavior {
leftTime = inputState.GetButtonHoldTime(left);
airSpeed = body.velocity.x;
//only sets a change if the button has been held for a set time
if (rightTime >= wallClingTime)
{
......@@ -132,21 +130,19 @@ public class Walk : AbstractBehavior {
{
body.velocity = new Vector2(body.velocity.x, -clingSpeed);
}
}
//change localScale depending on direction
if (inputState.GetButtonValue (right) && inputState.GetButtonValue (left))
if (inputState.GetButtonValue (right) && inputState.GetButtonValue (left))
{
} else if (inputState.GetButtonValue (right))
} else if (inputState.GetButtonValue (right))
{
inputState.direction = Directions.Right;
body.transform.localScale = new Vector3 (xScale, body.transform.localScale.y, body.transform.localScale.z);
} else if (inputState.GetButtonValue (left))
{
inputState.direction = Directions.Left;
body.transform.localScale = new Vector3 (-xScale, body.transform.localScale.y, body.transform.localScale.z);
}
}
}
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