/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { /*if (input.MouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released) * { * for (int i = 0; i < clientWindows.Count; i++) * { * if (input.MouseState.X > clientWindows[i].windowRect.Left && * input.MouseState.X < clientWindows[i].windowRect.Right && * input.MouseState.Y > clientWindows[i].windowRect.Top && * input.MouseState.Y < clientWindows[i].windowRect.Bottom) * { * DraggingWindow = i; * } * } * } * else if (input.MouseState.LeftButton == ButtonState.Released && input.PreviousMouseState.LeftButton == ButtonState.Pressed) * { * DraggingWindow = -1; * } * * if (DraggingWindow >= clientWindows.Count) * { * DraggingWindow = -1; * } * else if (DraggingWindow >= 0) * { * clientWindows[DraggingWindow].windowRect.X = input.MouseState.X - (clientWindows[DraggingWindow].windowRect.Width / 2); * clientWindows[DraggingWindow].windowRect.Y = input.MouseState.Y - (clientWindows[DraggingWindow].windowRect.Height / 2); * }*/ /*if (controllingBall) * { * serverBall.Position += serverBall.Direction * serverBall.Speed; * * //Is this the size of the server ? * if (serverBall.Position.Y > GetMaxWindowY())//graphics.GraphicsDevice.Viewport.Height) * { * serverBall.Direction.Y = -1; * } * else if (serverBall.Position.Y < 0) * { * serverBall.Direction.Y = 1; * } * * if (serverBall.Position.X > GetMaxWindowX())//graphics.GraphicsDevice.Viewport.Width) * { * serverBall.Direction.X = -1; * } * else if (serverBall.Position.X < 0) * { * serverBall.Direction.X = 1; * } * * if(serverBall.Direction != Vector2.Zero) * serverBall.Direction.Normalize(); * //Should be serverBall.Direction = serverBall.Direction.Normalize(); * * Rectangle clientRect; * Rectangle ballRect = new Rectangle((int)serverBall.Position.X, * (int)serverBall.Position.Y, 4, 4); //HARDCODED BAAAAAAAAADDDDD -AB * for (int i = 0; i < clientWindows.Count; i++) * { * clientRect = clientWindows[i].windowRect; * if (clientRect.Intersects(ballRect)) * { * if (!server.Clients[i].Writing) * { * controllingBall = false; * ClientControllingBall = i; * serverBall.Position.Y -= clientRect.Top; * serverBall.Position.X -= clientRect.Left; * serverBall.Position *= 10; * serverBall.Speed *= 10; * serverBall.Direction *= 10; * * server.BeginWrite(onWrite, i, serverBall); * } * } * } * } * else*/ if (server.Clients.Count <= 0 || clientWindows.Count <= 0) { return; } if (serverBall.FindNewScreen) { if (serverBall.Enter == Entrance.Left) { if (ClientControllingBall == clientWindows.Count - 1) { serverBall.Direction.X *= -1; } else { ClientControllingBall++; } } else { if (ClientControllingBall == 0) { serverBall.Direction.X *= -1; } else { ClientControllingBall--; } } serverBall.Position.Y -= clientWindows[ClientControllingBall].windowRect.Top; serverBall.Position.X -= clientWindows[ClientControllingBall].windowRect.Left; serverBall.Position *= 10; serverBall.Speed *= 10; serverBall.Direction *= 10; if (!server.Clients[ClientControllingBall].Writing) { server.BeginWrite(onWrite, ClientControllingBall, serverBall); serverBall.FindNewScreen = false; } } else if (!server.Clients[ClientControllingBall].Reading) { server.BeginRead(onRead, ClientControllingBall); } base.Update(gameTime); }