public void WriteScores() { Point location = new Point(Constants.ScoreXOrigin + windowBounds.X, Constants.ScoreYOrigin + windowBounds.Y); Point scoreLocation = location; scoreLocation.X += Constants.ScoreOffset; ship.DrawHostName(surfaceSecondary, location, 0xFFFFFF); // this ship is white... Word word = GetWordFromScore(ship.Score.ToString()); int color = 0xFFFFFF; word.Draw(surfaceSecondary, color, Constants.LetterSpacing, scoreLocation); int shipIndex = 0; lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) { continue; } location.Y += Constants.ScoreVerticalSpacing; scoreLocation.Y += Constants.ScoreVerticalSpacing; player.Ship.DrawHostName(surfaceSecondary, location, shipColors[shipIndex].ToArgb()); word = GetWordFromScore(player.Ship.Score.ToString()); word.Draw(surfaceSecondary, shipColors[shipIndex].ToArgb(), Constants.LetterSpacing, scoreLocation); shipIndex = (shipIndex + 1) % shipColors.Length; } } }
public void DrawHostName(Surface surface, Point location, int color) { if (hostName == null) { return; } if (hostNameWord == null) { hostNameWord = new Word(hostName, Constants.LetterSize); } hostNameWord.Draw(surface, color, Constants.LetterSpacing, location); }
public void MainLoop() { float minFrameTime = gameSettings.GameSpeed * 0.005f; if (lastFrameTime < minFrameTime) { lastFrameTime += DXUtil.Timer(DirectXTimer.GetElapsedTime); return; } lastFrameTime = 0.0f; try { if (gameState == GameStates.Paused) { Word paused = new Word("PAUSED", Constants.LetterSize * 1.5f); paused.Draw(surfaceSecondary, Color.White.ToArgb(), Constants.LetterSpacing * 2, new Point(windowBounds.Left + 50, windowBounds.Top + 50)); surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); } // Clear the ship's sound flags ship.Sounds = (Sounds)0; // process input HandleKeys(); if (gameState != GameStates.Running) { return; } surfaceSecondary.ColorFill(Color.Black); surfaceSecondary.DrawWidth = 1; // update my position, and tell others about it... ship.UpdatePosition(); // update my state, and draw myself... ship.UpdateState(); //If there are other players, send them our ship info if (netPeer.InSession && otherPlayers.Count > 0) { SendMyPlayerUpdate(); } WriteScores(); stars.Draw(surfaceSecondary); int shipColor = Color.White.ToArgb(); int shotColor = Color.White.ToArgb(); ship.Draw(surfaceSecondary, shipColor, shotColor); // Handle other ships // walk through all other players. For each player // 1) draw the ship // 2) check to see whether the other ship has killed us // 3) figure the score // 4) see if we need to time-out this ship int shipIndex = 0; Sounds otherShipSounds = (Sounds)0; DateTime now = DateTime.Now; lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) { continue; } player.Ship.Draw(surfaceSecondary, shipColors[shipIndex].ToArgb(), shotColor); shipIndex = (shipIndex + 1) % shipColors.Length; ship.TestShip(player); otherShipSounds |= player.Ship.Sounds; // if we haven't gotten an update in a while, // mark the player as inactive... TimeSpan delta = now - player.UpdateTime; if (delta.Seconds > Constants.RemoteTickTimeout) { player.Active = false; } } } // Draw the sun only if the "Black Hole" option isn't enabled if (!blackHole) { sun.Draw(surfaceSecondary); } surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); PlaySounds(otherShipSounds); } catch (SurfaceLostException) { // The surface can be lost if power saving // mode kicks in, or any other number of reasons. CreateSurfaces(); } }
public void MainLoop() { float minFrameTime = gameSettings.GameSpeed * 0.005f; if (lastFrameTime < minFrameTime) { lastFrameTime += DXUtil.Timer(DirectXTimer.GetElapsedTime); return; } lastFrameTime = 0.0f; try { if (gameState == GameStates.Paused) { Word paused = new Word("PAUSED", Constants.LetterSize * 1.5f); paused.Draw(surfaceSecondary, Color.White.ToArgb(), Constants.LetterSpacing * 2, new Point(windowBounds.Left + 50, windowBounds.Top + 50)); surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); } // Clear the ship's sound flags ship.Sounds = (Sounds) 0; // process input HandleKeys(); if (gameState != GameStates.Running) return; surfaceSecondary.ColorFill(Color.Black); surfaceSecondary.DrawWidth = 1; // update my position, and tell others about it... ship.UpdatePosition(); // update my state, and draw myself... ship.UpdateState(); //If there are other players, send them our ship info if (netPeer.InSession && otherPlayers.Count > 0) SendMyPlayerUpdate(); WriteScores(); stars.Draw(surfaceSecondary); int shipColor = Color.White.ToArgb(); int shotColor = Color.White.ToArgb(); ship.Draw(surfaceSecondary, shipColor, shotColor); // Handle other ships // walk through all other players. For each player // 1) draw the ship // 2) check to see whether the other ship has killed us // 3) figure the score // 4) see if we need to time-out this ship int shipIndex = 0; Sounds otherShipSounds = (Sounds) 0; DateTime now = DateTime.Now; lock (otherPlayers) { foreach (RemotePlayer player in otherPlayers.Values) { if (!player.Active) continue; player.Ship.Draw(surfaceSecondary, shipColors[shipIndex].ToArgb(), shotColor); shipIndex = (shipIndex + 1) % shipColors.Length; ship.TestShip(player); otherShipSounds |= player.Ship.Sounds; // if we haven't gotten an update in a while, // mark the player as inactive... TimeSpan delta = now - player.UpdateTime; if (delta.Seconds > Constants.RemoteTickTimeout) { player.Active = false; } } } // Draw the sun only if the "Black Hole" option isn't enabled if (!blackHole) sun.Draw(surfaceSecondary); surfacePrimary.Draw(surfaceSecondary, DrawFlags.DoNotWait); PlaySounds(otherShipSounds); } catch(SurfaceLostException) { // The surface can be lost if power saving // mode kicks in, or any other number of reasons. CreateSurfaces(); } }