Game1.cs 5.6 KB

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