WaypointList.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // WaypointList.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using Microsoft.Xna.Framework;
  10. using Microsoft.Xna.Framework.Audio;
  11. // using Microsoft.Xna.Framework.GamerServices;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using Microsoft.Xna.Framework.Input;
  14. //using Microsoft.Xna.Framework.Storage;
  15. using Microsoft.Xna.Framework.Content;
  16. using Microsoft.Xna.Framework.Media;
  17. namespace Waypoint
  18. {
  19. /// <summary>
  20. /// WaypointList is a drawable List of screen locations
  21. /// </summary>
  22. public class WaypointList : Queue<Vector2>
  23. {
  24. // Draw data
  25. Texture2D waypointTexture;
  26. Vector2 waypointCenter;
  27. /// <summary>
  28. /// Load the WaypointList's texture resources
  29. /// </summary>
  30. /// <param name="content"></param>
  31. public void LoadContent(ContentManager content)
  32. {
  33. waypointTexture = content.Load<Texture2D>("dot");
  34. waypointCenter =
  35. new Vector2(waypointTexture.Width / 2, waypointTexture.Height / 2);
  36. }
  37. /// <summary>
  38. /// Draw the waypoint list, fading from red for the next waypoint to blue
  39. /// for the last
  40. /// </summary>
  41. /// <param name="spriteBatch"></param>
  42. public void Draw(SpriteBatch spriteBatch)
  43. {
  44. if (Count == 1)
  45. {
  46. // If we only have a single waypoint in the list we don�t have to
  47. // worry about creating a nice color gradient, so we just draw it
  48. // as completely red here
  49. spriteBatch.Begin();
  50. spriteBatch.Draw(waypointTexture, Peek(), null, Color.Red,
  51. 0f, waypointCenter, 1f, SpriteEffects.None, 0f);
  52. spriteBatch.End();
  53. }
  54. else if (Count > 0)
  55. {
  56. // In this case we have more than one waypoint on the list, so we
  57. // want to fade smoothly from red for the first and blue for the
  58. // last so we can tell visually what order they�re in
  59. float numberPoints = this.Count - 1;
  60. float i = 0;
  61. spriteBatch.Begin();
  62. foreach (Vector2 location in this)
  63. {
  64. // This creates a gradient between 0 for the first waypoint on
  65. // the list and 1 for the last, 0 creates a color that's
  66. // completely red and 1 creates a color that's completely blue
  67. spriteBatch.Draw(waypointTexture, location, null,
  68. new Color(Vector4.Lerp(Color.Red.ToVector4(),
  69. Color.Blue.ToVector4(), i / numberPoints)),
  70. 0f, waypointCenter, 1f, SpriteEffects.None, 0f);
  71. spriteBatch.Draw(waypointTexture, location, null, Color.Blue,
  72. 0f, waypointCenter, 1f, SpriteEffects.None, 0f);
  73. i++;
  74. }
  75. spriteBatch.End();
  76. }
  77. }
  78. }
  79. }