Cross platform physics games - NDC 2014

1,093 views

Published on

My slides from NDC 2014 regarding how to build games using MonoGame and Farseer Physics.

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,093
On SlideShare
0
From Embeds
0
Number of Embeds
83
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cross platform physics games - NDC 2014

  1. 1. Cross-platform physics games Using MonoGame and Farseer Physics Rune Andreas Grimstad @runegri Capgemini Norge
  2. 2. What to expect • Lots of code! • Intoduction to MonoGame and Farseer • Playable demos • Code on GitHub for you to play with :-)
  3. 3. What NOT to expect • Deep dive into the features • That would take days... • 3D games • Visit Richard Garside’s talk tomorrow at 11:40 • A complete game
  4. 4. Who am I? • Rune Andreas Grimstad • Lives in Trondheim • Works for Cagemini • Focus on .Net and anything mobile • Programming since I was 8 years old...
  5. 5. Why games programming? • Not my job! • Fun • Learning • Becoming a billionaire after creating the next Angry Birds Flappy Bird!
  6. 6. MonoGame • Open Source implementation of XNA 4 • Runs everywhere • C# / .Net • Xamarin
  7. 7. Fez
  8. 8. Bastion
  9. 9. Draw a Stickman Epic
  10. 10. Transistor
  11. 11. MonoGame – getting it • Download from monogame.net • Clone from GitHub • NuGet
  12. 12. MonoGame – features • Supports all features of XNA4 (more or less) • 2D • 3D • Content pipeline • Input • Sound and music • Networking • It’s a bare-bones framework…
  13. 13. Enough background!
  14. 14. How MonoGame works - The Game Loop Initialize and load content Update game state Draw everything Unload content
  15. 15. How MonoGame works - Creating content • Most file types are supported • Either use an XNA content project • Requires XNA Game Studio, so Windows only • Create a MonoGame Content project • Or use the MonoGame Content Builder • Runs everywhere • Not 100% done yet, but getting close
  16. 16. How MonoGame works - Loading content • Using the ContentManager.Load method • Usually Content.Load<Texture2D>("spaceship"); • You can also load other resources this way • SpriteFont, SoundEffect, Song, and so on • Store the files in the Content folder in your project • Build Action – Content • Copy to Output Directory – Copy if newer
  17. 17. How MonoGame works - Drawing stuff • Use the SpriteBatch class • Start with SpriteBatch.Begin • Do your SpriteBatch.Draw calls • End with SpriteBatch.End • Try to limit how many SpriteBatches you use
  18. 18. Demo 1 • The basics • Draw a sprite on screen • Content • Animation • Camera, pan & zoom • Input
  19. 19. Demo 1 – What did we learn? • Game loop • Content • SpriteBatch • Texture atlas • Camera • Input
  20. 20. All that from this little guy!
  21. 21. But there is more
  22. 22. Farseer physics Farseer Physics Engine is a collision detection system with realistic physics responses.
  23. 23. Farseer physics • 2D Physics simulation • Collision detection • Objects with any shape • Friction and restitution • Joints • Gravity ... and more
  24. 24. Farseer physics – getting it • NuGet • Download from https://farseerphysics.codeplex.com/ • Build from sources • The easiest way to combine with MonoGame?
  25. 25. One thing to be aware of • Farseer uses the KMS system (Kilo, Meters, Seconds) • Use the ConvertUnits class • Init with SetDisplayUnitToSimUnitRatio • Use ToDisplayUnits and ToSimUnits Your screen Display coordinates: 1920 x 1080 pixels Farseer coordinates: 19.2 x 10.8 meters
  26. 26. Demo 2 – more Bubble Bobble! • A simple platformer • Simulates a world • Sprites are bodies in the world • Collision detection • Movement Bubbles!
  27. 27. Demo 2 – what did we learn? • Using Farseer! • Worlds • Bodies • World and display coordinates
  28. 28. More features of Farseer Physics • Polygon shapes • Turning an image into a polygon in the game world • Complex objects • Combining many shapes into a single object • Joints • Attaching bodies to each other
  29. 29. Demo 3 – Exploring the cave • Stupid game with lots of physics • Polygon objects • Complex objects • Disabling gravity • Attaching objects
  30. 30. Polygon shapes Turn this... ... into this MAGIC!
  31. 31. Polygon shapes
  32. 32. Complex objects • Add many shapes to one body
  33. 33. Complex objects • Join bodies using joints • Revolute joints can be used to create a chain or rope • Use the RopeJoint to set the length of the rope • The possibilities are endless!
  34. 34. Finally • There is much more to MonoGame! • 3D – Richard Garside will talk about this tomorrow! • Pixel shaders and effects • Sound and music • Use the SoundEffect and Song classes • Input beyond the keyboard • Mouse • Touch • Joystick
  35. 35. Finally finally • Find my code samples on GitHub • github.com/runegri • And my slides on SlideShare • slideshare.net/runegri
  36. 36. Get in touch • I’m here for the rest of the conference • Twitter: @runegri • Email: rag@rag.no

×