public override void Update(GameTime gameTime) { // mute check checkForMute(); // update mouse and keyboard state mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); SimpleButton.UpdateAll(mouseState, keyboardState); NetIncomingMessage inc; while ((inc = server.ReadMessage()) != null) { Thread.Sleep(1); if (inc.MessageType == NetIncomingMessageType.DiscoveryRequest) { // Create a response and write some example data to it NetOutgoingMessage response = server.CreateMessage(); myTeam = (short)rand.Next(2); response.Write(myTeam); // Send the response to the sender of the request server.SendDiscoveryResponse(response, inc.SenderEndPoint); } else if (inc.MessageType == NetIncomingMessageType.StatusChanged) { NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte(); if (status == NetConnectionStatus.RespondedConnect) { cleanup(); returnControlToStartGame(); return; } } /*else// if (inc.MessageType == NetIncomingMessageType.ConnectionApproval) * { * string str = ""; * foreach (byte b in inc.Data) * { * str += (char)b; * } * str += "balls"; * * //networkEndPoint = inc.SenderEndPoint; * * cleanup(); * returnControlToStartGame(); * return; * }*/ } }
public override void Update(GameTime gameTime) { // mute check checkForMute(); // update mouse and keyboard state mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); if (state == StartMenuState.Joining) { NetIncomingMessage inc; while ((inc = client.ReadMessage()) != null) { Thread.Sleep(1); if (inc.MessageType == NetIncomingMessageType.DiscoveryResponse) { short enemyTeam = inc.ReadInt16(); myTeam = (short)((enemyTeam + 1) % 2); client.Connect(inc.SenderEndPoint); //NetOutgoingMessage msg = client.CreateMessage(); // msg.Write("bowlop"); //client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); cleanup(); returnControlToStartGame(); return; } /*else// if (inc.MessageType == NetIncomingMessageType.Data) * { * cleanup(); * returnControlToStartGame(); * return; * }*/ } } else if (state == StartMenuState.Normal) { SimpleButton.UpdateAll(mouseState, keyboardState); if (checkButtons()) { return; } } }
public override void Update(GameTime gameTime) { int i = Player.Me.UnitArray.Length; // check for exit /*if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) * Game1.Game.Exit(); * if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape)) * { * //Graphics.ToggleFullScreen(); * cleanup(); * returnControl("exit"); * return; * }*/ //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size); Rts.gameTime = gameTime; if (!waitingForMessage) { GameClock += (float)gameTime.ElapsedGameTime.TotalSeconds * GameSpeed; } // count down if (doCountDown()) { return; } // send time sync message if server checkToSync(gameTime); // just checkup if not server checkToCheckup(gameTime); // receive and process network messages receiveData(gameTime); // mute check checkForMute(); // update mouse and keyboard state mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); // pause check /*if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.P)) * allowPause = true; * if (allowPause && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P)) * { * paused ^= true; * allowPause = false; * if (paused) * { * MediaPlayer.Volume /= 4; * //GameTimer.Stop(); * } * else * { * MediaPlayer.Volume *= 4; * //GameTimer.Start(); * } * }*/ // do cleanup of player unit/structure arrays Player.SetNullIDS(); // pathfinding performance info if (Game1.DEBUG) { timeForPathFindingProfiling += gameTime.ElapsedGameTime.TotalMilliseconds; if (timeForPathFindingProfiling >= 500) { double pathFindingTime; lock (Rts.pathFinder.TimeSpentPathFindingLock) { pathFindingTime = Rts.pathFinder.TimeSpentPathFinding.TotalMilliseconds; Rts.pathFinder.TimeSpentPathFinding = TimeSpan.Zero; } pathFindingPercentage = pathFindingTime / timeForPathFindingProfiling * 100; timeForPathFindingProfiling = 0; lock (PathFindRequest.HighPriorityPathFindRequests) { pathFindQueueSize = PathFindRequest.HighPriorityPathFindRequests.Count; } } } //update fps fpsElapsedTime += gameTime.ElapsedGameTime; if (fpsElapsedTime > TimeSpan.FromSeconds(1)) { //Game1.Game.Window.Title = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL"); fpsMessage = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL"); if (Game1.DEBUG) { fpsMessage += " - Unit count: " + Unit.Units.Count; } fpsElapsedTime -= TimeSpan.FromSeconds(1); frameCounter = 0; } // do nothing else if paused if (paused) { return; } // input processing checkForShift(gameTime); checkForCommands(); SimpleButton.UpdateAll(mouseState, keyboardState); checkHotKeyGroups(gameTime); checkForLeftClick(gameTime); checkForRightClick(); checkForTab(); checkForMouseCameraScroll(gameTime); checkForCameraZoom(gameTime); checkForCameraRotate(gameTime); if (keyboardState.IsKeyDown(Keys.Space)) { centerCameraOnSelectedUnits(); } clampCameraToMap(); updatePlacingStructure(); updatePlacedStructures(); if (!placingStructure) { SelectBox.Update(worldViewport, camera); } Shrinker.UpdateShrinkers(gameTime); // do nothing else if waiting for message if (waitingForMessage) { return; } doScheduledActions(); checkForUnitStatusUpdates(gameTime); checkForStructureStatusUpdates(gameTime); //update stats updateStats(gameTime); map.UpdateBoundingBoxes(); updateCogWheels(gameTime); RtsBullet.UpdateAll(gameTime); Resource.UpdateResources(gameTime); Structure.UpdateStructures(gameTime); Unit.UpdateUnits(gameTime, netPeer, connection); UnitAnimation.UpdateAll(gameTime); removeDeadUnitsFromSelections(); applyVisibilityToMap(); }