Jump and crouch OK, lane broken
This commit is contained in:
parent
ee95dd043f
commit
2898130a82
File diff suppressed because it is too large
Load Diff
@ -13,7 +13,8 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
|
||||
public static GameSession Instance { get; private set; }
|
||||
public WorldCurver Curver { get; private set; }
|
||||
private IInputTranslator inputTranslator;
|
||||
private IInputTranslator _player1InputTranslator;
|
||||
private IInputTranslator _player2InputTranslator;
|
||||
|
||||
private bool isSessionPaused = false;
|
||||
private bool isInputAlreadyRestricted = false;
|
||||
@ -34,7 +35,9 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
inputTranslator.Tick();
|
||||
_player1InputTranslator.Tick();
|
||||
_player2InputTranslator.Tick();
|
||||
|
||||
Curver.Tick();
|
||||
// curver.SinCurveX();
|
||||
// Curver.SinCurveY();
|
||||
@ -43,26 +46,34 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
|
||||
private void Init()
|
||||
{
|
||||
IBindingHolder<KeyBinding> keyHolder = new KeyBindingHolder();
|
||||
inputTranslator = new InputTranslator<KeyBinding>(keyHolder, isPlayer2);
|
||||
var player1Holder = new KeyBindingHolder();
|
||||
player1Holder.Init(false);
|
||||
_player1InputTranslator = new InputTranslator<KeyBinding>(player1Holder, false);
|
||||
|
||||
var player2Holder = new KeyBindingHolder();
|
||||
player2Holder.Init(true);
|
||||
_player2InputTranslator = new InputTranslator<KeyBinding>(player2Holder, true);
|
||||
}
|
||||
|
||||
public void AddCommandTranslator(ICommandTranslator translator)
|
||||
public void AddCommandTranslator(ICommandTranslator translator, bool isPlayer2)
|
||||
{
|
||||
inputTranslator.AddCommandTranslator(translator);
|
||||
if (isPlayer2)
|
||||
_player2InputTranslator.AddCommandTranslator(translator);
|
||||
else
|
||||
_player1InputTranslator.AddCommandTranslator(translator);
|
||||
}
|
||||
|
||||
|
||||
public void PauseSession(bool isPaused)
|
||||
{
|
||||
Time.timeScale = isPaused ? 0 : 1;
|
||||
if (!isSessionPaused && inputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
||||
if (!isSessionPaused && _player1InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) && _player2InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) )
|
||||
{
|
||||
isInputAlreadyRestricted = true;
|
||||
isSessionPaused = isPaused;
|
||||
return;
|
||||
}
|
||||
if (!inputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
||||
if (!_player1InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) && !_player2InputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
||||
{
|
||||
isInputAlreadyRestricted = false;
|
||||
}
|
||||
@ -76,7 +87,9 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
|
||||
public void RestrictInputs(List<ECommand> commands,bool isRestricted)
|
||||
{
|
||||
inputTranslator.RestictTranslation(commands, isRestricted);
|
||||
_player1InputTranslator.RestictTranslation(commands, isRestricted);
|
||||
_player2InputTranslator.RestictTranslation(commands, isRestricted);
|
||||
|
||||
}
|
||||
|
||||
public void UpdateScoreboard(ScoreboardEntry entry)
|
||||
|
@ -27,7 +27,7 @@ public class KeyBindingHolder : IBindingHolder<KeyBinding>
|
||||
{ECommand.RIGHT2, new KeyBinding(KeyCode.D)},
|
||||
};
|
||||
|
||||
public void Init(Boolean isPlayer2 = false)
|
||||
public void Init(Boolean isPlayer2)
|
||||
{
|
||||
if (InputBindings == null)
|
||||
if (isPlayer2)
|
||||
|
@ -6,7 +6,7 @@ public class Pause : MonoBehaviour,ICommandTranslator
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
GameSession.Instance.AddCommandTranslator(this);
|
||||
GameSession.Instance.AddCommandTranslator(this, false);
|
||||
}
|
||||
|
||||
public void TranslateCommand(ECommand command, PressedState state)
|
||||
|
@ -42,7 +42,7 @@ public class Health : MonoBehaviour, IDamageable,IHealable, IResettable
|
||||
public void TakeDamage(int amount)
|
||||
{
|
||||
if (CurrentHealth > 0){
|
||||
CurrentHealth -= amount;
|
||||
//CurrentHealth -= amount; TODO: To change to take damage
|
||||
if (CurrentHealth <= 0){
|
||||
CurrentHealth = 0;
|
||||
OnOutOfHealth?.Invoke();
|
||||
|
@ -50,9 +50,16 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
||||
|
||||
public LaneSystem LaneSystem
|
||||
{
|
||||
get { return laneSystem; }
|
||||
private set { laneSystem = value; }
|
||||
get
|
||||
{
|
||||
return laneSystem;
|
||||
}
|
||||
private set
|
||||
{
|
||||
laneSystem = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CharacterController CharacterController { get; private set; }
|
||||
public PlayerCollider PlayerCollider { get; private set; }
|
||||
@ -65,7 +72,7 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GameSession.Instance.AddCommandTranslator(this);
|
||||
GameSession.Instance.AddCommandTranslator(this, isPlayer2);
|
||||
animator = GetComponent<Animator>();
|
||||
if (animator)
|
||||
PlayerAnimator = new PlayerAnimator(animator);
|
||||
@ -163,20 +170,22 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
||||
public void TranslateCommand(ECommand command, PressedState state)
|
||||
{
|
||||
if (state.IsPressed)
|
||||
{
|
||||
if (isPlayer2)
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case ECommand.RIGHT:
|
||||
case ECommand.RIGHT2:
|
||||
PlayerStateMachine.IncreaseTargetLane();
|
||||
break;
|
||||
case ECommand.LEFT:
|
||||
case ECommand.LEFT2:
|
||||
PlayerStateMachine.DecreaseTargetLane();
|
||||
break;
|
||||
case ECommand.UP:
|
||||
case ECommand.UP2:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerJumpState);
|
||||
break;
|
||||
case ECommand.DOWN:
|
||||
case ECommand.DOWN2:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerSlideState);
|
||||
break;
|
||||
@ -184,26 +193,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case ECommand.RIGHT:
|
||||
PlayerStateMachine.IncreaseTargetLane();
|
||||
break;
|
||||
case ECommand.LEFT:
|
||||
PlayerStateMachine.DecreaseTargetLane();
|
||||
break;
|
||||
case ECommand.UP:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerJumpState);
|
||||
break;
|
||||
case ECommand.DOWN:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerSlideState);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class Scoreboard : MonoBehaviour, ICommandTranslator
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameSession.Instance.AddCommandTranslator(this);
|
||||
GameSession.Instance.AddCommandTranslator(this, false);
|
||||
string jsonScoreboardEntries = PlayerPrefs.GetString("ScoreboardEntriesTableTest"); //Binary file
|
||||
ScoreboardEntriesTable entriesTable = JsonUtility.FromJson<ScoreboardEntriesTable>(jsonScoreboardEntries);
|
||||
if (entriesTable == null)
|
||||
|
File diff suppressed because one or more lines are too long
@ -14,5 +14,8 @@ EditorBuildSettings:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/DeathScreen.unity
|
||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/DuoGameScene.unity
|
||||
guid: 682d64d1d4474994cba4504e7df89dd0
|
||||
m_configObjects: {}
|
||||
m_UseUCBPForAssetBundles: 0
|
||||
|
@ -2,8 +2,9 @@
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!78 &1
|
||||
TagManager:
|
||||
serializedVersion: 2
|
||||
tags: []
|
||||
serializedVersion: 3
|
||||
tags:
|
||||
- PlayerEyes
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
@ -11,8 +12,8 @@ TagManager:
|
||||
-
|
||||
- Water
|
||||
- UI
|
||||
-
|
||||
-
|
||||
- Player1
|
||||
- Player2
|
||||
-
|
||||
-
|
||||
-
|
||||
@ -41,3 +42,5 @@ TagManager:
|
||||
- name: Default
|
||||
uniqueID: 0
|
||||
locked: 0
|
||||
m_RenderingLayers:
|
||||
- Default
|
||||
|
Loading…
x
Reference in New Issue
Block a user