LevelSelector.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Tutorial029.Misc;
  10. using Tutorial029.Models;
  11. using Tutorial029.Sprites;
  12. namespace Tutorial029.Controls
  13. {
  14. public class LevelSelector : Component
  15. {
  16. private Player _player;
  17. private List<ScrollingBackground> _scrollingBackgrounds;
  18. private Vector2 _position;
  19. private float _scale = 1f;
  20. public bool IsMouseHovering { get; set; }
  21. public Viewport Viewport
  22. {
  23. get
  24. {
  25. return new Viewport((int)Position.X, (int)Position.Y, Game1.ScreenWidth / 4, Game1.ScreenHeight / 4);
  26. }
  27. }
  28. public float Scale
  29. {
  30. get { return _scale; }
  31. set
  32. {
  33. _scale = value;
  34. }
  35. }
  36. public Vector2 Position
  37. {
  38. get { return _position; }
  39. set
  40. {
  41. _position = value;
  42. }
  43. }
  44. public string Name
  45. {
  46. get
  47. {
  48. return LevelModel.Name;
  49. }
  50. }
  51. private readonly LevelModel LevelModel;
  52. public LevelSelector(Player player, LevelModel levelModel)
  53. {
  54. _player = player;
  55. LevelModel = levelModel;
  56. }
  57. public void LoadContent(ContentManager content)
  58. {
  59. }
  60. public override void Update(GameTime gameTime)
  61. {
  62. if (!IsMouseHovering)
  63. return;
  64. _player.Update(gameTime);
  65. foreach (var sb in LevelModel.ScrollingBackgrounds)
  66. sb.Update(gameTime);
  67. }
  68. public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  69. {
  70. _player.Draw(gameTime, spriteBatch);
  71. foreach (var sb in LevelModel.ScrollingBackgrounds)
  72. sb.Draw(gameTime, spriteBatch);
  73. }
  74. }
  75. }