Commit 8577a09b authored by Joshua C Derossett's avatar Joshua C Derossett

Merge branch 'master' into 'WallSliding'

# Conflicts:
#   ProjectSettings/ProjectVersion.txt
parents 6e910a70 95005fdc
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:
fileFormatVersion: 2
guid: a58ae0e00797d794297ccb4228d903bf
folderAsset: yes
timeCreated: 1487292663
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: fa60ffd6264804b43bc03430e8dd86b1
timeCreated: 1487292666
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d31ebdd80916bea45bd33409fe585333
folderAsset: yes
timeCreated: 1486686817
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
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;
private bool _isDashing = false;
private Transform dashMeter;
// Call to check if currently dashing
public bool isDashing
{
get { return _isDashing; }
private set
{
_isDashing = value;
}
}
void Start() {
dashMeter = GameObject.FindGameObjectWithTag("DashMeter").transform;
}
// 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());
}
UpdateUI();
}
void UpdateUI() {
float progress = 1 - ((lastDash - Time.time)/coolDown);
dashMeter.localScale = new Vector2(Mathf.Clamp01(progress), dashMeter.localScale.y);
}
// Dash
IEnumerator DoDash() {
// Cooldown
lastDash = Time.time + coolDown;
// Is dashing
isDashing = true;
// 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
break;
}
// Apply velocity
body.velocity = targetVel;
// Wait
yield return new WaitForEndOfFrame();
}
// Restore gravity
body.gravityScale = initialGrav;
// Is not dashing
isDashing = false;
}
public void DashIgnoringCooldown() {
StartCoroutine(DoDash());
}
}
fileFormatVersion: 2
guid: f246b93f516db6d4881da268c3588e75
timeCreated: 1486687030
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 GameManager : SingletonBehaviour<GameManager>
{
private bool _isPaused;
//Manages game state. Pause, death, win, and changing levels.
public bool isPaused
{
get
{
return _isPaused;
}
set
{
_isPaused = value;
if (isPaused)
{
//set timescale back to normal
isPaused = false;
Debug.Log("Game is unpaused");
}
else
{
//set timescale to zero
isPaused = true;
Debug.Log("Game is paused");
}
}
}
public void Fail()
{
Debug.Log("You have died");
}
public void Win()
{
Debug.Log("You won!");
}
public void ChangeLevel()
{
Debug.Log("Changing level state");
}
}
fileFormatVersion: 2
guid: cad3061263b98c140a9a3a49d70204c9
timeCreated: 1486686808
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
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
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
m_EditorVersion: 5.5.0f3
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