Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class InputPlayer : IInput
{
public bool ShouldPlay{get{
return !GameSettings.PauseOnInaction ||
(
Input.GetKey(KeyCode.W) ||
Input.GetKey(KeyCode.A) ||
Input.GetKey(KeyCode.S) ||
Input.GetKey(KeyCode.D) ||
Input.GetKey(KeyCode.E) ||
Input.GetKey(KeyCode.Space)
);
}}
public void EndInput()
{
ReleaseKeyboard();
}
void ReleaseKeyboard()
{
Player player = GameManager.CurrentPlayer;
if (player.MovingForward)
{
GameManager.AddActionToTimeline(new Action(player, ActionEnum.ReleaseForward));
}
//Repeat for the other 3 directions
}
public void GetInput()
{
Movement();
MakeNewPlayer();
SwitchPlayers();
SetSpawnPoint();
Activate();
}
public void SetSpawnPoint(){
if(Input.GetKeyDown(KeyCode.Q)){
GameManager.SetSpawnPoint(GameManager.CurrentPlayer.transform.position);
}
}
public void SwitchPlayers(){
if(Input.GetKeyDown(KeyCode.Tab)){
GameManager.SwitchPlayer(1);
}
}
void MakeNewPlayer(){
if(Input.GetKeyDown(KeyCode.F)){
GameManager.MakeNewPlayer();
}
}
void Activate(){
Player player = GameManager.CurrentPlayer;
if(Input.GetKeyDown(KeyCode.E)){
GameManager.AddActionToTimeline(new Action(player, ActionEnum.Activate));
}
}
void Movement()
{
Player player = GameManager.CurrentPlayer;
if (Input.GetKeyDown(KeyCode.W))
{
GameManager.AddActionToTimeline(new Action(player, ActionEnum.PressForward));
}
if (Input.GetKeyUp(KeyCode.W))
{
GameManager.AddActionToTimeline(new Action(player, ActionEnum.ReleaseForward));
}
//Repeat for the other 3 directions
}
public void StartInput()
{
Player player = GameManager.CurrentPlayer;
if (Input.GetKey(KeyCode.W))
{
if (!player.MovingForward)
{
GameManager.AddActionToTimeline(new Action(player, ActionEnum.PressForward));
}
}
else
{
if (player.MovingForward)
{
GameManager.AddActionToTimeline(new Action(player, ActionEnum.ReleaseForward));
}
}
//Repeat for the other 3 directions
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.