2
0

SimpleDemo6.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Text;
  2. using Microsoft.Xna.Framework;
  3. namespace FarseerPhysics.SamplesFramework
  4. {
  5. public class SimpleDemo6 : PhysicsGameScreen, IDemoScreen
  6. {
  7. private Agent _agent;
  8. private Border _border;
  9. private Spider[] _spiders;
  10. #region IDemoScreen Members
  11. public string GetTitle()
  12. {
  13. return "Dynamic Angle Joints";
  14. }
  15. public string GetDetails()
  16. {
  17. StringBuilder sb = new StringBuilder();
  18. sb.AppendLine("This demo demonstrates the use of revolute joints combined");
  19. sb.AppendLine("with angle joints that have a dynamic target angle.");
  20. sb.AppendLine(string.Empty);
  21. sb.AppendLine("GamePad:");
  22. sb.AppendLine(" - Rotate agent: left and right triggers");
  23. sb.AppendLine(" - Move agent: right thumbstick");
  24. sb.AppendLine(" - Move cursor: left thumbstick");
  25. sb.AppendLine(" - Grab object (beneath cursor): A button");
  26. sb.AppendLine(" - Drag grabbed object: left thumbstick");
  27. sb.AppendLine(" - Exit to menu: Back button");
  28. sb.AppendLine(string.Empty);
  29. sb.AppendLine("Keyboard:");
  30. sb.AppendLine(" - Rotate agent: left and right arrows");
  31. sb.AppendLine(" - Move agent: A,S,D,W");
  32. sb.AppendLine(" - Exit to menu: Escape");
  33. sb.AppendLine(string.Empty);
  34. sb.AppendLine("Mouse / Touchscreen");
  35. sb.AppendLine(" - Grab object (beneath cursor): Left click");
  36. sb.AppendLine(" - Drag grabbed object: move mouse / finger");
  37. return sb.ToString();
  38. }
  39. #endregion
  40. public override void LoadContent()
  41. {
  42. base.LoadContent();
  43. World.Gravity = new Vector2(0f, 20f);
  44. _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
  45. _agent = new Agent(World, this, new Vector2(0f, 10f));
  46. _spiders = new Spider[8];
  47. for (int i = 0; i < _spiders.Length; i++)
  48. {
  49. _spiders[i] = new Spider(World, this, new Vector2(0f, 8f - (i + 1) * 2f));
  50. }
  51. SetUserAgent(_agent.Body, 1000f, 400f);
  52. }
  53. public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
  54. {
  55. if (IsActive)
  56. {
  57. for (int i = 0; i < _spiders.Length; i++)
  58. {
  59. _spiders[i].Update(gameTime);
  60. }
  61. }
  62. base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
  63. }
  64. public override void Draw(GameTime gameTime)
  65. {
  66. ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);
  67. _agent.Draw();
  68. for (int i = 0; i < _spiders.Length; i++)
  69. {
  70. _spiders[i].Draw();
  71. }
  72. ScreenManager.SpriteBatch.End();
  73. _border.Draw();
  74. base.Draw(gameTime);
  75. }
  76. }
  77. }