void UpdateAngle(PlayerTransferableData remoteData) { if (remoteData == null) { return; } Angle = remoteData.Angle; }
void UpdatePosition(PlayerTransferableData remoteData) { if (remoteData == null || Position == remoteData.Position) { return; } Position = remoteData.Position; /* var difference = remoteData.Position - Position; float newX = Position.X, newY = Position.Y; if (difference.X < DestinationThreshold) { newX = remoteData.Position.X; } if (difference.Y < DestinationThreshold) { newY = remoteData.Position.Y; } Vector2 newPosition = new Vector2(newX, newY); if (newPosition != remoteData.Position) //we haven't arrived yet { Body.ApplyImpulse(Velocity * Speed); } else { Body.Position = newPosition; } */ /* var difference = remoteData.Position - Position; float newX = difference.X * InterpolationConstant, newY = difference.Y * InterpolationConstant; if (difference.X > 0 && difference.X < DestinationThreshold) { newX = difference.X; } if (difference.Y > 0 && difference.Y < DestinationThreshold) { newY = difference.Y; if (difference.X > 0 && difference.X < DestinationThreshold) { newX = difference.X; } if (difference.Y > 0 && difference.Y < DestinationThreshold) { newY = difference.Y; } } Position += new Vector2(newX, newY); */ }
void UpdateOtherPlayer(NetIncomingMessage msg) { var playerData = new PlayerTransferableData(msg); if (RemoteObjectsList.Exists(playerData.ID)) { RemoteObjectsList.UpdateData(playerData); } else { PlayerRemote newPlayer = playerFactory.NewRemotePlayer(playerData.SessionID, playerData.ID, playerData.Index, playerData.Position, playerData.Angle); RemoteObjectsList.Add(newPlayer, playerData); remotePlayers.Add(newPlayer.SessionID,newPlayer); } }
void NewServerConnection(NetIncomingMessage msg) { var data = new PlayerTransferableData(msg); localPlayer = playerFactory.NewPlayer(data.SessionID, data.ID, data.Index, data.Position, data.Angle, new KeyboardControls(Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.Space)); localHealthBar = healthBarFactory.NewHealthBar(client.UniqueIdentifier, Helpers.GetNewID(), localPlayer.Index, new Vector2(localPlayer.Index*150 + 50, 25)); LocalObjectList.Add(localPlayer,localHealthBar); }