Browse Source

Pushing works

Josh_Dev_branch
Joshua Reason 5 years ago
parent
commit
aa8b44bdee
17 changed files with 77 additions and 101 deletions
  1. +0
    -8
      Assets/Plugins/IngameDebugConsole/Android.meta
  2. +0
    -8
      Assets/Plugins/IngameDebugConsole/Prefabs.meta
  3. +0
    -8
      Assets/Plugins/IngameDebugConsole/Scripts.meta
  4. +0
    -8
      Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta
  5. +1
    -2
      Assets/Scripts/BlockInput.cs
  6. +6
    -2
      Assets/Scripts/Character.cs
  7. +1
    -1
      Assets/Scripts/Components.meta
  8. +2
    -2
      Assets/Scripts/KeyboardInput.cs
  9. +4
    -6
      Assets/Scripts/Logic/BlockReader.cs
  10. +15
    -6
      Assets/Scripts/Logic/Blocks/CombinedBlock.cs
  11. +2
    -2
      Assets/Scripts/Logic/Blocks/Jump.cs
  12. +18
    -6
      Assets/Scripts/Logic/Blocks/LogicBlock.cs
  13. +2
    -4
      Assets/Scripts/Logic/Blocks/Move.cs
  14. +2
    -2
      Assets/Scripts/Logic/Blocks/Rotate.cs
  15. +2
    -1
      Assets/Scripts/Logic/Blocks/RotateHalf.cs
  16. +0
    -8
      Assets/Scripts/LogicBlocks.meta
  17. +22
    -27
      Assets/Scripts/Managers/GameManager.cs

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Android.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 3d7d7a61a5341904eb3c65af025b1d86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Prefabs.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 7dbc36665bc0d684db9a4447e27a7a4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Scripts.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 860c08388401a6d4e858fe4910ea9337
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f6caae32d463529478f2186f47c2e3fe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 1
- 2
Assets/Scripts/BlockInput.cs View File

@ -20,8 +20,7 @@ public class BlockInput : MonoBehaviour
[ContextMenu("Read Next")] [ContextMenu("Read Next")]
public void ReadNext() public void ReadNext()
{ {
float TotalAnimationTime;
blockReader.Read(character, waitTime,out TotalAnimationTime);
StartCoroutine(blockReader.Read(character, waitTime));
} }
public void ReadAll() public void ReadAll()

+ 6
- 2
Assets/Scripts/Character.cs View File

@ -103,6 +103,7 @@ public class Character : MonoBehaviour
public IEnumerator MoveToBlock(Block target, Animation animation, float time) public IEnumerator MoveToBlock(Block target, Animation animation, float time)
{ {
float startTime = Time.time;
Vector3 moveDirection = Vector3.ProjectOnPlane(target.position - _currentBlock.position, Vector3.up).normalized; Vector3 moveDirection = Vector3.ProjectOnPlane(target.position - _currentBlock.position, Vector3.up).normalized;
_currentBlock.OnLeftByPlayer(this); _currentBlock.OnLeftByPlayer(this);
@ -113,10 +114,13 @@ public class Character : MonoBehaviour
StartAnimation(animation, time); StartAnimation(animation, time);
yield return StartCoroutine(LerpToBlock(target.VisualPosition, time, yFunction));
yield return StartCoroutine(LerpToBlock(target.VisualPosition, time * 0.8f, yFunction));
_currentBlock= target; _currentBlock= target;
yield return StartCoroutine (_currentBlock.OnWalkedOnByPlayer(this,moveDirection)); yield return StartCoroutine (_currentBlock.OnWalkedOnByPlayer(this,moveDirection));
yield return new WaitForSeconds(time - (Time.time - startTime));
StopAnimation(animation); StopAnimation(animation);
} }
@ -130,7 +134,7 @@ public class Character : MonoBehaviour
StartAnimation(animation, time); StartAnimation(animation, time);
yield return StartCoroutine(LerpToRotation(_endDir, time, yFunction));
yield return StartCoroutine(LerpToRotation(_endDir, time * 0.8f, yFunction));
StopAnimation(animation); StopAnimation(animation);
} }

Assets/Models.meta → Assets/Scripts/Components.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 296bd90e667df1f4697823a0aa45acf0
guid: 8d7394d70ec233849a60a26da5f23b75
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

+ 2
- 2
Assets/Scripts/KeyboardInput.cs View File

@ -35,14 +35,14 @@ public class KeyboardInput : MonoBehaviour
{ {
float outTime; float outTime;
Move move = (Move)ScriptableObject.CreateInstance(typeof(Move)); Move move = (Move)ScriptableObject.CreateInstance(typeof(Move));
move.Run(character, characterSpeed, out outTime);
StartCoroutine(move.Run(character, characterSpeed));
Destroy(move); Destroy(move);
} }
if (Input.GetKeyDown(KeyCode.Space)) if (Input.GetKeyDown(KeyCode.Space))
{ {
float outTime; float outTime;
Jump jump = (Jump)ScriptableObject.CreateInstance(typeof(Jump)); Jump jump = (Jump)ScriptableObject.CreateInstance(typeof(Jump));
jump.Run(character, characterSpeed, out outTime);
StartCoroutine(jump.Run(character, characterSpeed));
Destroy(jump); Destroy(jump);
} }
} }

+ 4
- 6
Assets/Scripts/Logic/BlockReader.cs View File

@ -56,13 +56,12 @@ public class BlockReader
/// </summary> /// </summary>
/// <param name="character">Character to control</param> /// <param name="character">Character to control</param>
/// <returns>Returns false if other readers should wait for this one to run again</returns> /// <returns>Returns false if other readers should wait for this one to run again</returns>
public bool Read(Character character,float speedMultiplier, out float TotalAnimationTime)
public IEnumerator Read(Character character,float speedMultiplier)
{ {
//If the character has become stuck, they forfeit their remaining moves - we skip directly to their end of their chain //If the character has become stuck, they forfeit their remaining moves - we skip directly to their end of their chain
if (character.stuck == true) if (character.stuck == true)
{ {
Debug.Log("Character is stuck! No moving!"); Debug.Log("Character is stuck! No moving!");
TotalAnimationTime = 0;
//return true; //return true;
currentBlockIndex = LogicChain.Count; currentBlockIndex = LogicChain.Count;
@ -75,15 +74,14 @@ public class BlockReader
//return that this is done if no more blocks left in chain //return that this is done if no more blocks left in chain
if (LogicChain.Count <= currentBlockIndex) if (LogicChain.Count <= currentBlockIndex)
{ {
TotalAnimationTime = 0;
return true;
//return true;
} }
//get current Block //get current Block
LogicBlock currentBlock = LogicChain[currentBlockIndex]; LogicBlock currentBlock = LogicChain[currentBlockIndex];
//apply blocks to character //apply blocks to character
bool runAgainNot = currentBlock.Run(character, speedMultiplier,out TotalAnimationTime);
yield return character.StartCoroutine(currentBlock.Run(character, speedMultiplier));
//if the block is finished reset it and move on to next one //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) //(it might not be finished if it is a for loop or something)
@ -95,7 +93,7 @@ public class BlockReader
} }
//Should other readers wait for this one //Should other readers wait for this one
return (runAgainNot || !currentBlock.WaitUntilFinished);
//return (runAgainNot || !currentBlock.WaitUntilFinished);
} }
/// <summary> /// <summary>

+ 15
- 6
Assets/Scripts/Logic/Blocks/CombinedBlock.cs View File

@ -25,24 +25,33 @@ public class CombinedBlock : LogicBlock
#endregion Private Variables #endregion Private Variables
public override bool Run(Character player, float animationTime, out float TotalAnimationTime)
public override IEnumerator Run(Character player, float animationTime)
{ {
BlockLogic(player,animationTime); BlockLogic(player,animationTime);
blockReader.Read(player, animationTime / SpeedMultiplier, out TotalAnimationTime);
if (WaitUntilFinished)
{
for (int i = 0; i < blockReader.Length; i++)
{
yield return player.StartCoroutine(blockReader.Read(player, animationTime / SpeedMultiplier));
}
}
else
{
yield return player.StartCoroutine(blockReader.Read(player, animationTime / SpeedMultiplier));
}
if (blockReader.Finished) if (blockReader.Finished)
{ {
blockReader.Reset(); blockReader.Reset();
RepeatCount++; RepeatCount++;
} }
return isFinished();
} }
protected override void BlockLogic(Character player, float animationTime)
protected override IEnumerator BlockLogic(Character player, float animationTime)
{ {
yield break;
} }

+ 2
- 2
Assets/Scripts/Logic/Blocks/Jump.cs View File

@ -28,13 +28,13 @@ public class Jump : LogicBlock
/// Implementation of BlockLogic, moves the player forward /// Implementation of BlockLogic, moves the player forward
/// </summary> /// </summary>
/// <param name="player">Player to move</param> /// <param name="player">Player to move</param>
protected override void BlockLogic(Character player, float animationTime)
protected override IEnumerator BlockLogic(Character player, float animationTime)
{ {
//player.Jump(direction, animationTime); //player.Jump(direction, animationTime);
player.justMoved = true; player.justMoved = true;
Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore); Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore);
player.StartCoroutine(player.MoveToBlock(endBlock, Character.Animation.Jump, animationTime));
yield return player.StartCoroutine(player.MoveToBlock(endBlock, Character.Animation.Jump, animationTime));
} }

+ 18
- 6
Assets/Scripts/Logic/Blocks/LogicBlock.cs View File

@ -58,17 +58,29 @@ public abstract class LogicBlock : ScriptableObject
/// </summary> /// </summary>
/// <param name="player">Player which will be affected by the block</param> /// <param name="player">Player which will be affected by the block</param>
/// <returns>returns true if block is finished</returns> /// <returns>returns true if block is finished</returns>
public virtual bool Run(Character player, float animationSpeed, out float TotalAnimationTime)
public virtual IEnumerator Run(Character player, float animationSpeed)
{ {
RepeatCount++;
TotalAnimationTime = animationSpeed / SpeedMultiplier;
BlockLogic(player, TotalAnimationTime);
float TotalAnimationTime = animationSpeed / SpeedMultiplier;
if(GlobalVariables.playerMoves == true){ if(GlobalVariables.playerMoves == true){
player.DisplayBlock(this); player.DisplayBlock(this);
} }
return isFinished();
if (WaitUntilFinished)
{
for (int i = 0; i < RepeatAmount; i++)
{
RepeatCount++;
yield return player.StartCoroutine(BlockLogic(player, TotalAnimationTime));
}
}
else
{
RepeatCount++;
yield return player.StartCoroutine(BlockLogic(player, TotalAnimationTime));
}
} }
/// <summary> /// <summary>
@ -85,7 +97,7 @@ public abstract class LogicBlock : ScriptableObject
/// </summary> /// </summary>
/// <param name="player">Player which will be affected by the block</param> /// <param name="player">Player which will be affected by the block</param>
/// <returns>returns true if block is finished</returns> /// <returns>returns true if block is finished</returns>
protected abstract void BlockLogic(Character player, float animationTime);
protected abstract IEnumerator BlockLogic(Character player, float animationTime);
/// <summary> /// <summary>
/// Returns the block that the character will endUp on after they use this logic element /// Returns the block that the character will endUp on after they use this logic element

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

@ -19,15 +19,13 @@ public class Move : LogicBlock
/// Implementation of BlockLogic, moves the player forward /// Implementation of BlockLogic, moves the player forward
/// </summary> /// </summary>
/// <param name="player">Player to move</param> /// <param name="player">Player to move</param>
protected override void BlockLogic(Character player, float animationTime)
protected override IEnumerator BlockLogic(Character player, float animationTime)
{ {
player.justMoved = true; player.justMoved = true;
//player.Move(direction, animationTime); //player.Move(direction, animationTime);
Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore); Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore);
Debug.Log("CurrentBlock: " + player.CurrentBlock.position + "\nEndBlock: " + endBlock.position);
player.StartCoroutine(player.MoveToBlock(endBlock, Character.Animation.Walk, animationTime));
yield return player.StartCoroutine(player.MoveToBlock(endBlock, Character.Animation.Walk, animationTime));
} }
/// <summary> /// <summary>

+ 2
- 2
Assets/Scripts/Logic/Blocks/Rotate.cs View File

@ -23,11 +23,11 @@ public class Rotate : LogicBlock
/// Rotates the player in the direction specified by this block /// Rotates the player in the direction specified by this block
/// </summary> /// </summary>
/// <param name="player">Player to rotate</param> /// <param name="player">Player to rotate</param>
protected override void BlockLogic(Character player, float animationTime)
protected override IEnumerator BlockLogic(Character player, float animationTime)
{ {
//player.Rotate(direction, animationTime); //player.Rotate(direction, animationTime);
player.StartCoroutine(player.RotateToDirection(direction, Character.Animation.Jump, animationTime, true));
yield return player.StartCoroutine(player.RotateToDirection(direction, Character.Animation.Jump, animationTime, true));
} }
/// <summary> /// <summary>

+ 2
- 1
Assets/Scripts/Logic/Blocks/RotateHalf.cs View File

@ -23,9 +23,10 @@ public class RotateHalf : LogicBlock
/// Rotates the player in the direction specified by this block /// Rotates the player in the direction specified by this block
/// </summary> /// </summary>
/// <param name="player">Player to rotate</param> /// <param name="player">Player to rotate</param>
protected override void BlockLogic(Character player, float animationTime)
protected override IEnumerator BlockLogic(Character player, float animationTime)
{ {
player.RotateHalf(direction, animationTime); player.RotateHalf(direction, animationTime);
yield break;
} }
/// <summary> /// <summary>

+ 0
- 8
Assets/Scripts/LogicBlocks.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 8936b441d7647f74884c94f97bfb8931
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 22
- 27
Assets/Scripts/Managers/GameManager.cs View File

@ -44,7 +44,7 @@ public class GameManager : MonoBehaviour
/// <summary> /// <summary>
/// Easy access to GameMode value in CurrentGameMode reference /// Easy access to GameMode value in CurrentGameMode reference
/// </summary> /// </summary>
private GameMode gameMode {get { return CurrentGameMode.Value; } }
private GameMode gameMode { get { return CurrentGameMode.Value; } }
#endregion Read Only #endregion Read Only
#region Unity Functions #region Unity Functions
@ -117,6 +117,8 @@ public class GameManager : MonoBehaviour
while (playerDataAsArray.Any(p => !p.blockReader.Finished)) while (playerDataAsArray.Any(p => !p.blockReader.Finished))
{ {
//Loop through all players //Loop through all players
foreach (PlayerData player in playerDataAsArray) foreach (PlayerData player in playerDataAsArray)
{ {
@ -142,18 +144,18 @@ public class GameManager : MonoBehaviour
//force them back to the waiting for players screen //force them back to the waiting for players screen
foreach (PlayerData player in playerDataAsArray) foreach (PlayerData player in playerDataAsArray)
{ {
if(player.client.Lives == 0)
if (player.client.Lives == 0)
{ {
Debug.Log("Remove: " + player.client.characterAnimal); Debug.Log("Remove: " + player.client.characterAnimal);
removePlayer(player); removePlayer(player);
} }
} }
//Reset some player Data
//Reset some player Data
foreach (PlayerData player in playerDataAsArray) foreach (PlayerData player in playerDataAsArray)
{ {
if(player.client.Lives > 0)
if (player.client.Lives > 0)
{ {
player.blockReader.Reset(); player.blockReader.Reset();
player.client.SendInventory(); player.client.SendInventory();
@ -166,7 +168,7 @@ public class GameManager : MonoBehaviour
//send round length to players //send round length to players
//#TODO make this only happen after first input //#TODO make this only happen after first input
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime());
//playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); //playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime));
foreach (PlayerData player in playerDataAsArray) foreach (PlayerData player in playerDataAsArray)
{ {
@ -180,7 +182,7 @@ public class GameManager : MonoBehaviour
//ClientList.ForEach(p => p.ChangeScene("ClientScene")); //ClientList.ForEach(p => p.ChangeScene("ClientScene"));
foreach (ClientData client in ClientList) foreach (ClientData client in ClientList)
{ {
if(client.Lives > 0){client.ChangeScene("ClientScene");}
if (client.Lives > 0) { client.ChangeScene("ClientScene"); }
} }
//Let gamemode know clients are input-ing //Let gamemode know clients are input-ing
@ -193,7 +195,7 @@ public class GameManager : MonoBehaviour
//playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list //playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list
foreach (PlayerData player in playerDataAsArray) foreach (PlayerData player in playerDataAsArray)
{ {
if (player.client.Lives > 0){player.recievedList = false;}
if (player.client.Lives > 0) { player.recievedList = false; }
} }
//Let gamemode know all inputs have been recieved //Let gamemode know all inputs have been recieved
@ -202,28 +204,21 @@ public class GameManager : MonoBehaviour
private IEnumerator MoveRoutine(PlayerData data) private IEnumerator MoveRoutine(PlayerData data)
{ {
bool blockFinished = false;
float waitTime;
//Loop until the current block indicates or the reader indicates it has finished
while (!blockFinished && !data.blockReader.Finished)
//If the current block hasn't already been removed, remove it from the player inventory
//We need to check if it has already been removed so loops don't eat an entire stack
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved)
{ {
data.client.Inventory.Remove(data.blockReader.CurrentBlock);
data.blockReader.CurrentBlock.hasBeenRemoved = true;
}
//If the current block hasn't already been removed, remove it from the player inventory
//We need to check if it has already been removed so loops don't eat an entire stack
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved)
{
data.client.Inventory.Remove(data.blockReader.CurrentBlock);
data.blockReader.CurrentBlock.hasBeenRemoved = true;
}
//Process the move
blockFinished = data.blockReader.Read(data.character, AnimationTime, out waitTime);
//Process the move
//blockFinished = data.blockReader.Read(data.character, AnimationTime, out waitTime);
//Wait for the animation to finish
yield return new WaitForSeconds(waitTime);
//Wait for the animation to finish
//yield return new WaitForSeconds(waitTime);
}
yield return StartCoroutine(data.blockReader.Read(data.character, AnimationTime));
} }
private void SpawnCharacters() private void SpawnCharacters()
@ -256,7 +251,7 @@ public class GameManager : MonoBehaviour
newChar.ClientLink = client; newChar.ClientLink = client;
client.playerCharacter = newChar; client.playerCharacter = newChar;
} }
}
}
#endregion Class Functions #endregion Class Functions
#region Networking Functions #region Networking Functions

Loading…
Cancel
Save