Commit 238c3b61 authored by Shellby Grehawick's avatar Shellby Grehawick
Browse files

Merge branch 'master' into 'gameManager'

# Conflicts:
#   Assets/Scripts/Birb.meta
#   ProjectSettings/ProjectVersion.txt
parents 21b0840e f7c174b8
fileFormatVersion: 2
guid: 507f9015dd3807547896c3c9d9e8a4e1
folderAsset: yes
timeCreated: 1486689690
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 120aaee2a73d6364d87bc0095a298b23
timeCreated: 1486689701
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,4 +6,4 @@ licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
assetBundleVariant:
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sets dash velocity and smoothly decelerates to a minimum velocity
public class Dash : AbstractBehavior {
private float lastDash;
public float coolDown = 1f;
public float dashforce = 5;
public float holdTime = 0.4f;
public float minVelocity = 0.5f;
// Should be called every frame
public void DashCheck() {
// Button pressed, not in cooldown, and not on wall
if (inputState.GetButtonValue(inputButtons[0]) && Time.time > lastDash && !collisionState.onWall) {
StartCoroutine(DoDash());
}
}
// Dash
IEnumerator DoDash() {
// Cooldown
lastDash = Time.time + coolDown;
// Set initial velocity
body.velocity = transform.right * dashforce;
// Disable gravity
float initialGrav = body.gravityScale;
body.gravityScale = 0;
// Decelerate
for (float i = 0; i < holdTime; i += Time.deltaTime) {
// Calculate velocity
Vector2 targetVel = (transform.right * dashforce) * (1 - (i / holdTime));
if(body.velocity.magnitude < minVelocity || collisionState.onWall) {
// Velocity is low enough or collision with wall
Debug.Log("Stopped");
break;
}
// Apply velocity
body.velocity = targetVel;
// Wait
yield return new WaitForEndOfFrame();
}
// Restore gravity
body.gravityScale = initialGrav;
}
}
fileFormatVersion: 2
guid: f246b93f516db6d4881da268c3588e75
timeCreated: 1486687030
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -41,7 +41,7 @@ public class InputAxisState{
}
}
public class InputManager : MonoBehaviour {
public class InputManager : SingletonBehaviour<InputManager> {
public InputAxisState[] inputs;
public InputState inputState;
......
......@@ -10,12 +10,14 @@ using System.Collections.Generic;
*/
public class ButtonState{
public bool last;
public bool value;
public float holdTime = 0;
}
public class InputState : MonoBehaviour {
[HideInInspector]
public Directions direction = Directions.Right;
private Dictionary<Buttons,ButtonState> buttonStates = new Dictionary<Buttons, ButtonState>();
......@@ -25,7 +27,7 @@ public class InputState : MonoBehaviour {
buttonStates.Add (key, new ButtonState ());
}
var state = buttonStates[key];
state.last = state.value;
if(state.value && !value){//key has been released
state.holdTime = 0;
}else if(state.value && value){//key is being held down
......@@ -34,6 +36,26 @@ public class InputState : MonoBehaviour {
state.value = value;
}
public bool GetButtonPressed(Buttons button) {
if (buttonStates.ContainsKey(button)) {
ButtonState state = buttonStates[button];
return state.value && !state.last;
}
else {
return false;
}
}
public bool GetButtonReleased(Buttons button) {
if (buttonStates.ContainsKey(button)) {
ButtonState state = buttonStates[button];
return !state.value && state.last;
}
else {
return false;
}
}
public bool GetButtonValue(Buttons key){
if (buttonStates.ContainsKey (key)) {
return buttonStates [key].value;
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walk : AbstractBehavior {
public int speed;
private float airSpeed;
public float airAcceleration;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
Buttons left = inputButtons[0];
Buttons right = inputButtons[1];
int rightInt = 0;
int leftInt = 0;
if (inputState.GetButtonValue(right))
rightInt = 1;
else
rightInt = 0;
if (inputState.GetButtonValue(left))
leftInt = -1;
else
leftInt = 0;
if (collisionState.onGround)
{
body.velocity = new Vector2(speed * (rightInt + leftInt), body.velocity.y);
} else
{
airSpeed = body.velocity.x;
if (inputState.GetButtonValue(right) || inputState.GetButtonValue(left))
{
airSpeed = Mathf.Clamp(airSpeed + airAcceleration * (rightInt + leftInt), -speed, speed);
}
else
{
if (airSpeed != 0) {
airSpeed += (-1) * Mathf.Sign(airSpeed) * airAcceleration;
if (Mathf.Abs(airSpeed) < airAcceleration)
airSpeed = 0;
}
}
body.velocity = new Vector2(airSpeed, body.velocity.y);
}
}
}
fileFormatVersion: 2
guid: fffc5061cced9b8498b9146e0712c85e
timeCreated: 1486687201
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hazard : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
other.GetComponent<Birb>().Die ();
}
}
}
fileFormatVersion: 2
guid: 763513e1173772545a16c3cb1a4d40d5
timeCreated: 1486688527
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WinTrigger : MonoBehaviour {
//checks for incoming collision
public void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.name == "Player") //ensuring it's the player
{
//tell manager it has won
GameEditor.Win();
//Debug.Log("Victory Achieved");
}
}
}
fileFormatVersion: 2
guid: 79af5acd6c178454090143472b307c76
timeCreated: 1486692331
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
m_EditorVersion: 5.5.1f1
m_EditorVersion: 5.5.1f1
\ No newline at end of file
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