Commit c73f6fd0 by Alisa Jung
parents 164aff47 2d3f3dcc
...@@ -12,8 +12,13 @@ public class PlayerControl : MonoBehaviour ...@@ -12,8 +12,13 @@ public class PlayerControl : MonoBehaviour
public float groundDamping = 20f; // how fast do we change direction? higher means faster public float groundDamping = 20f; // how fast do we change direction? higher means faster
public float inAirDamping = 5f; public float inAirDamping = 5f;
public float targetJumpHeight = 2f; public float targetJumpHeight = 2f;
public bool canDash = true; public float lastDashStart = float.NegativeInfinity;
public float dashCoolDown = 0.25f; public float currentDashDirection = 0.0f;
public float dashDirection = 1.0f;
public float dashCompletionTime = 0.25f;
public float dashStartSpeed = 20.0f;
public float dashEndSpeed = 8.0f;
public float dashCoolDown = 0.5f;
// public float jumpWaitTime = 2.0; // public float jumpWaitTime = 2.0;
[HideInInspector] [HideInInspector]
...@@ -93,7 +98,28 @@ public class PlayerControl : MonoBehaviour ...@@ -93,7 +98,28 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded) if (_controller.isGrounded)
velocity.y = 0; velocity.y = 0;
if (Input.GetKey (goRightKeyCode))
{
dashDirection = 1.0f;
}
else if (Input.GetKey (goLeftKeyCode))
{
dashDirection = -1.0f;
}
if (canDash () && Input.GetKey (dashKeyCode))
{
lastDashStart = Time.time;
currentDashDirection = dashDirection;
}
if (isDashing ())
{
velocity.x = Mathf.Lerp(currentDashDirection * dashStartSpeed, currentDashDirection * dashEndSpeed, getDashTime() / dashCompletionTime);
velocity.y = 0;
}
else
{
if (Input.GetKey(goRightKeyCode)) if (Input.GetKey(goRightKeyCode))
{ {
normalizedHorizontalSpeed = 1; normalizedHorizontalSpeed = 1;
...@@ -117,21 +143,7 @@ public class PlayerControl : MonoBehaviour ...@@ -117,21 +143,7 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded) //if (_controller.isGrounded)
} }
if (canDash && Input.GetKey(dashKeyCode)) if (Input.GetKey (jumpKeyCode))
{
float direction = Mathf.Sign(transform.localScale.x);
if (normalizedHorizontalSpeed != 0)
{
// player pressed a movement button so prefer the new direction
direction = Mathf.Sign(normalizedHorizontalSpeed);
}
normalizedHorizontalSpeed = 5 * direction;
canDash = false;
Invoke("EnableDash", dashCoolDown);
}
if (Input.GetKeyDown(jumpKeyCode))
{ {
//to avoid DOUBLE JUMP //to avoid DOUBLE JUMP
if (_controller.isGrounded) if (_controller.isGrounded)
...@@ -148,11 +160,6 @@ public class PlayerControl : MonoBehaviour ...@@ -148,11 +160,6 @@ public class PlayerControl : MonoBehaviour
// apply gravity before moving // apply gravity before moving
velocity.y += gravity * Time.deltaTime; velocity.y += gravity * Time.deltaTime;
_controller.move(velocity * Time.deltaTime);
/*==========Power Ups // Bullet management ===*/ /*==========Power Ups // Bullet management ===*/
if (Input.GetKeyDown(shootKeyCode)) if (Input.GetKeyDown(shootKeyCode))
{ {
...@@ -163,12 +170,25 @@ public class PlayerControl : MonoBehaviour ...@@ -163,12 +170,25 @@ public class PlayerControl : MonoBehaviour
coolDown(); coolDown();
} }
} }
}
_controller.move(velocity * Time.deltaTime);
}
private float getDashTime ()
{
return Time.time - lastDashStart;
}
private bool isDashing ()
{
float dashTime = getDashTime();
return 0 <= dashTime && dashTime < dashCompletionTime;
} }
void EnableDash() private bool canDash ()
{ {
canDash = true; return getDashTime() >= dashCompletionTime + dashCoolDown;
} }
/*==========Power Ups // Bullet management ===*/ /*==========Power Ups // Bullet management ===*/
......
using UnityEngine;
using System.Collections;
public class Spikes : MonoBehaviour {
float damage; //the amount of damage the spikes make.
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player")
{
//TODO: do damage
}
}
}
fileFormatVersion: 2
guid: 6420b29453e1bf744941e7bec3f7d443
timeCreated: 1433438590
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -4,18 +4,30 @@ using System.Collections; ...@@ -4,18 +4,30 @@ using System.Collections;
public class Trap : MonoBehaviour { public class Trap : MonoBehaviour {
public int damagePoints = 10; public int damagePoints = 10;
public float respawnTime = 5.0f;
// used to store the position while the trap is deactivated
private Vector2 realPosition;
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
if (other.tag == "Player") if (other.tag == "Player")
{ {
other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints); other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
destroyTrap();
} }
} }
public void destroyTrap() public void destroyTrap()
{ {
realPosition = transform.position;
transform.position = new Vector2(100, 100); transform.position = new Vector2(100, 100);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = realPosition;
} }
} }
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