From 3afffa15756eabc8e06f308598524034d343633f Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Mon, 16 Sep 2019 16:42:11 +1000 Subject: [PATCH] -Updated water to new system + Jumping has a bounce effect --- Assets/Plugins.meta | 8 ---- Assets/Prefabs/Blocks/Cube_Water.prefab | 38 ++++++------------- Assets/Scripts/Character.cs | 15 ++++++++ Assets/Scripts/LevelBlocks/ActiveBlock.cs | 27 +++++++++++-- Assets/Scripts/LevelBlocks/Block.cs | 14 +++---- Assets/Scripts/LevelBlocks/Water.cs | 32 +++++++++++++--- Assets/Scripts/Logic/BlockReader.cs | 29 +++++--------- Assets/Scripts/Logic/Blocks/Jump.cs | 8 ++++ Assets/Scripts/Logic/Blocks/LogicBlock.cs | 2 + Assets/Scripts/Managers/GameManager.cs | 46 +++++++++++++++++++++-- 10 files changed, 145 insertions(+), 74 deletions(-) delete mode 100644 Assets/Plugins.meta diff --git a/Assets/Plugins.meta b/Assets/Plugins.meta deleted file mode 100644 index aa3b71c..0000000 --- a/Assets/Plugins.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: eb6762a6d45772b43a77849ba46f89db -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Prefabs/Blocks/Cube_Water.prefab b/Assets/Prefabs/Blocks/Cube_Water.prefab index 5191790..73c386c 100644 --- a/Assets/Prefabs/Blocks/Cube_Water.prefab +++ b/Assets/Prefabs/Blocks/Cube_Water.prefab @@ -24,7 +24,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 530235143574139110} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: -1, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 8106369753450024413} @@ -59,7 +59,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 671413771732590573} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 1.005, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.6, y: 0.1, z: 0.6} m_Children: [] m_Father: {fileID: 1828716198829146157} @@ -119,9 +119,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 47964057} - - component: {fileID: 177033255137993395} - component: {fileID: 6650162365135615188} - - component: {fileID: 5031374599848591737} + - component: {fileID: 5226278787542506594} m_Layer: 0 m_Name: Cube_Water m_TagString: Untagged @@ -145,23 +144,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &177033255137993395 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1999421548732318256} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 13e596b7661bb0b43b4ef2f0432f5966, type: 3} - m_Name: - m_EditorClassIdentifier: - clientData: {fileID: 11400000, guid: ded0b21c3ef1e7049a1128c12e9401fe, type: 2} - Names: [] - lilypad: {fileID: 530235143574139110} - triggeranimate: 0 - triggeranimate1: 0 --- !u!65 &6650162365135615188 BoxCollider: m_ObjectHideFlags: 0 @@ -175,7 +157,7 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} ---- !u!114 &5031374599848591737 +--- !u!114 &5226278787542506594 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -184,15 +166,17 @@ MonoBehaviour: m_GameObject: {fileID: 1999421548732318256} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1a69d64be9f9e8543b4278d7f139f6f1, type: 3} + m_Script: {fileID: 11500000, guid: 68d0f0591435c9944a441b8fa5244072, type: 3} m_Name: m_EditorClassIdentifier: - VisualOffset: {x: 0, y: 0, z: 0} + VisualOffset: {x: 0, y: 0.5, z: 0} is_Walkable: 1 - isWater: 1 + isWater: 0 isPit: 0 isSpawnable: 0 SpawnDirection: 2 + lillyPad: {fileID: 530235143574139110} + FallDistance: 0.5 --- !u!1 &7281521922483143231 GameObject: m_ObjectHideFlags: 0 @@ -296,7 +280,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7858000249164259621} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0.93, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1.1, y: 1.1, z: 1.1} m_Children: [] m_Father: {fileID: 1828716198829146157} @@ -373,7 +357,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8864229519112577870} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0.931, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 2, y: 1, z: 2} m_Children: [] m_Father: {fileID: 1828716198829146157} diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 5df7ea4..6b1bfea 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -132,6 +132,8 @@ public class Character : MonoBehaviour StopAnimation(animation); } + + public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true) { System.Func yFunction = null; @@ -206,6 +208,19 @@ public class Character : MonoBehaviour transform.position = _startPos + Vector3.up * heightOffset(1); } + public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time) + { + System.Func yFunction = null; + if (animation == Animation.Jump) + yFunction = (t) => Mathf.Sin((Mathf.PI * t)); + + StartAnimation(animation, time); + + yield return StartCoroutine(LerpToBlock(position, time * 0.8f, yFunction)); + + StopAnimation(animation); + } + public void StartAnimation(Animation animation,float speed = 1) { characterAnimator.SetFloat("AnimationSpeed", (1 / speed)); diff --git a/Assets/Scripts/LevelBlocks/ActiveBlock.cs b/Assets/Scripts/LevelBlocks/ActiveBlock.cs index c0bff6e..f3ed369 100644 --- a/Assets/Scripts/LevelBlocks/ActiveBlock.cs +++ b/Assets/Scripts/LevelBlocks/ActiveBlock.cs @@ -2,8 +2,13 @@ using System.Collections.Generic; using UnityEngine; -public class ActiveBlock : Block +public abstract class ActiveBlock : Block { + + #region Read-Only Variables + public bool isFinished { get; protected set; } + #endregion Read-Only Variables + #region Class Functions /// @@ -11,9 +16,10 @@ public class ActiveBlock : Block /// /// Should be implemented by a derived class /// - public virtual void OnEnvironmentTurn(PlayerData[] allPlayers) + public virtual IEnumerator OnEnvironmentTurn(PlayerData[] allPlayers) { - + isFinished = true; + yield break; } /// @@ -21,11 +27,24 @@ public class ActiveBlock : Block /// /// Should be implemented by a derived class /// - public virtual void OnRoundEnd(PlayerData[] allPlayers) + public virtual IEnumerator OnRoundEnd(PlayerData[] allPlayers) { + isFinished = true; + yield break; + } + public void Reset() + { + isFinished = false; } + /// + /// Returns what order this block should be called in for the environment turn; + /// + /// The Higher the number returned the earlier it goes + /// This was made abstract because it shouldn't be accidentally changed + so we don;t accidentally forget to implement it + public abstract int GetInitative(); + #endregion Class Functions diff --git a/Assets/Scripts/LevelBlocks/Block.cs b/Assets/Scripts/LevelBlocks/Block.cs index 5e3d4c7..2b51cfa 100644 --- a/Assets/Scripts/LevelBlocks/Block.cs +++ b/Assets/Scripts/LevelBlocks/Block.cs @@ -37,7 +37,7 @@ public class Block : MonoBehaviour /// /// List of current players on this block /// - protected Character currentPlayer; + public Character CurrentPlayer { get; protected set; } #endregion Private Functions #region ReadOnly Properties @@ -85,7 +85,7 @@ public class Block : MonoBehaviour /// Player which moved on to block public virtual void OnLeftByPlayer(Character player) { - currentPlayer = null; + CurrentPlayer = null; } /// @@ -95,17 +95,17 @@ public class Block : MonoBehaviour /// The direction the player moved to get to this block public virtual IEnumerator DoPush(Character newPlayer, Vector3 moveDirection) { - if (currentPlayer == null) + if (CurrentPlayer == null) { - currentPlayer = newPlayer; + CurrentPlayer = newPlayer; yield break; } - Block pushBlock = GetPushLocation(moveDirection, ~currentPlayer.Ignore); + Block pushBlock = GetPushLocation(moveDirection, ~CurrentPlayer.Ignore); if (pushBlock != this) { - Character oldPlayer = currentPlayer; - currentPlayer = newPlayer; + Character oldPlayer = CurrentPlayer; + CurrentPlayer = newPlayer; yield return StartCoroutine(oldPlayer.MoveToBlock(pushBlock, Character.Animation.Hit, 1)); } else diff --git a/Assets/Scripts/LevelBlocks/Water.cs b/Assets/Scripts/LevelBlocks/Water.cs index 54796ed..de269a3 100644 --- a/Assets/Scripts/LevelBlocks/Water.cs +++ b/Assets/Scripts/LevelBlocks/Water.cs @@ -13,16 +13,23 @@ public class Water : ActiveBlock [Tooltip("Distance character will be submerged into the water")] private float FallDistance = 0.5f; + private bool isLillyPadUp = false; + private Character trappedCharacter; + public override int GetInitative() + { + return 0; + } public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection) { - base.OnWalkedOnByPlayer(player, moveDirection); + yield return StartCoroutine(base.OnWalkedOnByPlayer(player, moveDirection)); if (trappedCharacter == null) { - player = trappedCharacter; + CurrentPlayer = null; + trappedCharacter = player; trappedCharacter.stuck = true; trappedCharacter.StartAnimation(Character.Animation.Hit); @@ -31,16 +38,31 @@ public class Water : ActiveBlock } - public override void OnRoundEnd(PlayerData[] allPlayers) + public override void OnLeftByPlayer(Character player) + { + base.OnLeftByPlayer(player); + if (isLillyPadUp) + { + StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition + Vector3.down * FallDistance, 1)); + isLillyPadUp = false; + } + + } + + public override IEnumerator OnRoundEnd(PlayerData[] allPlayers) { - base.OnRoundEnd(allPlayers); + Debug.Log("reseting water"); if (trappedCharacter != null) { StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1)); - StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1)); + yield return StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1)); trappedCharacter.stuck = false; + isLillyPadUp = true; + trappedCharacter = null; + } + isFinished = true; } diff --git a/Assets/Scripts/Logic/BlockReader.cs b/Assets/Scripts/Logic/BlockReader.cs index eb1744a..4972d96 100644 --- a/Assets/Scripts/Logic/BlockReader.cs +++ b/Assets/Scripts/Logic/BlockReader.cs @@ -29,7 +29,7 @@ public class BlockReader /// /// Gets the current block in the logic chain /// - public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } } + public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } } /// /// Sum of size of all Blocks in the chain @@ -56,37 +56,26 @@ public class BlockReader /// /// Character to control /// Returns false if other readers should wait for this one to run again - public IEnumerator Read(Character character,float speedMultiplier) + public IEnumerator Read(Character character, float speedMultiplier) { + + LogicBlock currentBlock = LogicChain[currentBlockIndex]; + //If the character has become stuck, they forfeit their remaining moves - we skip directly to their end of their chain if (character.stuck == true) { - Debug.Log("Character is stuck! No moving!"); - //return true; - currentBlockIndex = LogicChain.Count; - } - else - { - Debug.Log("Character is not stuck"); - } + currentBlock.Reset(); - //return that this is done if no more blocks left in chain - if (LogicChain.Count <= currentBlockIndex) - { - //return true; + yield break; } - //get current Block - LogicBlock currentBlock = LogicChain[currentBlockIndex]; - //apply blocks to character yield return character.StartCoroutine(currentBlock.Run(character, speedMultiplier)); //if the block is finished reset it and move on to next one //(it might not be finished if it is a for loop or something) - bool isFinished = currentBlock.isFinished(); - if (isFinished) + if (currentBlock.isFinished()) { currentBlock.Reset(); currentBlockIndex++; @@ -137,7 +126,7 @@ public class BlockReader { LogicChain.Insert(index, item); if (OnUpdate != null) - OnUpdate.Invoke(); + OnUpdate.Invoke(); } #endregion diff --git a/Assets/Scripts/Logic/Blocks/Jump.cs b/Assets/Scripts/Logic/Blocks/Jump.cs index a08224a..4886061 100644 --- a/Assets/Scripts/Logic/Blocks/Jump.cs +++ b/Assets/Scripts/Logic/Blocks/Jump.cs @@ -34,6 +34,14 @@ public class Jump : LogicBlock player.justMoved = true; Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore); + + while(endBlock.CurrentPlayer != null) + { + yield return player.StartCoroutine(player.AnimateToPosition(endBlock.VisualPosition + Vector3.up * 0.5f, Character.Animation.Jump, 0.8f)); + endBlock.CurrentPlayer.StartAnimation(Character.Animation.Hit); + endBlock = GetEndBlock(endBlock, player.transform, ~player.Ignore); + } + yield return player.StartCoroutine(player.MoveToBlock(endBlock, Character.Animation.Jump, animationTime)); } diff --git a/Assets/Scripts/Logic/Blocks/LogicBlock.cs b/Assets/Scripts/Logic/Blocks/LogicBlock.cs index aec45db..db94f8f 100644 --- a/Assets/Scripts/Logic/Blocks/LogicBlock.cs +++ b/Assets/Scripts/Logic/Blocks/LogicBlock.cs @@ -74,6 +74,8 @@ public abstract class LogicBlock : ScriptableObject { for (int i = 0; i < RepeatAmount; i++) { + if (player.stuck) + yield break; RepeatCount++; yield return player.StartCoroutine(BlockLogic(player, TotalAnimationTime)); } diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 1567c2f..4d2c2ba 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -33,6 +33,7 @@ public class GameManager : MonoBehaviour #region Private Variables private Dictionary playerData; + private ActiveBlock[] EnvironmentBlocks; #endregion Private Variables #region Read Only @@ -51,6 +52,7 @@ public class GameManager : MonoBehaviour private void Start() { + //Start Game StartCoroutine(GameRoutine()); } @@ -94,6 +96,10 @@ public class GameManager : MonoBehaviour //wait until we have recieved all player input yield return StartCoroutine(WaitForPlayerInput()); + //I hate having to do this + EnvironmentBlocks = FindObjectsOfType(); + Debug.Log("Active blocks found: " + EnvironmentBlocks.Length); + //Routine for players movement yield return StartCoroutine(RoundRoutine()); //it's pretty long so it gets it's own coroutine; } @@ -102,7 +108,7 @@ public class GameManager : MonoBehaviour gameMode.GameEnd(playerDataAsArray); } - void removePlayer(PlayerData player) + private void removePlayer(PlayerData player) { player.client.ChangeScene("WaitScene"); player.isDead = true; @@ -127,8 +133,11 @@ public class GameManager : MonoBehaviour } //Let Gamemode know all players have moved - gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); - + gameMode.AllPlayersMoved(playerDataAsArray); + + //Let the environment take a turn + yield return StartCoroutine(EnvironmentTurn()); + gameMode.EnvironmentTurn(playerDataAsArray); //if Game is over break out of loop if (gameMode.isGameOver(playerDataAsArray)) @@ -143,6 +152,7 @@ public class GameManager : MonoBehaviour playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score //Let GameMode know that Round is Over + yield return StartCoroutine(EnvironmentEnd()); gameMode.RoundEnd(playerDataAsArray.ToArray()); @@ -259,6 +269,36 @@ public class GameManager : MonoBehaviour client.playerCharacter = newChar; } } + + private IEnumerator EnvironmentTurn() + { + foreach (var InitiativeGroup in EnvironmentBlocks.GroupBy(p => p.GetInitative())){ + + foreach (ActiveBlock block in InitiativeGroup) + StartCoroutine(block.OnEnvironmentTurn(playerDataAsArray)); + + yield return new WaitUntil(() => InitiativeGroup.All(p => p.isFinished)); + InitiativeGroup.ForEach(p => p.Reset()); + } + + } + + private IEnumerator EnvironmentEnd() + { + foreach (var InitiativeGroup in EnvironmentBlocks.GroupBy(p => p.GetInitative())){ + + foreach (ActiveBlock block in InitiativeGroup) + StartCoroutine(block.OnRoundEnd(playerDataAsArray)); + + yield return new WaitUntil(() => InitiativeGroup.All(p => p.isFinished)); + InitiativeGroup.ForEach(p => p.Reset()); + } + } + + private ActiveBlock[] GetActiveBlocksOf(int intiative) + { + return EnvironmentBlocks.Where(p => p.GetInitative() == intiative).ToArray(); + } #endregion Class Functions #region Networking Functions