/// <summary> /// Draw method for when the game is in the playing state. /// </summary> /// <param name="gameTime"></param> void DrawPlaying(GameTime gameTime) { /* Draw world elements */ WorldSpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, Camera.GetTransformation()); DrawMap(); double time = gameTime.ElapsedGameTime.TotalSeconds; DrawGameplayObjects(); if (ActivePlayer.IsPlacingTower) { DrawPendingTower(); } WorldSpriteBatch.End(); /* Draw effect elements */ BoltSpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Camera.Transform); foreach (Bolt e in Effects) { e.Draw(BoltSpriteBatch); } BoltSpriteBatch.End(); /* Draw UI elements */ ActivePlayer.DrawUI(); DrawDebug(); }
/// <summary> /// Draws a health bar given the max and current health values as well as a bounding rectangle. /// </summary> /// <param name="healthFraction">Fraction of health that is remaining</param> /// <param name="rectangle">A bounding rectangle in which the health bar will be rendered.</param> public static void DrawHealthBar(double healthFraction, Rectangle rectangle) { // Render black border around the health bar WorldSpriteBatch.Draw(Art.Pixel, rectangle, Color.Black); // Width of the health bar that will be filled int filledWidth = (int)Math.Ceiling((rectangle.Width - 2) * healthFraction); Rectangle filledBar = new Rectangle(rectangle.X + 1, rectangle.Y + 1, filledWidth, rectangle.Height - 2); // Render filled section of health bar WorldSpriteBatch.Draw(Art.Pixel, filledBar, Color.White); // Width of the health bar that is missing int missingWidth = rectangle.Width - filledWidth - 2; if (missingWidth != 0) { Rectangle missingBar = new Rectangle(rectangle.X + filledWidth + 1, rectangle.Y + 1, missingWidth, rectangle.Height - 2); // Render missing section of health bar WorldSpriteBatch.Draw(Art.Pixel, missingBar, Color.Red); } }