2
0

SimpleDemo4.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Text;
  2. using Microsoft.Xna.Framework;
  3. namespace FarseerPhysics.SamplesFramework
  4. {
  5. internal class SimpleDemo4 : PhysicsGameScreen, IDemoScreen
  6. {
  7. #region IDemoScreen Members
  8. public string GetTitle()
  9. {
  10. return "Stacked Objects";
  11. }
  12. public string GetDetails()
  13. {
  14. StringBuilder sb = new StringBuilder();
  15. sb.AppendLine("This demo shows the stacking stability of the engine.");
  16. sb.AppendLine("It shows a stack of rectangular bodies stacked in the shape of a pyramid.");
  17. sb.AppendLine(string.Empty);
  18. sb.AppendLine("GamePad:");
  19. sb.AppendLine(" - Rotate agent: left and right triggers");
  20. sb.AppendLine(" - Move agent: right thumbstick");
  21. sb.AppendLine(" - Move cursor: left thumbstick");
  22. sb.AppendLine(" - Grab object (beneath cursor): A button");
  23. sb.AppendLine(" - Drag grabbed object: left thumbstick");
  24. sb.AppendLine(" - Exit to menu: Back button");
  25. sb.AppendLine(string.Empty);
  26. sb.AppendLine("Keyboard:");
  27. sb.AppendLine(" - Rotate agent: left and right arrows");
  28. sb.AppendLine(" - Move agent: A,S,D,W");
  29. sb.AppendLine(" - Exit to menu: Escape");
  30. sb.AppendLine(string.Empty);
  31. sb.AppendLine("Mouse / Touchscreen");
  32. sb.AppendLine(" - Grab object (beneath cursor): Left click");
  33. sb.AppendLine(" - Drag grabbed object: move mouse / finger");
  34. return sb.ToString();
  35. }
  36. #endregion
  37. #if XBOX || WINDOWS_PHONE
  38. //Xbox360 / WP7 can't handle as many geometries
  39. private const int PyramidBaseBodyCount = 10;
  40. #else
  41. private const int PyramidBaseBodyCount = 14;
  42. #endif
  43. private Agent _agent;
  44. private Pyramid _pyramid;
  45. private Border _border;
  46. public override void LoadContent()
  47. {
  48. base.LoadContent();
  49. World.Gravity = new Vector2(0f, 20f);
  50. _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
  51. _agent = new Agent(World, this, new Vector2(5f, -10f));
  52. _pyramid = new Pyramid(World, this, new Vector2(0f, 15f), PyramidBaseBodyCount, 1f);
  53. SetUserAgent(_agent.Body, 1000f, 400f);
  54. }
  55. public override void Draw(GameTime gameTime)
  56. {
  57. ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);
  58. _agent.Draw();
  59. _pyramid.Draw();
  60. ScreenManager.SpriteBatch.End();
  61. _border.Draw();
  62. base.Draw(gameTime);
  63. }
  64. }
  65. }