AdvancedDemo3.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Text;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Input;
  4. namespace FarseerPhysics.SamplesFramework
  5. {
  6. internal class AdvancedDemo3 : PhysicsGameScreen, IDemoScreen
  7. {
  8. private Border _border;
  9. private TheoJansenWalker _walker;
  10. #region IDemoScreen Members
  11. public string GetTitle()
  12. {
  13. return "Theo Jansen's walker";
  14. }
  15. public string GetDetails()
  16. {
  17. StringBuilder sb = new StringBuilder();
  18. sb.AppendLine("TODO: Add sample description!");
  19. sb.AppendLine(string.Empty);
  20. sb.AppendLine("GamePad:");
  21. sb.AppendLine(" - Switch walker direction: B button");
  22. sb.AppendLine(" - Exit to menu: Back button");
  23. sb.AppendLine(string.Empty);
  24. sb.AppendLine("Keyboard:");
  25. sb.AppendLine(" - Switch walker direction: Space");
  26. sb.AppendLine(" - Exit to menu: Escape");
  27. sb.AppendLine(string.Empty);
  28. sb.AppendLine("Mouse / Touchscreen");
  29. sb.AppendLine(" - Switch walker direction: Right click");
  30. return sb.ToString();
  31. }
  32. #endregion
  33. public override void LoadContent()
  34. {
  35. base.LoadContent();
  36. HasCursor = false;
  37. World.Gravity = new Vector2(0, 9.82f);
  38. _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
  39. _walker = new TheoJansenWalker(World, this, Vector2.Zero);
  40. }
  41. public override void HandleInput(InputHelper input, GameTime gameTime)
  42. {
  43. if (input.IsNewButtonPress(Buttons.B) ||
  44. input.IsNewMouseButtonPress(MouseButtons.RightButton) ||
  45. input.IsNewKeyPress(Keys.Space))
  46. {
  47. _walker.Reverse();
  48. }
  49. base.HandleInput(input, gameTime);
  50. }
  51. public override void Draw(GameTime gameTime)
  52. {
  53. _walker.Draw();
  54. _border.Draw();
  55. base.Draw(gameTime);
  56. }
  57. }
  58. }