Browse Source

Did some bug fixing. Water pushes character off if someone ends up ontop

master
Joshua Reason 5 years ago
parent
commit
d3720b4dae
5 changed files with 73 additions and 31 deletions
  1. +5
    -1
      Assets/Scripts/LevelBlocks/Air.cs
  2. +0
    -12
      Assets/Scripts/LevelBlocks/Block.cs
  3. +28
    -1
      Assets/Scripts/LevelBlocks/Water.cs
  4. +4
    -17
      Assets/Scripts/Logic/Blocks/Move.cs
  5. +36
    -0
      Assets/Scripts/Utility/Enums.cs

+ 5
- 1
Assets/Scripts/LevelBlocks/Air.cs View File

@ -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;
}

+ 0
- 12
Assets/Scripts/LevelBlocks/Block.cs View File

@ -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

+ 28
- 1
Assets/Scripts/LevelBlocks/Water.cs View File

@ -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;

+ 4
- 17
Assets/Scripts/Logic/Blocks/Move.cs View File

@ -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)

+ 36
- 0
Assets/Scripts/Utility/Enums.cs View File

@ -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<Direction> selection = new System.Collections.Generic.List<Direction>(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;
}
}

Loading…
Cancel
Save