Skip to content

Instantly share code, notes, and snippets.

@jesterswilde
Created December 18, 2018 20:16
Show Gist options
  • Save jesterswilde/70b7858355b7e5bbdcc362695a79a4ea to your computer and use it in GitHub Desktop.
Save jesterswilde/70b7858355b7e5bbdcc362695a79a4ea to your computer and use it in GitHub Desktop.
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