@ -1,4 +1,5 @@
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
/// <summary>
@ -28,15 +29,76 @@ public class Jump : LogicBlock
protected override IEnumerator BlockLogic ( Character player , float animationTime , bool useBlockDirection = false )
{
player . justMoved = true ;
List < Block > jumpBlocks = new List < Block > ( ) ; //Blocks to jump forward between
List < Block > bounceBlocks = new List < Block > ( ) ; //Blocks to bounce backward across
//Debug.Log("<b>" + player.name + " jumping from " + player.transform.position + "<\b>");
Block endBlock = GetEndBlock ( player . CurrentBlock , player . transform , ~ player . Ignore ) ;
//Debug.Log("Initial end block: " + endBlock.transform.position);
jumpBlocks . Add ( endBlock ) ;
while ( endBlock . CurrentPlayer ! = null & & endBlock . CurrentPlayer ! = player )
{
//Debug.Log("End block occupied! Time to bounce");
Block oldEndBlock = endBlock ;
//Debug.Log("oldEndBlock = " + oldEndBlock.transform.position);
endBlock = GetEndBlock ( endBlock , player . transform , ~ player . Ignore ) ;
//Debug.Log("new endBlock = " + endBlock.transform.position);
if ( endBlock = = oldEndBlock ) //Make sure we're not bouncing on the spot
{
//Debug.Log("We are bouncing in place, stop here");
break ;
}
//Debug.Log("Added block to list");
jumpBlocks . Add ( endBlock ) ;
}
//If we've ended on a block containing another player, we'll need to bounce backwards until we find an open square
while ( endBlock . CurrentPlayer ! = null & & endBlock . CurrentPlayer ! = player )
{
//Debug.Log("Block at " + endBlock.transform.position + " still occupied, we must bounce back");
Vector3 position = endBlock . position + ( Direction . Back . ToVector ( player . transform ) ) ;
endBlock = Block . GetOrCreateBlockAtPosition ( position , 1 , ~ player . Ignore ) ;
//Debug.Log("New endBlock = " + endBlock.transform.position);
bounceBlocks . Add ( endBlock ) ;
}
//Jump forward, bouncing across every player
//If there are multi-jumps to be done, they'll happen here
for ( int i = 0 ; i < jumpBlocks . Count - 1 ; i + + )
{
//Debug.Log("Jumping to: " + jumpBlocks[i].transform.position);
yield return player . StartCoroutine ( player . AnimateToPosition ( jumpBlocks [ i ] . VisualPosition + Vector3 . up * 0.5f , Character . Animation . Jump , 0.8f ) ) ;
}
//If we're at the last queued jump and there are no bouncebacks in the queue, then we've reached an open square, and can officially move here
if ( bounceBlocks . Count = = 0 )
{
//Debug.Log("Final jump to: " + endBlock.transform.position);
yield return player . StartCoroutine ( player . MoveToBlock ( endBlock , Character . Animation . Jump , animationTime ) ) ;
}
else //Otherwise, we have to bounce back first
{
yield return player . StartCoroutine ( player . AnimateToPosition ( jumpBlocks [ jumpBlocks . Count - 1 ] . VisualPosition + Vector3 . up * 0.5f , Character . Animation . Jump , 0.8f ) ) ;
for ( int i = 0 ; i < bounceBlocks . Count - 1 ; i + + )
{
//Debug.Log("Bouncing to: " + bounceBlocks[i].transform.position);
yield return player . StartCoroutine ( player . AnimateToPosition ( bounceBlocks [ i ] . VisualPosition + Vector3 . up * 0.5f , Character . Animation . Jump , 0.8f ) ) ;
}
//Debug.Log("Final bounce to: " + endBlock.transform.position);
yield return player . StartCoroutine ( player . MoveToBlock ( endBlock , Character . Animation . Jump , animationTime ) ) ;
}
while ( endBlock . CurrentPlayer ! = null & & endBlock . CurrentPlayer ! = player )
/ * while ( endBlock . CurrentPlayer ! = null & & endBlock . CurrentPlayer ! = player )
{
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 ) ) ;
yield return player . StartCoroutine ( player . MoveToBlock ( endBlock , Character . Animation . Jump , animationTime ) ) ; * /
}
/// <summary>