public void SendGameState(GameState gState, uint objectId) { GameStatePacket packet = new GameStatePacket(); packet.payload = gState; PacketManager.Instance.SendPacket(packet, objectId, false); }
/// <summary> /// Sets the current state of the game. /// </summary> /// <param name="gameState">The desired state.</param> public static void SetGameStatePacket(GameStatePacket gameState) { byte[] data = gameState.Data; int status = SetGameState(data, data.Length); if (status > 0) { throw NewRLBotCoreException((RLBotCoreStatus)status); } }
// Sends information about the current game state to the players // resendTimeout is how long to wait until sending another GameStatePacket private void _sendGameState(PlayerInfo player, TimeSpan resendTimeout) { if (DateTime.Now >= (player.LastPacketSentTime.Add(resendTimeout))) { // Set the data GameStatePacket gsp = new GameStatePacket(); gsp.LeftY = LeftPlayer.Paddle.Position.Y; gsp.RightY = RightPlayer.Paddle.Position.Y; gsp.BallPosition = _ball.Position; gsp.LeftScore = LeftPlayer.Paddle.Score; gsp.RightScore = RightPlayer.Paddle.Score; _sendTo(player, gsp); } }
void OnReceivePacket(ushort type, Stream stream) { switch (type) { case (ushort)UserPacketType.GameState: GameStatePacket gStateMessage = new GameStatePacket(); gStateMessage.Deserialize(stream); switch (gStateMessage.payload) { case GameState.GameStart: PongManager.Instance.StartGame(); break; case GameState.GameEnd: PongManager.Instance.GameEnd(); break; } break; } }
/// <summary> /// Sets the current state of the game. /// </summary> /// <param name="gameState">The desired state.</param> public static void SetGameStatePacket(GameStatePacket gameState) { byte[] data = gameState.Data; SetGameState(data, data.Length); }