public void OnInput(PlayerInputKey key) { if (buffer.Count < 3) { buffer.Add(key); } }
IEnumerator WaitForInput() { while (buffer.Count == 0) { yield return(null); } PlayerInputKey key = buffer[0]; buffer.RemoveAt(0); if (key == PlayerInputKey.up) { DoAction(hitDigOrMove.GetAction(IntVector2.up), IntVector2.up); } else if (key == PlayerInputKey.right) { DoAction(hitDigOrMove.GetAction(IntVector2.right), IntVector2.right); } else if (key == PlayerInputKey.down) { DoAction(hitDigOrMove.GetAction(IntVector2.down), IntVector2.down); } else if (key == PlayerInputKey.left) { DoAction(hitDigOrMove.GetAction(IntVector2.left), IntVector2.left); } else { StartCoroutine(WaitForInput()); yield break; //Break out to signify that valid input wasn't actually provided (don't call onPlayerAction; } intTransform.GetLevel().OnPlayerAction(this); }
public PlayerInputHandler(TileWorld world) { Name = "PlayerInputHandler"; World = world; // Create keys Left = new PlayerInputKey("Left"); Right = new PlayerInputKey("Right"); Up = new PlayerInputKey("Up"); Down = new PlayerInputKey("Down"); Explode = new PlayerInputKey("Explode"); Bomb = new PlayerInputKey("Bomb"); Action = new PlayerInputKey("Action"); }
protected override void DecodeBufferAndExecute(ref BinaryReader reader, ClientData clientData) { inputKey = (PlayerInputKey)reader.ReadByte(); if (inputKey == PlayerInputKey.space && clientData.player == null) { IntVector2 spawnPos = LevelManager.S.startLevel.GetOpenPlayerSpawnPosition(); if (spawnPos == IntVector2.error) { Debug.LogError("No available spawn position!"); return; } NetManager.S.SendServerMessageToGroup(new NetMessage_SpawnPlayer(spawnPos, LevelManager.S.startLevel, clientData.connectionID), ConnectionGroup.game); } else if (clientData.player != null) { clientData.player.GetComponent <PlayerController>().OnInput(inputKey); } }
public NetMessage_ClientInput(PlayerInputKey inputKey) { this.inputKey = inputKey; }