Game1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. }
  33. /// <summary>
  34. /// Allows the game to perform any initialization it needs to before starting to run.
  35. /// This is where it can query for any required services and load any non-graphic
  36. /// related content. Calling base.Initialize will enumerate through any components
  37. /// and initialize them as well.
  38. /// </summary>
  39. protected override void Initialize()
  40. {
  41. // TODO: Add your initialization logic here
  42. base.Initialize();
  43. }
  44. /// <summary>
  45. /// LoadContent will be called once per game and is the place to load
  46. /// all of your content.
  47. /// </summary>
  48. protected override void LoadContent()
  49. {
  50. // Create a new SpriteBatch, which can be used to draw textures.
  51. spriteBatch = new SpriteBatch(GraphicsDevice);
  52. spriteFont = Content.Load<SpriteFont>("SimpleFont");
  53. }
  54. /// <summary>
  55. /// UnloadContent will be called once per game and is the place to unload
  56. /// all content.
  57. /// </summary>
  58. protected override void UnloadContent()
  59. {
  60. // TODO: Unload any non ContentManager content here
  61. }
  62. /// <summary>
  63. /// Allows the game to run logic such as updating the world,
  64. /// checking for collisions, gathering input, and playing audio.
  65. /// </summary>
  66. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  67. protected override void Update(GameTime gameTime)
  68. {
  69. // Allows the game to exit
  70. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  71. this.Exit();
  72. KeyboardState state = Keyboard.GetState();
  73. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
  74. if (state.IsKeyDown(Keys.Q))
  75. cursor.StartScale += 1.0f * elapsed;
  76. if (state.IsKeyDown(Keys.A))
  77. cursor.StartScale -= 1.0f * elapsed;
  78. if (state.IsKeyDown(Keys.W))
  79. cursor.EndScale += 1.0f * elapsed;
  80. if (state.IsKeyDown(Keys.S))
  81. cursor.EndScale -= 1.0f * elapsed;
  82. if (state.IsKeyDown(Keys.E))
  83. cursor.LerpExponent += 1.0f * elapsed;
  84. if (state.IsKeyDown(Keys.D))
  85. cursor.LerpExponent -= 1.0f * elapsed;
  86. if (state.IsKeyDown(Keys.R))
  87. cursor.BorderSize += 10.0f * elapsed;
  88. if (state.IsKeyDown(Keys.F))
  89. cursor.BorderSize -= 10.0f * elapsed;
  90. if (state.IsKeyDown(Keys.T))
  91. cursor.TrailStiffness += 1000.0f * elapsed;
  92. if (state.IsKeyDown(Keys.G))
  93. cursor.TrailStiffness -= 1000.0f * elapsed;
  94. if (state.IsKeyDown(Keys.Y))
  95. cursor.TrailDamping += 100.0f * elapsed;
  96. if (state.IsKeyDown(Keys.H))
  97. cursor.TrailDamping -= 100.0f * elapsed;
  98. if (state.IsKeyDown(Keys.U))
  99. cursor.TrailNodeMass += 1.0f * elapsed;
  100. if (state.IsKeyDown(Keys.J))
  101. cursor.TrailNodeMass -= 1.0f * elapsed;
  102. base.Update(gameTime);
  103. }
  104. /// <summary>
  105. /// This is called when the game should draw itself.
  106. /// </summary>
  107. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  108. protected override void Draw(GameTime gameTime)
  109. {
  110. GraphicsDevice.Clear(Color.CornflowerBlue);
  111. base.Draw(gameTime);
  112. spriteBatch.Begin();
  113. DrawString("[Q/A] Start Scale : " + cursor.StartScale, new Vector2(20, 20));
  114. DrawString("[W/S] End Scale : " + cursor.EndScale, new Vector2(20, 40));
  115. DrawString("[E/D] Lerp Exponent : " + cursor.LerpExponent, new Vector2(20, 60));
  116. DrawString("[R/F] Border Size : " + cursor.BorderSize, new Vector2(20, 80));
  117. DrawString("[T/G] Stiffness : " + cursor.TrailStiffness, new Vector2(400, 20));
  118. DrawString("[Y/H] Damping : " + cursor.TrailDamping, new Vector2(400, 40));
  119. DrawString("[U/J] Node Mass : " + cursor.TrailNodeMass, new Vector2(400, 60));
  120. spriteBatch.End();
  121. }
  122. private void DrawString(String text, Vector2 position)
  123. {
  124. spriteBatch.DrawString(spriteFont, text, position + new Vector2(1, 1), Color.Black);
  125. spriteBatch.DrawString(spriteFont, text, position , Color.White);
  126. }
  127. }
  128. }