|
|
@ -37,7 +37,7 @@ public class Block : MonoBehaviour |
|
|
|
/// <summary>
|
|
|
|
/// List of current players on this block
|
|
|
|
/// </summary>
|
|
|
|
protected List<Character> currentPlayers = new List<Character>(); |
|
|
|
protected Character currentPlayer; |
|
|
|
#endregion Private Functions
|
|
|
|
|
|
|
|
#region ReadOnly Properties
|
|
|
@ -71,9 +71,10 @@ public class Block : MonoBehaviour |
|
|
|
/// Should be implemented by a derived class
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="player">Player which moved on to block</param>
|
|
|
|
public virtual void OnWalkedOnByPlayer(Character player) |
|
|
|
///<param name="moveDirection">The direction the player moved to get to this block</param>
|
|
|
|
public virtual IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection) |
|
|
|
{ |
|
|
|
currentPlayers.Add(player); |
|
|
|
yield return StartCoroutine(DoPush(player, moveDirection)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -84,22 +85,69 @@ public class Block : MonoBehaviour |
|
|
|
/// <param name="player">Player which moved on to block</param>
|
|
|
|
public virtual void OnLeftByPlayer(Character player) |
|
|
|
{ |
|
|
|
currentPlayers.Remove(player); |
|
|
|
currentPlayer = null; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns an array of players who can be pushed off this block
|
|
|
|
/// Called to deal with players colliding on this block
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>array of players who can be pushed off this block</returns>
|
|
|
|
public virtual Character[] GetPushablePlayers() |
|
|
|
/// <param name="newPlayer">Player which is moving into this block</param>
|
|
|
|
/// <param name="moveDirection">The direction the player moved to get to this block</param>
|
|
|
|
public virtual IEnumerator DoPush(Character newPlayer, Vector3 moveDirection) |
|
|
|
{ |
|
|
|
return currentPlayers.ToArray(); |
|
|
|
} |
|
|
|
if (currentPlayer == null) |
|
|
|
{ |
|
|
|
currentPlayer = newPlayer; |
|
|
|
yield break; |
|
|
|
} |
|
|
|
|
|
|
|
Block pushBlock = GetPushLocation(moveDirection, ~currentPlayer.Ignore); |
|
|
|
if (pushBlock != this) |
|
|
|
{ |
|
|
|
Character oldPlayer = currentPlayer; |
|
|
|
currentPlayer = newPlayer; |
|
|
|
yield return StartCoroutine(oldPlayer.MoveToBlock(pushBlock, Character.Animation.Hit, 1)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Block returnBlock = GetPushLocation(-moveDirection, ~newPlayer.Ignore); |
|
|
|
|
|
|
|
if (returnBlock != this) |
|
|
|
yield return StartCoroutine(newPlayer.MoveToBlock(returnBlock, Character.Animation.Hit, 1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion Public Functions
|
|
|
|
|
|
|
|
#region Protected Functions
|
|
|
|
|
|
|
|
protected Block GetPushLocation(Vector3 pushDirection, LayerMask ignoreMask) |
|
|
|
{ |
|
|
|
//setting up variables
|
|
|
|
Vector3 newPosition = position + pushDirection; // position wanted
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
|
|
//if move is obstucted no where to move
|
|
|
|
if (Block.isBlockAtPosition(newPosition + Vector3.up, 1, ignoreMask)) |
|
|
|
return this; |
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
#region Editor Functions
|
|
|
|
private void OnDrawGizmos() |
|
|
|
{ |
|
|
|