From 4ecd89e406f5f1efb2bb4a0a82aebe4306e6c924 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 2 Feb 2020 15:00:34 -0500 Subject: [PATCH] added button animation --- Assets/Coffee.cs | 18 +++++++++++ Assets/Coffee.cs.meta | 11 +++++++ Assets/Model/EventControlTile.cs | 5 ++- Assets/Prefabs/Coffee.prefab | 4 +-- Assets/Scenes/LevelOne.unity | 53 +++++++++++++++++++++++++++++--- Assets/Scripts/EventControls.cs | 18 ++++++++++- Assets/Scripts/Player.cs | 16 ++++++++++ 7 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 Assets/Coffee.cs create mode 100644 Assets/Coffee.cs.meta diff --git a/Assets/Coffee.cs b/Assets/Coffee.cs new file mode 100644 index 0000000..ae54775 --- /dev/null +++ b/Assets/Coffee.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Coffee : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Coffee.cs.meta b/Assets/Coffee.cs.meta new file mode 100644 index 0000000..b767c82 --- /dev/null +++ b/Assets/Coffee.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b72c6073f9135a4894350d4cde51a76 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Model/EventControlTile.cs b/Assets/Model/EventControlTile.cs index 6b87ac1..93a3e7e 100644 --- a/Assets/Model/EventControlTile.cs +++ b/Assets/Model/EventControlTile.cs @@ -12,16 +12,19 @@ namespace Assets.Model { public KeyCode keyCode; public Tile tile; + public Tile pressedTile; public Tile successTile; public Tile failTile; public Vector3Int position; public bool isPlusTile; public bool isPerformed; + public bool isPressed; - public EventControlTile(KeyCode keyCode, Tile tile, Tile successTile, Tile failTile, Vector3Int position, bool isPlusTile = false) + public EventControlTile(KeyCode keyCode, Tile tile, Tile pressedTile, Tile successTile, Tile failTile, Vector3Int position, bool isPlusTile = false) { this.keyCode = keyCode; this.tile = tile; + this.pressedTile = pressedTile; this.successTile = successTile; this.failTile = failTile; this.position = position; diff --git a/Assets/Prefabs/Coffee.prefab b/Assets/Prefabs/Coffee.prefab index 7249181..af6d425 100644 --- a/Assets/Prefabs/Coffee.prefab +++ b/Assets/Prefabs/Coffee.prefab @@ -94,14 +94,14 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} - oldSize: {x: 0.32, y: 0.4} + oldSize: {x: 2, y: 2.5} newSize: {x: 1.5, y: 1.5} adaptiveTilingThreshold: 0.5 drawMode: 0 diff --git a/Assets/Scenes/LevelOne.unity b/Assets/Scenes/LevelOne.unity index 1cebe99..c407b4f 100644 --- a/Assets/Scenes/LevelOne.unity +++ b/Assets/Scenes/LevelOne.unity @@ -175,6 +175,13 @@ MonoBehaviour: - {fileID: 11400000, guid: bfe2d3906a2ea9a459088706930d84a6, type: 2} - {fileID: 11400000, guid: eb62aa8f449e99a499ed3a9dde109158, type: 2} - {fileID: 11400000, guid: 3892d3fd4f09d3546a9c0fa91c23804c, type: 2} + pressedTiles: + - {fileID: 11400000, guid: ae6e7a8b9fa2433448a66da4090e310c, type: 2} + - {fileID: 11400000, guid: ccb4ffcdbc096b448881b3a12ed1bfce, type: 2} + - {fileID: 11400000, guid: f3b494a9dede1e34cbf612b95ee136ec, type: 2} + - {fileID: 11400000, guid: a6df840757ade3b4b91133bd128a4ca7, type: 2} + - {fileID: 11400000, guid: 8e4de2f5a5925ad47b2e5135946daee7, type: 2} + - {fileID: 11400000, guid: 8a9fda06d52381844891193f6ed6bb07, type: 2} successTiles: - {fileID: 11400000, guid: c2678bd928e9a0943ad5fadb602db819, type: 2} - {fileID: 11400000, guid: db1d65b4da209fa489ba3d7582dbff24, type: 2} @@ -190,7 +197,7 @@ MonoBehaviour: - {fileID: 11400000, guid: aa0847f2d07a5de409fea20d9eef8f98, type: 2} - {fileID: 11400000, guid: 4a575a19b6cd8a140959a1461963418f, type: 2} plusTile: {fileID: 11400000, guid: ee14e10b7ac07bd449e0f1d5ea99eb42, type: 2} - framesPerControlTile: 8 + framesPerControlTile: 3 nextControlYOffset: 2 tileMapClearDelayInSeconds: 0.5 --- !u!483693784 &1491656 @@ -397,6 +404,11 @@ PrefabInstance: propertyPath: m_Size.y value: 1.3199286 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -410,12 +422,12 @@ PrefabInstance: - target: {fileID: 7123021364386132083, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_LocalPosition.x - value: 133.11 + value: 132.4 objectReference: {fileID: 0} - target: {fileID: 7123021364386132083, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_LocalPosition.y - value: -13.99 + value: -18.2 objectReference: {fileID: 0} - target: {fileID: 7123021364386132083, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} @@ -462,7 +474,8 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 1518483160148691188, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} --- !u!1001 &170428179 PrefabInstance: @@ -486,6 +499,11 @@ PrefabInstance: propertyPath: m_SortingLayer value: 1 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -1420,6 +1438,11 @@ PrefabInstance: propertyPath: m_SortingLayer value: 1 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -1945,6 +1968,11 @@ PrefabInstance: propertyPath: m_Size.y value: 1.3281136 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -47402,6 +47430,11 @@ PrefabInstance: propertyPath: m_SortingLayer value: 1 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -47631,6 +47664,11 @@ PrefabInstance: propertyPath: m_Size.y value: 1.31913 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name @@ -47727,7 +47765,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1671840916} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 22.5, y: -10, z: 0} + m_LocalPosition: {x: -10.5, y: 4, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1008122163} @@ -48934,6 +48972,11 @@ PrefabInstance: propertyPath: m_Size.y value: 1.31913 objectReference: {fileID: 0} + - target: {fileID: 5520736153122788072, guid: 2ccb08e2c4b8851498f8ecbf1a873146, + type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6870250841519595495, guid: 2ccb08e2c4b8851498f8ecbf1a873146, type: 3} propertyPath: m_Name diff --git a/Assets/Scripts/EventControls.cs b/Assets/Scripts/EventControls.cs index 91f7087..94281d6 100644 --- a/Assets/Scripts/EventControls.cs +++ b/Assets/Scripts/EventControls.cs @@ -11,6 +11,7 @@ public class EventControls : MonoBehaviour [SerializeField] private Camera camera; [SerializeField] private GameObject music; [SerializeField] private List tiles; + [SerializeField] private List pressedTiles; [SerializeField] private List successTiles; [SerializeField] private List failTiles; [SerializeField] private Tile plusTile; @@ -43,6 +44,7 @@ public class EventControls : MonoBehaviour private EventControlTile currentEventControl; private bool isInBattle = false; private bool hasFailed = false; + private int buttonPressAnimationAccumalator = 0; private Collider2D currentPlayerCollider; private Collider2D currentEnemyCollider; @@ -177,6 +179,18 @@ public class EventControls : MonoBehaviour if (currentEventControl == null) currentEventControl = eventControlTilesInCycle.First(x => !x.isPlusTile && !x.isPerformed); + else + { + if (buttonPressAnimationAccumalator >= framesPerControlTile) + { + tilemap.SetTile(currentEventControl.position, currentEventControl.isPressed ? currentEventControl.pressedTile : + currentEventControl.tile); + currentEventControl.isPressed = !currentEventControl.isPressed; + buttonPressAnimationAccumalator = 0; + } + else + buttonPressAnimationAccumalator++; + } if (Input.GetKeyDown(currentEventControl.keyCode)) { @@ -203,7 +217,7 @@ public class EventControls : MonoBehaviour return; } - else if (eventCycleAccumalator >= eventCycleInSeconds * framesPerSecond) + else if (eventCycleAccumalator >= eventCycleInSeconds * framesPerSecond * player.GetStaminaDifficultyFactor()) { eventTriggered = false; isInBattle = false; @@ -294,6 +308,7 @@ public class EventControls : MonoBehaviour return new EventControlTile(TileToKeyMappings.TileToKey[randomNumber], tiles[randomNumber], + pressedTiles[randomNumber], successTiles[randomNumber], failTiles[randomNumber], position); @@ -305,6 +320,7 @@ public class EventControls : MonoBehaviour plusTile, null, null, + null, position, true); } diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 7bac19c..2b26916 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -115,6 +115,7 @@ public class Player : MonoBehaviour private void Hurt() { + currentHealth = 3; // TODO: REMOVE! currentHealth -= currentHealth > 0 ? 1 : 0; healthBar.size = new Vector2(1.5f * currentHealth, this.healthBar.size.y); @@ -181,6 +182,16 @@ public class Player : MonoBehaviour { rigidBody.velocity = new Vector2(actualRunSpeed * -1, rigidBody.velocity.y); } + + // Run + if (Input.GetKeyUp(KeyCode.RightArrow)) + { + rigidBody.velocity = new Vector2(0, rigidBody.velocity.y); + } + else if (Input.GetKeyUp(KeyCode.LeftArrow)) + { + rigidBody.velocity = new Vector2(0, rigidBody.velocity.y); + } } private bool IsPlayerOnGround() @@ -289,4 +300,9 @@ public class Player : MonoBehaviour isHurt = true; Hurt(); } + + public float GetStaminaDifficultyFactor() + { + return currentStamina / (startStamina * 1f); + } }