From d3720b4dae1746629484c000dd6418cc7b31e957 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Wed, 16 Oct 2019 20:03:37 +1100 Subject: [PATCH] Did some bug fixing. Water pushes character off if someone ends up ontop --- Assets/Scripts/LevelBlocks/Air.cs | 6 ++++- Assets/Scripts/LevelBlocks/Block.cs | 12 ---------- Assets/Scripts/LevelBlocks/Water.cs | 29 ++++++++++++++++++++++- Assets/Scripts/Logic/Blocks/Move.cs | 21 ++++------------- Assets/Scripts/Utility/Enums.cs | 36 +++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/LevelBlocks/Air.cs b/Assets/Scripts/LevelBlocks/Air.cs index 9a59254..7ccc472 100644 --- a/Assets/Scripts/LevelBlocks/Air.cs +++ b/Assets/Scripts/LevelBlocks/Air.cs @@ -5,6 +5,8 @@ using UnityEngine; public class Air : ActiveBlock { + int DeleteCount = 2; + public override int GetInitative() { return -1; @@ -28,7 +30,9 @@ public class Air : ActiveBlock public override IEnumerator OnRoundEnd(PlayerData[] allPlayers) { isFinished = true; - Destroy(gameObject); + DeleteCount--; + if (DeleteCount == 0) + Destroy(gameObject); yield break; } diff --git a/Assets/Scripts/LevelBlocks/Block.cs b/Assets/Scripts/LevelBlocks/Block.cs index ae7e150..141623d 100644 --- a/Assets/Scripts/LevelBlocks/Block.cs +++ b/Assets/Scripts/LevelBlocks/Block.cs @@ -144,18 +144,6 @@ public class Block : MonoBehaviour return Block.GetOrCreateBlockAtPosition(newPosition, 1, ignoreMask); - - ////If block at Position is walkable set it to moveTo - //if (Block.isBlockAtPosition(newPosition, 1, ignoreMask, out hit) && hit.isWalkable(ignoreMask)) - //{ - // return hit; - //} - ////else if block down one is walkable - //else if (Block.isBlockAtPosition(newPosition + Vector3.down, 1, ignoreMask, out hit) && hit.isWalkable(ignoreMask)) - //{ - // return hit; - //} - //return this; } #endregion Protected Functions diff --git a/Assets/Scripts/LevelBlocks/Water.cs b/Assets/Scripts/LevelBlocks/Water.cs index 32e94d4..03120d5 100644 --- a/Assets/Scripts/LevelBlocks/Water.cs +++ b/Assets/Scripts/LevelBlocks/Water.cs @@ -73,7 +73,19 @@ public class Water : ActiveBlock StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1)); - yield return StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1)); + StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1)); + + if (CurrentPlayer != null) + { + yield return new WaitForSeconds(0.2f); + yield return StartCoroutine(PushPlayOnTop()); + } + else + { + yield return new WaitForSeconds(1); + CurrentPlayer = trappedCharacter; + } + trappedCharacter.stuck = false; isLillyPadUp = true; trappedCharacter = null; @@ -83,6 +95,21 @@ public class Water : ActiveBlock } + private IEnumerator PushPlayOnTop() + { + Direction[] possibleDirections = DirectionExtras.RandomOrder(); + + for (int i = 0; i < 4; i++) + { + if (Block.isBlockAtPosition(position + possibleDirections[i].ToVector() + Vector3.up, 1, ~0)) + continue; + + yield return StartCoroutine(DoPush(trappedCharacter, possibleDirections[i].ToVector())); + break; + } + + } + private IEnumerator LerpToPosition(Transform target, Vector3 endPos, float time) { Vector3 _startPos = target.position; diff --git a/Assets/Scripts/Logic/Blocks/Move.cs b/Assets/Scripts/Logic/Blocks/Move.cs index 3a7eaaa..04fa373 100644 --- a/Assets/Scripts/Logic/Blocks/Move.cs +++ b/Assets/Scripts/Logic/Blocks/Move.cs @@ -48,23 +48,10 @@ public class Move : LogicBlock Block hit; //output of block detection Block retVal = startBlock; //Block we'll move to - - return Block.GetOrCreateBlockAtPosition(wantedPosition, 1, layerMask); - - //If block at Position is walkable set it to moveTo - if (Block.isBlockAtPosition(wantedPosition, 1, layerMask, out hit) && hit.isWalkable(layerMask)) - { - retVal = hit; - } - //else if block down one is walkable - else if (Block.isBlockAtPosition(wantedPosition + Vector3.down, 1, layerMask, out hit) && hit.isWalkable(layerMask)) - { - //and it isn't obstructed - if (Block.isBlockAtPosition(wantedPosition + Vector3.up, 1, layerMask, out hit)) - retVal = hit; - } - - return retVal; + if (!Block.isBlockAtPosition(wantedPosition + Vector3.up, 1, layerMask)) + return Block.GetOrCreateBlockAtPosition(wantedPosition, 1, layerMask); + else + return startBlock; } public override void CopyToken(BlockToken token) diff --git a/Assets/Scripts/Utility/Enums.cs b/Assets/Scripts/Utility/Enums.cs index 572d130..59cd8d7 100644 --- a/Assets/Scripts/Utility/Enums.cs +++ b/Assets/Scripts/Utility/Enums.cs @@ -1,3 +1,39 @@ //Use this file to Global enums in public enum Direction { Left, Right,Forward, Back} + +public static class DirectionExtras +{ + public static Direction Random() + { + int r = UnityEngine.Random.Range(0, 4); + switch (r) + { + case 0: + return Direction.Forward; + case 1: + return Direction.Right; + case 2: + return Direction.Left; + case 3: + return Direction.Back; + } + return Direction.Forward; + } + + public static Direction[] RandomOrder() + { + + System.Collections.Generic.List selection = new System.Collections.Generic.List(new Direction[] { Direction.Right,Direction.Left,Direction.Forward,Direction.Back}); + Direction[] retVal = new Direction[4]; + + for (int i = 0; i < 4; i++) + { + int r = UnityEngine.Random.Range(0, selection.Count); + retVal[i] = selection[r]; + selection.RemoveAt(r); + } + + return retVal; + } +}