Browse Source

-Updated water to new system + Jumping has a bounce effect

Josh_Dev_branch
Joshua Reason 4 years ago
parent
commit
3afffa1575
10 changed files with 145 additions and 74 deletions
  1. +0
    -8
      Assets/Plugins.meta
  2. +11
    -27
      Assets/Prefabs/Blocks/Cube_Water.prefab
  3. +15
    -0
      Assets/Scripts/Character.cs
  4. +23
    -4
      Assets/Scripts/LevelBlocks/ActiveBlock.cs
  5. +7
    -7
      Assets/Scripts/LevelBlocks/Block.cs
  6. +27
    -5
      Assets/Scripts/LevelBlocks/Water.cs
  7. +9
    -20
      Assets/Scripts/Logic/BlockReader.cs
  8. +8
    -0
      Assets/Scripts/Logic/Blocks/Jump.cs
  9. +2
    -0
      Assets/Scripts/Logic/Blocks/LogicBlock.cs
  10. +43
    -3
      Assets/Scripts/Managers/GameManager.cs

+ 0
- 8
Assets/Plugins.meta View File

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

+ 11
- 27
Assets/Prefabs/Blocks/Cube_Water.prefab View File

@ -24,7 +24,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 530235143574139110}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -1, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 8106369753450024413}
@ -59,7 +59,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 671413771732590573}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 1.005, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.6, y: 0.1, z: 0.6}
m_Children: []
m_Father: {fileID: 1828716198829146157}
@ -119,9 +119,8 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 47964057}
- component: {fileID: 177033255137993395}
- component: {fileID: 6650162365135615188}
- component: {fileID: 5031374599848591737}
- component: {fileID: 5226278787542506594}
m_Layer: 0
m_Name: Cube_Water
m_TagString: Untagged
@ -145,23 +144,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &177033255137993395
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1999421548732318256}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 13e596b7661bb0b43b4ef2f0432f5966, type: 3}
m_Name:
m_EditorClassIdentifier:
clientData: {fileID: 11400000, guid: ded0b21c3ef1e7049a1128c12e9401fe, type: 2}
Names: []
lilypad: {fileID: 530235143574139110}
triggeranimate: 0
triggeranimate1: 0
--- !u!65 &6650162365135615188
BoxCollider:
m_ObjectHideFlags: 0
@ -175,7 +157,7 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &5031374599848591737
--- !u!114 &5226278787542506594
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -184,15 +166,17 @@ MonoBehaviour:
m_GameObject: {fileID: 1999421548732318256}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1a69d64be9f9e8543b4278d7f139f6f1, type: 3}
m_Script: {fileID: 11500000, guid: 68d0f0591435c9944a441b8fa5244072, type: 3}
m_Name:
m_EditorClassIdentifier:
VisualOffset: {x: 0, y: 0, z: 0}
VisualOffset: {x: 0, y: 0.5, z: 0}
is_Walkable: 1
isWater: 1
isWater: 0
isPit: 0
isSpawnable: 0
SpawnDirection: 2
lillyPad: {fileID: 530235143574139110}
FallDistance: 0.5
--- !u!1 &7281521922483143231
GameObject:
m_ObjectHideFlags: 0
@ -296,7 +280,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7858000249164259621}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.93, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.1, y: 1.1, z: 1.1}
m_Children: []
m_Father: {fileID: 1828716198829146157}
@ -373,7 +357,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8864229519112577870}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.931, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 2, y: 1, z: 2}
m_Children: []
m_Father: {fileID: 1828716198829146157}

+ 15
- 0
Assets/Scripts/Character.cs View File

@ -132,6 +132,8 @@ public class Character : MonoBehaviour
StopAnimation(animation);
}
public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true)
{
System.Func<float, float> yFunction = null;
@ -206,6 +208,19 @@ public class Character : MonoBehaviour
transform.position = _startPos + Vector3.up * heightOffset(1);
}
public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time)
{
System.Func<float, float> yFunction = null;
if (animation == Animation.Jump)
yFunction = (t) => Mathf.Sin((Mathf.PI * t));
StartAnimation(animation, time);
yield return StartCoroutine(LerpToBlock(position, time * 0.8f, yFunction));
StopAnimation(animation);
}
public void StartAnimation(Animation animation,float speed = 1)
{
characterAnimator.SetFloat("AnimationSpeed", (1 / speed));

+ 23
- 4
Assets/Scripts/LevelBlocks/ActiveBlock.cs View File

@ -2,8 +2,13 @@
using System.Collections.Generic;
using UnityEngine;
public class ActiveBlock : Block
public abstract class ActiveBlock : Block
{
#region Read-Only Variables
public bool isFinished { get; protected set; }
#endregion Read-Only Variables
#region Class Functions
/// <summary>
@ -11,9 +16,10 @@ public class ActiveBlock : Block
///
/// Should be implemented by a derived class
/// </summary>
public virtual void OnEnvironmentTurn(PlayerData[] allPlayers)
public virtual IEnumerator OnEnvironmentTurn(PlayerData[] allPlayers)
{
isFinished = true;
yield break;
}
/// <summary>
@ -21,11 +27,24 @@ public class ActiveBlock : Block
///
/// Should be implemented by a derived class
/// </summary>
public virtual void OnRoundEnd(PlayerData[] allPlayers)
public virtual IEnumerator OnRoundEnd(PlayerData[] allPlayers)
{
isFinished = true;
yield break;
}
public void Reset()
{
isFinished = false;
}
/// <summary>
/// Returns what order this block should be called in for the environment turn;
/// </summary>
/// <returns>The Higher the number returned the earlier it goes</returns>
/// <remarks>This was made abstract because it shouldn't be accidentally changed + so we don;t accidentally forget to implement it</remarks>
public abstract int GetInitative();
#endregion Class Functions

+ 7
- 7
Assets/Scripts/LevelBlocks/Block.cs View File

@ -37,7 +37,7 @@ public class Block : MonoBehaviour
/// <summary>
/// List of current players on this block
/// </summary>
protected Character currentPlayer;
public Character CurrentPlayer { get; protected set; }
#endregion Private Functions
#region ReadOnly Properties
@ -85,7 +85,7 @@ public class Block : MonoBehaviour
/// <param name="player">Player which moved on to block</param>
public virtual void OnLeftByPlayer(Character player)
{
currentPlayer = null;
CurrentPlayer = null;
}
/// <summary>
@ -95,17 +95,17 @@ public class Block : MonoBehaviour
/// <param name="moveDirection">The direction the player moved to get to this block</param>
public virtual IEnumerator DoPush(Character newPlayer, Vector3 moveDirection)
{
if (currentPlayer == null)
if (CurrentPlayer == null)
{
currentPlayer = newPlayer;
CurrentPlayer = newPlayer;
yield break;
}
Block pushBlock = GetPushLocation(moveDirection, ~currentPlayer.Ignore);
Block pushBlock = GetPushLocation(moveDirection, ~CurrentPlayer.Ignore);
if (pushBlock != this)
{
Character oldPlayer = currentPlayer;
currentPlayer = newPlayer;
Character oldPlayer = CurrentPlayer;
CurrentPlayer = newPlayer;
yield return StartCoroutine(oldPlayer.MoveToBlock(pushBlock, Character.Animation.Hit, 1));
}
else

+ 27
- 5
Assets/Scripts/LevelBlocks/Water.cs View File

@ -13,16 +13,23 @@ public class Water : ActiveBlock
[Tooltip("Distance character will be submerged into the water")]
private float FallDistance = 0.5f;
private bool isLillyPadUp = false;
private Character trappedCharacter;
public override int GetInitative()
{
return 0;
}
public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
{
base.OnWalkedOnByPlayer(player, moveDirection);
yield return StartCoroutine(base.OnWalkedOnByPlayer(player, moveDirection));
if (trappedCharacter == null)
{
player = trappedCharacter;
CurrentPlayer = null;
trappedCharacter = player;
trappedCharacter.stuck = true;
trappedCharacter.StartAnimation(Character.Animation.Hit);
@ -31,16 +38,31 @@ public class Water : ActiveBlock
}
public override void OnRoundEnd(PlayerData[] allPlayers)
public override void OnLeftByPlayer(Character player)
{
base.OnLeftByPlayer(player);
if (isLillyPadUp)
{
StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition + Vector3.down * FallDistance, 1));
isLillyPadUp = false;
}
}
public override IEnumerator OnRoundEnd(PlayerData[] allPlayers)
{
base.OnRoundEnd(allPlayers);
Debug.Log("reseting water");
if (trappedCharacter != null)
{
StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1));
StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1));
yield return StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1));
trappedCharacter.stuck = false;
isLillyPadUp = true;
trappedCharacter = null;
}
isFinished = true;
}

+ 9
- 20
Assets/Scripts/Logic/BlockReader.cs View File

@ -29,7 +29,7 @@ public class BlockReader
/// <summary>
/// Gets the current block in the logic chain
/// </summary>
public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } }
public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } }
/// <summary>
/// Sum of size of all Blocks in the chain
@ -56,37 +56,26 @@ public class BlockReader
/// </summary>
/// <param name="character">Character to control</param>
/// <returns>Returns false if other readers should wait for this one to run again</returns>
public IEnumerator Read(Character character,float speedMultiplier)
public IEnumerator Read(Character character, float speedMultiplier)
{
LogicBlock currentBlock = LogicChain[currentBlockIndex];
//If the character has become stuck, they forfeit their remaining moves - we skip directly to their end of their chain
if (character.stuck == true)
{
Debug.Log("Character is stuck! No moving!");
//return true;
currentBlockIndex = LogicChain.Count;
}
else
{
Debug.Log("Character is not stuck");
}
currentBlock.Reset();
//return that this is done if no more blocks left in chain
if (LogicChain.Count <= currentBlockIndex)
{
//return true;
yield break;
}
//get current Block
LogicBlock currentBlock = LogicChain[currentBlockIndex];
//apply blocks to character
yield return character.StartCoroutine(currentBlock.Run(character, speedMultiplier));
//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)
bool isFinished = currentBlock.isFinished();
if (isFinished)
if (currentBlock.isFinished())
{
currentBlock.Reset();
currentBlockIndex++;
@ -137,7 +126,7 @@ public class BlockReader
{
LogicChain.Insert(index, item);
if (OnUpdate != null)
OnUpdate.Invoke();
OnUpdate.Invoke();
}
#endregion

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

@ -34,6 +34,14 @@ public class Jump : LogicBlock
player.justMoved = true;
Block endBlock = GetEndBlock(player.CurrentBlock, player.transform, ~player.Ignore);
while(endBlock.CurrentPlayer != null)
{
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));
}

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

@ -74,6 +74,8 @@ public abstract class LogicBlock : ScriptableObject
{
for (int i = 0; i < RepeatAmount; i++)
{
if (player.stuck)
yield break;
RepeatCount++;
yield return player.StartCoroutine(BlockLogic(player, TotalAnimationTime));
}

+ 43
- 3
Assets/Scripts/Managers/GameManager.cs View File

@ -33,6 +33,7 @@ public class GameManager : MonoBehaviour
#region Private Variables
private Dictionary<int, PlayerData> playerData;
private ActiveBlock[] EnvironmentBlocks;
#endregion Private Variables
#region Read Only
@ -51,6 +52,7 @@ public class GameManager : MonoBehaviour
private void Start()
{
//Start Game
StartCoroutine(GameRoutine());
}
@ -94,6 +96,10 @@ public class GameManager : MonoBehaviour
//wait until we have recieved all player input
yield return StartCoroutine(WaitForPlayerInput());
//I hate having to do this
EnvironmentBlocks = FindObjectsOfType<ActiveBlock>();
Debug.Log("Active blocks found: " + EnvironmentBlocks.Length);
//Routine for players movement
yield return StartCoroutine(RoundRoutine()); //it's pretty long so it gets it's own coroutine;
}
@ -102,7 +108,7 @@ public class GameManager : MonoBehaviour
gameMode.GameEnd(playerDataAsArray);
}
void removePlayer(PlayerData player)
private void removePlayer(PlayerData player)
{
player.client.ChangeScene("WaitScene");
player.isDead = true;
@ -127,8 +133,11 @@ public class GameManager : MonoBehaviour
}
//Let Gamemode know all players have moved
gameMode.AllPlayersMoved(playerDataAsArray.ToArray());
gameMode.AllPlayersMoved(playerDataAsArray);
//Let the environment take a turn
yield return StartCoroutine(EnvironmentTurn());
gameMode.EnvironmentTurn(playerDataAsArray);
//if Game is over break out of loop
if (gameMode.isGameOver(playerDataAsArray))
@ -143,6 +152,7 @@ public class GameManager : MonoBehaviour
playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score
//Let GameMode know that Round is Over
yield return StartCoroutine(EnvironmentEnd());
gameMode.RoundEnd(playerDataAsArray.ToArray());
@ -259,6 +269,36 @@ public class GameManager : MonoBehaviour
client.playerCharacter = newChar;
}
}
private IEnumerator EnvironmentTurn()
{
foreach (var InitiativeGroup in EnvironmentBlocks.GroupBy(p => p.GetInitative())){
foreach (ActiveBlock block in InitiativeGroup)
StartCoroutine(block.OnEnvironmentTurn(playerDataAsArray));
yield return new WaitUntil(() => InitiativeGroup.All(p => p.isFinished));
InitiativeGroup.ForEach(p => p.Reset());
}
}
private IEnumerator EnvironmentEnd()
{
foreach (var InitiativeGroup in EnvironmentBlocks.GroupBy(p => p.GetInitative())){
foreach (ActiveBlock block in InitiativeGroup)
StartCoroutine(block.OnRoundEnd(playerDataAsArray));
yield return new WaitUntil(() => InitiativeGroup.All(p => p.isFinished));
InitiativeGroup.ForEach(p => p.Reset());
}
}
private ActiveBlock[] GetActiveBlocksOf(int intiative)
{
return EnvironmentBlocks.Where(p => p.GetInitative() == intiative).ToArray();
}
#endregion Class Functions
#region Networking Functions

Loading…
Cancel
Save