Game1.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13. namespace GooCursor
  14. {
  15. /// <summary>
  16. /// This is the main type for your game
  17. /// </summary>
  18. public class Game1 : Microsoft.Xna.Framework.Game
  19. {
  20. GraphicsDeviceManager graphics;
  21. SpriteBatch spriteBatch;
  22. SpriteFont spriteFont;
  23. Cursor cursor;
  24. public Game1()
  25. {
  26. graphics = new GraphicsDeviceManager(this);
  27. Content.RootDirectory = "Content";
  28. cursor = new Cursor(this,10);
  29. cursor.BorderColor = Color.White;
  30. cursor.FillColor = Color.Black;
  31. Components.Add(cursor);
  32. //graphics.IsFullScreen = true;
  33. //IsMouseVisible = false;
  34. }
  35. /// <summary>
  36. /// Allows the game to perform any initialization it needs to before starting to run.
  37. /// This is where it can query for any required services and load any non-graphic
  38. /// related content. Calling base.Initialize will enumerate through any components
  39. /// and initialize them as well.
  40. /// </summary>
  41. protected override void Initialize()
  42. {
  43. // TODO: Add your initialization logic here
  44. base.Initialize();
  45. }
  46. /// <summary>
  47. /// LoadContent will be called once per game and is the place to load
  48. /// all of your content.
  49. /// </summary>
  50. protected override void LoadContent()
  51. {
  52. // Create a new SpriteBatch, which can be used to draw textures.
  53. spriteBatch = new SpriteBatch(GraphicsDevice);
  54. spriteFont = Content.Load<SpriteFont>("SimpleFont");
  55. }
  56. /// <summary>
  57. /// UnloadContent will be called once per game and is the place to unload
  58. /// all content.
  59. /// </summary>
  60. protected override void UnloadContent()
  61. {
  62. // TODO: Unload any non ContentManager content here
  63. }
  64. KeyboardState lastState = Keyboard.GetState();
  65. KeyboardState state = Keyboard.GetState();
  66. /// <summary>
  67. /// Allows the game to run logic such as updating the world,
  68. /// checking for collisions, gathering input, and playing audio.
  69. /// </summary>
  70. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  71. protected override void Update(GameTime gameTime)
  72. {
  73. // Allows the game to exit
  74. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  75. this.Exit();
  76. lastState = state;
  77. state = Keyboard.GetState();
  78. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
  79. if (state.IsKeyDown(Keys.Q))
  80. cursor.StartScale += 1.0f * elapsed;
  81. if (state.IsKeyDown(Keys.A))
  82. cursor.StartScale -= 1.0f * elapsed;
  83. if (state.IsKeyDown(Keys.W))
  84. cursor.EndScale += 1.0f * elapsed;
  85. if (state.IsKeyDown(Keys.S))
  86. cursor.EndScale -= 1.0f * elapsed;
  87. if (state.IsKeyDown(Keys.E))
  88. cursor.LerpExponent += 1.0f * elapsed;
  89. if (state.IsKeyDown(Keys.D))
  90. cursor.LerpExponent -= 1.0f * elapsed;
  91. if (state.IsKeyDown(Keys.R))
  92. cursor.BorderSize += 10.0f * elapsed;
  93. if (state.IsKeyDown(Keys.F))
  94. cursor.BorderSize -= 10.0f * elapsed;
  95. if (state.IsKeyDown(Keys.T))
  96. cursor.TrailStiffness += 1000.0f * elapsed;
  97. if (state.IsKeyDown(Keys.G))
  98. cursor.TrailStiffness -= 1000.0f * elapsed;
  99. if (state.IsKeyDown(Keys.Y))
  100. cursor.TrailDamping += 100.0f * elapsed;
  101. if (state.IsKeyDown(Keys.H))
  102. cursor.TrailDamping -= 100.0f * elapsed;
  103. if (state.IsKeyDown(Keys.U))
  104. cursor.TrailNodeMass += 1.0f * elapsed;
  105. if (state.IsKeyDown(Keys.J))
  106. cursor.TrailNodeMass -= 1.0f * elapsed;
  107. if (state.IsKeyDown(Keys.F) && lastState.IsKeyUp(Keys.F))
  108. graphics.ToggleFullScreen();
  109. base.Update(gameTime);
  110. }
  111. /// <summary>
  112. /// This is called when the game should draw itself.
  113. /// </summary>
  114. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  115. protected override void Draw(GameTime gameTime)
  116. {
  117. GraphicsDevice.Clear(Color.CornflowerBlue);
  118. base.Draw(gameTime);
  119. spriteBatch.Begin();
  120. DrawString("[Q/A] Start Scale : " + cursor.StartScale, new Vector2(20, 20));
  121. DrawString("[W/S] End Scale : " + cursor.EndScale, new Vector2(20, 40));
  122. DrawString("[E/D] Lerp Exponent : " + cursor.LerpExponent, new Vector2(20, 60));
  123. DrawString("[R/F] Border Size : " + cursor.BorderSize, new Vector2(20, 80));
  124. DrawString("[T/G] Stiffness : " + cursor.TrailStiffness, new Vector2(400, 20));
  125. DrawString("[Y/H] Damping : " + cursor.TrailDamping, new Vector2(400, 40));
  126. DrawString("[U/J] Node Mass : " + cursor.TrailNodeMass, new Vector2(400, 60));
  127. spriteBatch.End();
  128. }
  129. private void DrawString(String text, Vector2 position)
  130. {
  131. spriteBatch.DrawString(spriteFont, text, position + new Vector2(1, 1), Color.Black);
  132. spriteBatch.DrawString(spriteFont, text, position , Color.White);
  133. }
  134. }
  135. }