public void UpdateView(Vector2 pos, float dt, int clientId) { // Updated by the player that owns it and sent to client Vector2 prev = ViewPosition; ViewPosition = Vector2.Lerp(prev, pos, dt); float halfViewX = ViewSize.X * 0.5f; float halfViewY = ViewSize.Y * 0.5f; if (ViewPosition.X <= halfViewX) { ViewPosition.X = halfViewX; } else if (ViewPosition.X >= GameSimulation.instance.MapWidth() - halfViewX) { ViewPosition.X = GameSimulation.instance.MapWidth() - halfViewX; } if (ViewPosition.Y <= halfViewY) { ViewPosition.Y = halfViewY; } else if (ViewPosition.Y >= GameSimulation.instance.MapHeight() - halfViewY) { ViewPosition.Y = GameSimulation.instance.MapHeight() - halfViewY; } // Send packet of this calculated view centre PacketDefs.ViewUpdatePacket vp = new PacketDefs.ViewUpdatePacket(ViewPosition.X, ViewPosition.Y); ServerManager.instance.SendUdp(clientId, fastJSON.JSON.ToJSON(vp, PacketDefs.JsonParams())); }
private void UpdateSimulation(float dt) { // Loop through game objects for (int i = 0; i < m_UpdateObjects.Count; ++i) { GameObject gameObj = m_UpdateObjects[i]; if (gameObj != null) { // We will send a packet to each client from updateable things such as enemies gameObj.Update(); // Send this player to all other clients, ensure we send one update when deactivated if (!gameObj.SentInactivePacket) { // Send out the new position update here PacketDefs.PlayerInputUpdatePacket updatePacket = new PacketDefs.PlayerInputUpdatePacket( gameObj.UnqId(), gameObj.Position.X, gameObj.Position.Y, gameObj.FrameX(), gameObj.FrameY(), gameObj.Active); ServerManager.instance.SendAllUdp(fastJSON.JSON.ToJSON( updatePacket, PacketDefs.JsonParams())); } if (!gameObj.Active && !gameObj.SentInactivePacket) { // So only send one packet out when deactivated // This will be set back to false when Active prop is set to true gameObj.SentInactivePacket = true; } } } if (m_ShouldClearData) { m_ShouldClearData = false; ClearGameData(); } }