Split screen, controls not workings
This commit is contained in:
parent
17f27aa8a3
commit
ee95dd043f
4139
Assets/Scenes/DuoGameScene.unity
Normal file
4139
Assets/Scenes/DuoGameScene.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/DuoGameScene.unity.meta
Normal file
7
Assets/Scenes/DuoGameScene.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 682d64d1d4474994cba4504e7df89dd0
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -505,7 +505,7 @@ MonoBehaviour:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 533191356}
|
||||
m_TargetAssemblyTypeName: GameSession, Assembly-CSharp
|
||||
m_MethodName: GoToGameScene
|
||||
m_MethodName: GoToSoloMode
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@ -8,6 +9,8 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
{
|
||||
[SerializeField] private Player currentPlayer;
|
||||
[SerializeField] private Scoreboard scoreboard;
|
||||
[SerializeField] private Boolean isPlayer2;
|
||||
|
||||
public static GameSession Instance { get; private set; }
|
||||
public WorldCurver Curver { get; private set; }
|
||||
private IInputTranslator inputTranslator;
|
||||
@ -39,17 +42,9 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (ApplicationUtil.platform == RuntimePlatform.Android || ApplicationUtil.platform == RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
IBindingHolder<TouchBinding> touchHolder = new TouchBindingHolder();
|
||||
inputTranslator = new InputTranslator<TouchBinding>(touchHolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
IBindingHolder<KeyBinding> keyHolder = new KeyBindingHolder();
|
||||
inputTranslator = new InputTranslator<KeyBinding>(keyHolder);
|
||||
}
|
||||
inputTranslator = new InputTranslator<KeyBinding>(keyHolder, isPlayer2);
|
||||
}
|
||||
|
||||
public void AddCommandTranslator(ICommandTranslator translator)
|
||||
@ -89,12 +84,17 @@ public class GameSession : MonoBehaviour,IResettable
|
||||
scoreboard.AddScoreboardEntry(entry);
|
||||
}
|
||||
|
||||
public void GoToGameScene()
|
||||
public void GoToSoloMode()
|
||||
{
|
||||
SceneManager.LoadScene("GameScene", LoadSceneMode.Single);
|
||||
ResetToDefault();
|
||||
}
|
||||
|
||||
public void GoToDuoMode()
|
||||
{
|
||||
SceneManager.LoadScene("DuoGameScene", LoadSceneMode.Single);
|
||||
ResetToDefault();
|
||||
}
|
||||
public void GoToMainMenu()
|
||||
{
|
||||
SceneManager.LoadScene("MainMenu", LoadSceneMode.Single);
|
||||
|
@ -8,6 +8,6 @@ using System.Threading.Tasks;
|
||||
public interface IBindingHolder<T> where T : IBinding
|
||||
{
|
||||
public Dictionary<ECommand, T> InputBindings { get; }
|
||||
public void Init();
|
||||
public void Init(Boolean isPlayer2);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@ -10,17 +11,32 @@ public class KeyBindingHolder : IBindingHolder<KeyBinding>
|
||||
private readonly Dictionary<ECommand, KeyBinding> DefaultKeyBindings = new Dictionary<ECommand, KeyBinding>
|
||||
{
|
||||
{ECommand.NONE, new KeyBinding(KeyCode.None)},
|
||||
{ECommand.DOWN, new KeyBinding(KeyCode.DownArrow,KeyCode.S)},
|
||||
{ECommand.UP, new KeyBinding(KeyCode.UpArrow,KeyCode.W)},
|
||||
{ECommand.LEFT, new KeyBinding(KeyCode.LeftArrow,KeyCode.A)},
|
||||
{ECommand.RIGHT, new KeyBinding(KeyCode.RightArrow,KeyCode.D)},
|
||||
{ECommand.DOWN, new KeyBinding(KeyCode.DownArrow)},
|
||||
{ECommand.UP, new KeyBinding(KeyCode.UpArrow)},
|
||||
{ECommand.LEFT, new KeyBinding(KeyCode.LeftArrow)},
|
||||
{ECommand.RIGHT, new KeyBinding(KeyCode.RightArrow)},
|
||||
{ECommand.OPEN_SCOREBOARD, new KeyBinding(KeyCode.Tab)},
|
||||
{ECommand.OPEN_PAUSE_MENU, new KeyBinding(KeyCode.Escape)}
|
||||
};
|
||||
|
||||
public void Init()
|
||||
private readonly Dictionary<ECommand, KeyBinding> Player2KeyBindings = new Dictionary<ECommand, KeyBinding>
|
||||
{
|
||||
{ECommand.DOWN2, new KeyBinding(KeyCode.S)},
|
||||
{ECommand.UP2, new KeyBinding(KeyCode.Z)},
|
||||
{ECommand.LEFT2, new KeyBinding(KeyCode.Q)},
|
||||
{ECommand.RIGHT2, new KeyBinding(KeyCode.D)},
|
||||
};
|
||||
|
||||
public void Init(Boolean isPlayer2 = false)
|
||||
{
|
||||
if (InputBindings == null)
|
||||
if (isPlayer2)
|
||||
{
|
||||
InputBindings = Player2KeyBindings;
|
||||
}
|
||||
else
|
||||
{
|
||||
InputBindings = DefaultKeyBindings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class TouchBindingHolder : IBindingHolder<TouchBinding>
|
||||
{
|
||||
public Dictionary<ECommand, TouchBinding> InputBindings { get; private set; }
|
||||
|
||||
private readonly Dictionary<ECommand, TouchBinding> DefaultTouchBindings = new Dictionary<ECommand, TouchBinding>
|
||||
{
|
||||
{ECommand.NONE, new TouchBinding(ETouchGesture.NONE)},
|
||||
{ECommand.DOWN, new TouchBinding(ETouchGesture.SWIPE_DOWN)},
|
||||
{ECommand.UP, new TouchBinding(ETouchGesture.SWIPE_UP)},
|
||||
{ECommand.LEFT, new TouchBinding(ETouchGesture.SWIPE_LEFT)},
|
||||
{ECommand.RIGHT, new TouchBinding(ETouchGesture.SWIPE_RIGHT)},
|
||||
};
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (InputBindings == null)
|
||||
InputBindings = DefaultTouchBindings;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23353de203a94c447af7be38973acc1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,6 +1,7 @@
|
||||
|
||||
public enum ECommand
|
||||
{
|
||||
#region Player1
|
||||
NONE = 0,
|
||||
LEFT = 1,
|
||||
RIGHT = 2,
|
||||
@ -8,5 +9,17 @@ public enum ECommand
|
||||
DOWN = 4,
|
||||
OPEN_SCOREBOARD = 5,
|
||||
SHOOT = 6,
|
||||
OPEN_PAUSE_MENU = 7
|
||||
OPEN_PAUSE_MENU = 7,
|
||||
#endregion
|
||||
|
||||
#region Player2
|
||||
LEFT2 = 8,
|
||||
RIGHT2 = 9,
|
||||
UP2 = 10,
|
||||
DOWN2 = 11,
|
||||
OPEN_SCOREBOARD2 = 12,
|
||||
SHOOT2 = 13,
|
||||
OPEN_PAUSE_MENU2 = 14
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IInputTranslator
|
||||
@ -17,11 +18,11 @@ public class InputTranslator<T> : IInputTranslator where T : IBinding
|
||||
private List<ICommandTranslator> commandTranslators;
|
||||
private IBindingHolder<T> bindingHolder;
|
||||
|
||||
public InputTranslator(IBindingHolder<T> holder)
|
||||
public InputTranslator(IBindingHolder<T> holder, Boolean isPlayer2)
|
||||
{
|
||||
commandTranslators = new List<ICommandTranslator>();
|
||||
bindingHolder = holder;
|
||||
bindingHolder.Init();
|
||||
bindingHolder.Init(isPlayer2);
|
||||
}
|
||||
//public void Init(IBindingHolder<T> holder)
|
||||
//{
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@ -8,7 +9,7 @@ using UnityEngine.SceneManagement;
|
||||
[RequireComponent(typeof(Health))]
|
||||
[RequireComponent(typeof(Statistics))]
|
||||
|
||||
public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
||||
{
|
||||
#region StateMachine
|
||||
|
||||
@ -20,7 +21,12 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
|
||||
private Animator animator;
|
||||
[SerializeField] private AnimationCurve jumpDeltaYCurve;
|
||||
public AnimationCurve JumpDeltaYCurve { get { return jumpDeltaYCurve; } }
|
||||
|
||||
public AnimationCurve JumpDeltaYCurve
|
||||
{
|
||||
get { return jumpDeltaYCurve; }
|
||||
}
|
||||
|
||||
public PlayerAnimator PlayerAnimator { get; private set; }
|
||||
|
||||
#endregion
|
||||
@ -30,14 +36,24 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
[SerializeField] private PlayerData playerData;
|
||||
public IDamageable PlayerHealth { get; private set; }
|
||||
public Statistics PlayerStatictics { get; private set; }
|
||||
public PlayerData PlayerData { get { return playerData; } }
|
||||
|
||||
public PlayerData PlayerData
|
||||
{
|
||||
get { return playerData; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MovementControl
|
||||
|
||||
[SerializeField] private LaneSystem laneSystem;
|
||||
public LaneSystem LaneSystem { get { return laneSystem; } private set { laneSystem = value; } }
|
||||
|
||||
public LaneSystem LaneSystem
|
||||
{
|
||||
get { return laneSystem; }
|
||||
private set { laneSystem = value; }
|
||||
}
|
||||
|
||||
public CharacterController CharacterController { get; private set; }
|
||||
public PlayerCollider PlayerCollider { get; private set; }
|
||||
|
||||
@ -45,6 +61,7 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
|
||||
public bool IsInvincible { get; private set; }
|
||||
public float InvincibilityTime { get; private set; } //PLAYER DATA ScriptableObject
|
||||
[SerializeField] private Boolean isPlayer2;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -59,10 +76,12 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
PlayerStateMachine = new PlayerStateMachine(this);
|
||||
InvincibilityTime = playerData.InvincibilityTime;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
PlayerHealth.OnOutOfHealth += Die;
|
||||
}
|
||||
|
||||
// private void OnDisable()
|
||||
// {
|
||||
// PlayerHealth.OnOutOfHealth -= Die;
|
||||
@ -77,11 +96,14 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
{
|
||||
PlayerStateMachine.Tick();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
PlayerStateMachine.FixedTick();
|
||||
}
|
||||
|
||||
public float PendingAdditionalOffset { get; private set; }
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent(out IDamageDealer damageDealer)) //switch..case
|
||||
@ -94,8 +116,10 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
{
|
||||
damageDealer.DealDamage(component, damageAmount);
|
||||
}
|
||||
|
||||
StartCoroutine(GrantInvincibility());
|
||||
}
|
||||
|
||||
if (other.TryGetComponent(out IObstacle obstacle)) //switch..case
|
||||
{
|
||||
obstacle.Impact();
|
||||
@ -109,7 +133,7 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
private void Die()
|
||||
{
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerDeadState);
|
||||
GameSession.Instance.UpdateScoreboard(new ScoreboardEntry(name,PlayerStatictics.Score));
|
||||
GameSession.Instance.UpdateScoreboard(new ScoreboardEntry(name, PlayerStatictics.Score));
|
||||
|
||||
SceneManager.LoadScene("DeathScreen");
|
||||
}
|
||||
@ -120,11 +144,13 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
yield return new WaitForSeconds(InvincibilityTime);
|
||||
IsInvincible = false;
|
||||
}
|
||||
|
||||
private void ReloadAnimator()
|
||||
{
|
||||
if (animator)
|
||||
PlayerAnimator = new PlayerAnimator(animator);
|
||||
}
|
||||
|
||||
public void ResetToDefault()
|
||||
{
|
||||
PlayerStateMachine.SetState(null);
|
||||
@ -137,6 +163,28 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
public void TranslateCommand(ECommand command, PressedState state)
|
||||
{
|
||||
if (state.IsPressed)
|
||||
{
|
||||
if (isPlayer2)
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case ECommand.RIGHT2:
|
||||
PlayerStateMachine.IncreaseTargetLane();
|
||||
break;
|
||||
case ECommand.LEFT2:
|
||||
PlayerStateMachine.DecreaseTargetLane();
|
||||
break;
|
||||
case ECommand.UP2:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerJumpState);
|
||||
break;
|
||||
case ECommand.DOWN2:
|
||||
PlayerStateMachine.SetState(PlayerStateMachine.PlayerSlideState);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
@ -157,4 +205,5 @@ public class Player : MonoBehaviour,IResettable, ICommandTranslator
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class PausedView : BaseView
|
||||
|
||||
restartButton.onClick.AddListener(() =>
|
||||
{
|
||||
GameSession.Instance.GoToGameScene();
|
||||
GameSession.Instance.GoToSoloMode();
|
||||
});
|
||||
base.Init();
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user