Cross-platform physics games
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Subtitle |
| |
Alternative Title |
| |
Title of Series | ||
Number of Parts | 170 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/50633 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
NDC Oslo 201466 / 170
2
3
5
6
8
11
12
16
21
22
23
27
31
35
37
42
43
45
47
48
49
50
52
54
56
57
58
61
65
66
67
71
74
77
80
81
83
84
85
87
88
89
90
91
94
95
96
97
98
100
102
107
108
112
114
115
116
118
120
121
122
123
126
127
128
130
133
135
137
138
139
140
141
142
143
144
145
147
148
149
150
153
155
156
157
158
159
160
161
162
163
166
169
170
00:00
Game theoryComputer programmingFloppy diskOpen sourceImplementationCloningSurfaceRoundness (object)Workstation <Musikinstrument>Metropolitan area networkComputing platformGame theoryReal numberFocus (optics)Graphics tabletLine (geometry)Different (Kate Ryan album)QuicksortInstallation artCodeCompilerInternet forumComputer programmingOpen setCompass (drafting)Group actionInstance (computer science)Multiplication signBitWindowWeightProjective planeGame controllerStaff (military)Position operatorMusical ensembleMathematical optimizationWebsiteJoystickNeuroinformatikPhysicalismProcess (computing)Information technology consultingGraphic designoutputDemo (music)MathematicsSound effectTouch typingType theoryImplementationOpen sourceVisualization (computer graphics)Complete metric spaceBinary codeVideo game consoleSlide ruleCross-platformSource codeSoftware frameworkVideo gameWeb browserAndroid (robot)Revision controlComputer animation
05:50
Content (media)outputComputer networkSoftware frameworkLoop (music)Game theoryStructural loadType theorySound effectComputer fontGroup actionBuildingFunction (mathematics)Directory serviceStapeldateiLimit (category theory)TouchscreenDemo (music)State of matter2 (number)SoftwareMultiplication signInstance (computer science)XNA FrameworkBuildingVideo gameContent (media)Texture mappingSocial classType theoryProjective planeComputing platformComputer fileGame theoryReal numberFluidTouchscreenException handlingStapeldateiMedical imagingDemo (music)MereologyConstraint (mathematics)Semiconductor memoryData managementProcess (computing)Flow separationCartesian coordinate systemCodeNeuroinformatikLoop (music)Structural loadFitness functionWeightSoftware frameworkWindowObject (grammar)Classical physicsFood energyLine (geometry)Discrete element methodMatching (graph theory)Disk read-and-write headSystem callBinary multiplierMultilaterationSound effectSet (mathematics)Group actionComputer animation
11:41
TouchscreenContent (media)outputDemo (music)EmailPhysical systemSoftware frameworkFluid staticsGame theoryCollisionOvalSocial classLogicTexture mappingProjective planeGame theory2 (number)Multiplication signSurfaceSocial classTouch typingKeyboard shortcutContent (media)Core dumpGastropod shellRegular graphAreaVisualization (computer graphics)WindowFrame problemSound effectData managementComputer clusterSystem callComputing platformComputer animation
13:36
Physical systemSoftware frameworkSpacetimeContent (media)OvalGame theoryMoment of inertiaoutputDynamic random-access memoryTexture mappingoutputLogicObject-oriented programmingGame theoryImplementation2 (number)AreaMultiplication signDemo (music)Computer animation
14:19
OvalTexture mappingSpacetimeSoftware frameworkVector spaceFrame problemContent (media)Structural loadEmailPosition operatorVector spaceDirection (geometry)PixelPosition operatorSocial classoutputTouchscreenSpacetimeCartesian coordinate systemWave packetEuler anglesMathematicsGame theoryComputer animation
16:04
Duality (mathematics)Medical imagingCodeMereologyMassSource code
16:49
OvalFrame problemRectangleSource codeTexture mappingImplementationEmailSoftware frameworkInterface (computing)Group actionInclusion mapDirection (geometry)Letterpress printingKeyboard shortcutRight angleWechselseitige InformationGlass floatPositional notationVector spaceMatrix (mathematics)Singuläres IntegralHeat transferPhysical systemFluid staticsGame theoryTouchscreenClique-widthPosition operatorIndependent set (graph theory)RotationCodeGame theoryTouchscreenPixelScaling (geometry)Instance (computer science)State of matterMultiplication signSource codeImplementationMereologyMedical imagingDirection (geometry)Data storage deviceSoftware frameworkFrame problemInterface (computing)Matrix (mathematics)Complex (psychology)Right angleFitness functionHydraulic jumpSpacetimePoint (geometry)InternetworkingCASE <Informatik>Moment (mathematics)Keyboard shortcut2 (number)Object (grammar)Square numberProcess (computing)Touch typingAreaTranslation (relic)Software bugRotationDifferent (Kate Ryan album)Goodness of fitWeightKey (cryptography)AlgorithmoutputComputer fileMobile WebInfinityClique-widthComputer animation
22:39
Heat transferTexture mappingOvalTouchscreenoutputDemo (music)Coma BerenicesLoop (music)Game theoryContent (media)StapeldateiGamma functionMaxima and minimaMusical ensembleGame theoryRotationZoom lensMetropolitan area networkRow (database)Projective planeContent (media)Computing platformTexture mappingCompilerService (economics)Execution unitDisk read-and-write headStapeldateiWindowComputer animation
24:13
Loop (music)Game theoryContent (media)StapeldateiTexture mappingoutputDemo (music)PhysicsCollision detectionPhysical systemDependent and independent variablesSimulationShape (magazine)Object (grammar)FrictionGravitationSource codeVacuumSocial classMetreCircleExecution unitShape (magazine)MetreOpen sourcePolygonTexture mappingMultiplication signSquare numberObject (grammar)Physical systemElectronic visual display2 (number)PixelTouchscreenSource codeProjective planeLibrary (computing)PhysicalismGame theoryMereologyFunctional (mathematics)Apache ForrestPatch (Unix)CodeCollisionCollision detectionProcess (computing)Group actionGravitationFrictionService (economics)Complex (psychology)Social classData conversionDependent and independent variablesComputer animation
27:39
Demo (music)Moment (mathematics)Content (media)outputComputer networkSoftware frameworkCollision detectionDrag (physics)Hydraulic jumpGame theoryMereologyCASE <Informatik>Demo (music)Object (grammar)SimulationSlide ruleCollision detectionProjective planeComputer animation
28:59
Electronic visual displayDemo (music)Physical systemArmAerodynamicsSoftware frameworkBand matrixFluid staticsOnline service providerCodeComputing platformGame theoryQuicksortComputer animation
29:43
Software frameworkWechselseitige InformationPhysical systemFluid staticsAerodynamicsQuicksortGame theoryPhysicalismSquare numberProcess (computing)1 (number)BitObject (grammar)TouchscreenSimulationComputer animation
30:42
Online service providerPhysical systemSoftware frameworkFluid staticsVector spaceStapeldateiGraph (mathematics)DivisorPixelGravitationAerodynamicsVector graphicsFrame problemSpacetimeTexture mappingRectangleString (computer science)Independent set (graph theory)GUI widgetSet (mathematics)Maß <Mathematik>Object (grammar)Virtual realityPosition operatorSound effectClique-widthPhysicsRotationGamma functionFactory (trading post)CollisionDifferent (Kate Ryan album)MereologyWhiteboardGame theoryProcess (computing)Connected spaceExecution unitObject (grammar)GravitationTouchscreenPosition operatorDynamical systemRectangleExploit (computer security)BitCASE <Informatik>Condition numberDoubling the cubeForcing (mathematics)WordPhysicalismSoftware testingSystem callForcePixelConstructor (object-oriented programming)Projective planeClique-widthCollision detectionSimulationRotationFluid staticsSolid geometryComputer animation
34:55
Group actionGame theorySquare numberPhysicalismSimulationComputer animation
35:36
Fluid staticsElectronic mailing listVector spacePixelGame theoryVotingPhysicsAerodynamicsOvalTwin primeElectronic visual displayDemo (music)Independent set (graph theory)CountingHeat transferPosition operatorRotationSimulationGame theoryMultiplication signPhysicalismParsingProduct (business)Forcing (mathematics)MultilaterationLoop (music)Cellular automatonComputer animation
37:04
Electronic visual displayDemo (music)PhysicsPolygonObject (grammar)Computer-generated imageryGame theoryGravitationInstance (computer science)Object (grammar)QuicksortPhysical systemAuthorizationPhysical lawComplex (psychology)Game theoryShape (magazine)PhysicalismChainPolygonCircleGravitationDemo (music)BuildingAreaComputer animation
38:18
Software frameworkSpacetimeClique-widthObject (grammar)PolygonCollision detectionGroup actionGame theoryCodeCollisionComputer animation
39:11
Software frameworkPhysical systemOvalHeat transferPolygonVector spaceScale (map)Texture mappingReading (process)Clique-widthComputer fontPoint (geometry)Factory (trading post)Game theoryMedical imagingPolygonZoom lensShape (magazine)Electronic mailing listPoint (geometry)TriangleObject (grammar)Computer fontConnectivity (graph theory)Forcing (mathematics)IntegerPort scannerCodeSingle-precision floating-point formatMultiplication signAuthorizationSimulationSinc functionPixelFactory (trading post)Computer animation
41:00
Data typePolygonShape (magazine)CircleEllipseObject (grammar)EvoluteChainAerodynamicsSoftware frameworkPhysical systemPhysicsClique-widthStapeldateiVacuumContent (media)Generic programmingOvalReading (process)Texture mappingComputer fontScale (map)Game theoryInfinityoutputGravitationFactory (trading post)Vector spaceInformationAugmented realityConvex hullExecution unitThomas KuhnMaizeFrictionInterior (topology)Ext functorSound effectPixelShader <Informatik>Keyboard shortcutSocial classTouch typingJoystickRectanglePosition operatorSpacetimeMusical ensembleElectronic visual displayCountingDirection (geometry)Computer musicGame theoryMultiplication signCircleRight anglePhysicalismTouch typingAdditionJoystickTouchscreenoutputKeyboard shortcutComputing platformTheoryPosition operatorCodeMusical ensembleSurfaceObject (grammar)PlanningImplementationTrailPoint (geometry)Connectivity (graph theory)Graphics tabletChainState of matterAreaType theoryTexture mappingMereologyBuildingCuboidNumberRectangleRotationGravitationSimulationForcing (mathematics)Sound effectLengthGroup actionFrictionLine (geometry)Graph coloringLink (knot theory)Demo (music)EllipseElectronic visual displayShader <Informatik>Collision detectionDampingPolygonMappingComputer animation
50:03
Direction (geometry)Touch typingInterface (computing)outputGraphics tabletMappingSoftware developerGame theoryKeyboard shortcutComputer animation
50:44
outputPixelTouch typingJoystickSound effectKeyboard shortcutSocial classSample (statistics)CodeSlide ruleTwitterEmailSlide ruleGame theoryoutputSampling (statistics)Touch typingComputer-assisted translationComputer animation
51:26
Exterior algebraComputer animation
Transcript: English(auto-generated)
00:00
to the people there. It's good to see. Hi everybody, welcome. And welcome to my talk about cross-platform physics games. I'm going to show you how to build primarily mobile games using monogame and faster physics. Today, I'm going to show you lots of code.
00:22
So if you don't like code, then you should go away. I'm going to give you a short introduction to a monogame, a bit deeper into fast air physics. I'm going to show you a few playable demos. There will be lots of code on GitHub later if you want to play with it, and I'll publish my slides.
00:41
Well, get back to that. This will not be a deep dive into the features. That would take days, a three-day course or something like that. I want to do 3D games. Richard, go outside over there. He's doing that tomorrow. So it's going to be brilliant. Rumors about Daleks, so that's going to be fun.
01:04
And this, I won't build a complete game. That also takes too much time, but I have a few completed demos. They are playable, and you can do what you want with them afterwards. Okay, who am I? My name is Rene. I'm from Trondheim here in Norway.
01:21
Work for Camp Gemini as a consultant. Most of the time, I do .NET. Primarily, I want to do mobile stuff, maybe because it's fun, interesting. And I've been programming since I was eight years old, so I've done it for a while. My first computer was a Tandy TRS80, as the other guys say.
01:41
I'm sure no one of you even heard of it. But why games programming? It's not my job. Usually, my day-to-day job is making boring websites like the other guys talking about. Angular and MVC and all that boring stuff. But yeah, it is.
02:01
So, but games programming is fun, and you can learn a lot, but you get a completely different focus on programming. So for me, it's fun and it's learning. And of course, I wouldn't mind becoming a billionaire and making the next Flappy Bird, not Angry Birds. But I don't think that's gonna happen.
02:23
Anyway, let's get started with MonoGame. Have any of you heard of MonoGame before? Ah, quite a few. Anyone making games, for real? Ooh, don't ask any questions. Yes. MonoGame is an open-source re-implementation
02:44
of the Microsoft framework called XNA, XNA version four. It's based on .NET and also on the Xamarin tool, so it runs everywhere, from desktop, Mac, Linux, Windows,
03:05
to mobiles, your Android phones, iPhones, iPads, Windows phones, if you use that. And it runs on game consoles. The PlayStation, both PlayStation 3, PlayStation 4, runs on the Wii, the Xbox 360,
03:24
probably the Xbox One in the future. Microsoft a bit slow there. And you can make, it's open source, but you can make real games with it, not just the stuff I'm gonna show you. I'm no graphics designer, so the graphics will be quite simple,
03:41
but you can make proper stuff. Like Fez, an incredible platformer, sold millions of copies. Bastion, it's an action role-playing game, also sold millions of copies, runs everywhere, even in the browser. Draw a Stickman, Epic. It's a really cool game. It runs on the iPad, at least.
04:03
And Transistor, it's the latest game from the same guys that made Bastion. It's also an action role-playing game. But you see, this is real stuff. It's not just something we're playing with. It's not just for fun. You can make real games, publish them,
04:21
and they're everywhere. My demos, by the way, I'm gonna run it on my surface because it would take too much time to bring an iPad and all that stuff. But the code, as it is, it will compile on all platforms and you can run it virtually unmodified
04:40
on your iPhone, for instance. You import the same code into a summary in iPhone project and it compiles. So it runs everywhere. Now, monogame, getting it. It's a nice place to start. If you're on Windows, then you can just download an installer from monogame.net, install it, and your Visual Studio will have
05:01
a few project types that you can create. If you want the source code, you can clone it on GitHub. And if you have an existing project, you can use a new get and just install the binaries. So it's quite easy to get. Monogame, it's a more or less complete implementation of XNA4.
05:21
It supports 2D graphics, 3D graphics, it's got what I call a content pipeline. It allows you to import graphics, sound, and compile and optimize it for the platform. On your iPhone, for instance, the graphics are compressed and optimized in a different way than they are
05:43
on a Windows desktop. So you have the content pipeline that handles that for you. You have input, touch, keyboard, mouse, joystick, anything. You have a nice enough support for sound effects, music, 3D positioning, all that kind of stuff.
06:00
And you have a networking stack to make games that run multiplayer games over the network. But still, it's a bare-bones framework. You won't get built-in support for UI, for instance. So either you have to build your own, or you can find it on GitHub and on the net.
06:23
There are lots of people working with this. Okay, enough background. I have to introduce you to a few concepts about how a computer game works before we start looking at the code. And the main thing to know of, in my head,
06:41
is the game loop. When you're looking at the movie, you will see, you know that it's not really fluid movement. It's a bunch of still pictures. And we replace them 20, 30, 50, 60 times per second. But it's a bunch of still pictures.
07:00
And it's the same in a computer game. In Monogame, you have what they call the game loop. It really is two methods. It's the update method that lets you update the state of your game. You run the AI, you calculate where everything is supposed to be. You do anything except drawing, really.
07:21
And in the drawing method, you paint everything to the screen. And this is repeated, normally about 60 times per second. So it must be fast. And it gives the impression of a fluid movement because it's so fast. So you do tiny steps all the time,
07:41
and it looks like it moves for real. The game loop also has the initialize and load content methods. It's where you set up your game. You load all the resources you need, create your classes and all that stuff. And if you need, you can unload content when your game quits.
08:01
Content in Monogame, it's graphics, it's sounds, it's effects, 3D objects, you're doing that. And you can import most types of resources. In my examples, I'm gonna import PNG files for graphics, and that's it.
08:22
Whatever you need, it's usually supported. To create content, you either use a content project. On Windows, you need the XNA framework. And then you create a Monogame content project, it's called. And then you can select the platform you're building for, Linux, iOS, whatever.
08:41
And your resources are optimized for that platform. I think I'll have time to show you that later. You can also use a Monogame content builder. It's a command line application that runs on all platforms. It's not quite done yet. They're working hard on it. And it lets you, as part of your build step, if you have a build server, for instance,
09:00
you can build all the resources there. So it depends on what you prefer. Also, you can load a PNG file, for instance, as your graphics, without the processing using the content builder. Due to performance reasons, you want to optimize them.
09:21
Loading content, there is a class called the content manager that lets you load anything. So for instance, I want to load a texture, 2D texture, in 2D games, that's really the graphics you're loading. So content.load, texture 2D, and I want a resource named spaceship. So in my project, then I will have a folder called content,
09:45
and in there I will have the spaceship.xmb. It's a compiled content file. You can load sprite fonts, sound effects, songs, all kind of stuff in the same way. Drawing stuff, that's important as well.
10:01
We use, it's a sprite batch class. It's a batch because you give it several draw commands and they are batched together due to performance. So you begin a batch, you issue all the draw commands, draw your little spaceship hair and your enemies there, and then when you say end, and it's drawn to the screen.
10:23
So you try to limit how many sprite batches you start because if you do many of them, it will hurt performance. As you hear, I'm really concerned about performance, and while the demos I'm gonna show are terribly simple, even Stone Age Computer will run them,
10:44
but once things get complicated, you need to think about performance. A part of why it's kind of fun doing games, and you do most of the stuff I do at work at least, I don't really have to care too much about performance or memory constraints and all that because computers are fast enough,
11:02
but when doing games, you actually have to think about that. I think that's fun. But okay, let's get to a demo. Have any of you seen those guys before? Yay, bubble, bubble. I'm guessing many of you weren't born when this game was popular.
11:20
I'm gonna show you just some very basic stuff. I'm gonna draw a sprite that's really just a tiny image on the screen. I'm gonna show how to load content, how to do animation, and a very quick introduction to how to use a camera to zoom in and make stuff fit on screen, and I'm gonna mention how to do input. Okay, now I hope the technology works
11:42
and I find my project. Can you see this? No, now, hopefully. Yes. Okay, we're in Visual Studio. We're running Windows 8, Surface, blah, blah, blah,
12:00
and all that stuff. And this is a regular MonoGame content project. Yeah, it's large enough. Is the text large enough, by the way? Readable? Yeah. And the core of MonoGame is really the game class.
12:20
It defines the game that you're gonna run. And this will be reused on all platforms. You see, I have a graphics device manager, the sprite batch, you know that. But really, I usually don't touch the game class much.
12:40
I don't want to pollute it. This is the main shell of the game. So usually what I do, I have my game loop. You see, I have the update method and the draw method, and I delegate everything to my, I call it a game area. You call it whatever you want. So I tell my game area, my game itself, to update itself.
13:02
Game time tells how much time has passed since the game was started, and also how much time has passed since the last frame, the last time the method was called. So I tell my game, update yourself, and then I tell the game to draw itself, dead simple. And that's really all there is.
13:21
Update and draw, update and draw, 60 times per second. Now, if we, I'm not used to this Surface keyboard. I'm just gonna use the mouse. Oops. The game area is, now we're getting
13:43
into my implementation of the game. It's really my game logic. I still have the draw method. I still have the update. And you see, I delegate further down. I have a dragon. I'm gonna show you in 10 seconds. I tell it to update itself. I have the game input that handles my input.
14:03
This is stuff I make, my own abstractions. And then I have my draw methods. But let's start it first, so you can see what this is all about. If it starts, yes. I started my demos a few minutes ago when everything started, so I really hope the demo goes Garza with me.
14:21
And here you see, a little guy. He can even open his mouth. Yeah. Now, that wasn't very impressive, was it? Yeah, it was. Yeah. Okay, we're done. You're an easy crowd. Now, really, we have to start with the basics.
14:43
Drawing on the screen, making things move. The dragon is really the one doing all the work here. He is a very simple class. He is something called a drawable. That's my own class. It's something that can be drawn on screen.
15:03
He has a reference to my game input. He knows where it's placed, which direction he's looking, and so on and so on. This really isn't, there isn't really too much to it. You see, I'm checking the direction I'm moving. If I'm moving to the left, then I change my position.
15:22
And you see, I have a vector that I update. A vector is a position either in 2D space or 3D space. A vector 2 is a position on the screen. You have the x-axis, the horizontal position, and the y-axis, that's the vertical position. So I'm telling really where it's supposed to be.
15:40
So if I'm moving to the left, as you see here, then my position should be two pixels to the left on the x-axis, sorry. And moving to the right, I add the two to my position. So it's really that simple. When I'm doing animation, that's more interesting.
16:04
I'll show you my graphics. You see, here's the dragon. And really, this is four pictures in one. This is called Texture Atlas. It allows me, instead of having, and again, you may have thousands of thousands of graphics. And instead of having, loading all those thousands of files,
16:23
you stuff it together into big resources. Because it's easier to load, and in the end, it's easier to manage. So I need code that tells which part of that image do I want to draw. You see the first image on the left, that's when it's standing still.
16:41
Then the next two pictures, that's when it's working, and the final picture is when it's mouth is open. It's gonna blow a bubble afterwards. So I'm looking through, I'm updating the frame I want to display. This is, normally you would use a framework to do this,
17:03
but just so you see the basics, I do it myself. So you see, either the frame stands still, I'm not moving in that direction, and then I switch between the two move frames. And finally, if I'm trying to blow a bubble,
17:21
then I switch to that frame. And then based on which frame I want to display, you see, I change the source, which part of the image I'm drawing. Do you guys understand this? Yeah, good, good. So which part, I split the image into four parts,
17:43
32 times 32 pixels, and I select which part to draw. And this allows me to store the animation in one simple file. Now, input. To handle input, I define my own interface,
18:02
now I'm back to the .NET world, that tells my game, what does the player want to do? I have a direction I want to move, none, left, right. I have a Boolean says, am I jumping? Do I want to jump? Yes, no. Do I want to blow a bubble? Yes, no. And then I have my implementation of that.
18:24
So in this example, I have a keyboard game input. So you see, I do the keyboard, get state, so I'll use the keyboard. Okay, which keys are being pressed? If the player press A, then I want to move left. If you press D, then I want to move right,
18:42
blah, blah, blah, so on, so on. Press W to jump, space to blow a bubble. So it's really simple. Oh, question, yeah. Yeah, I know, I know. If you press both the left and right, then it depends on the code here.
19:02
There are better ways to code this, but there's much more code. It depends on what you need. And also, if you want to do touch input, for instance, you touch the screen, or mobile games, that's what you want. Then you also want to handle it. I think I'll have time to show you how to use touch input afterwards,
19:21
but I have to use the mouse. It's kind of awkward, but my algorithm here is stupid. That's not the point of it, really. But you see, you ask the keyboard, give me your state, which keys are pressed? And then you know, you can press as many keys as you want, it will handle it.
19:43
No, no, no, no, no, no infinite jumps. But this is just telling which keys am I pressing? I'm wrapping it, so instead of using the key abstraction, it won't fit if I do touch input, for instance. So I wrap it in my interface,
20:00
I can say the player wants their dragon to jump. Not that it is jumping. So even if I press the jump button, the dragon won't necessarily jump all the time unless I code it to do so. I'll show you a better example afterwards. And the final thing I want to show you is the camera. You see, I hit it.
20:22
Do you guys know matrices? Not the movie version? Yeah. It's complex and confusing, but they're kind of a magic way to let you, you have matrices that do different things. Translation, that's moving, that's movement.
20:42
I have the rotation, I have scaling, zooming in and out. So this allows me to actually fit the stuff on screen. If you see, go back to my game area, yeah. And go to top, you'll see that I define a game area
21:02
that's really small, 600 times 600 pixels. I'm on pixel graphics here. And then I use my camera to scale the graphics up so it will fit on screen. So you see here, I set up my camera to be zooming on the middle of the world.
21:20
And then I tell it to zoom. And I even have a bug. I tell it to zoom the width to the height of the screen, but it doesn't matter, the game is a square, but still, it's a bug. Okay. So you see, I have a setup, so I add my objects,
21:41
but that's not really, how we implement this stuff depends on what you want to do. The important stuff is how to use MonoGame, how to use farce afterwards. I just want to do one thing. If I find my update method, just show how the camera works. I can tell the camera, camera dot rotation.
22:10
Oh, no, no, I want to rotate faster. Now, you see, I don't care about the game time. Normally you would say, okay, how many milliseconds has passed since last frame?
22:23
And I define a speed, and I scale it based on how many milliseconds. So I say, in 10 seconds, you want the game to rotate, and then you divide, so you get smooth movement. That's too much work now. I just want to show you how the camera works. When I start now, the game is gonna rotate.
22:43
Ooh, yay. Did you see? I'm still moving to left and right, so I just really, I'm moving my camera, not the game world, I'm not doing anything. It's just a camera that rotates. I can do the same to zoom in, zoom out.
23:01
I'm not gonna do that now. Okay, let's go back. I think I covered everything now. So you've seen the game loop. It's really two methods, update and raw. You see how to load content? Oh, wait, I can show you the content project. You see, I have a BubbleBubble.content project up here.
23:23
It really has nothing, but it refers to my BubbleBubble.content content project. Forgive my naming. And it has a reference to a couple of PNG files. It's the dragon and the wall graphics.
23:41
Can you see? And you see down here, I'm telling MonoGame that this is a texture for the XNA framework, and it's supposed to be handled by a MonoGame texture. Normally, if you use the old XNA framework, it will say an XNA texture. But using the MonoGame texture, then I can tell the compiler to compile for Windows,
24:02
iOS, Linux, OS X, and so on and so on. So this way, I can use the same project and build the content for all platforms I need to support. So that's really Content. Okay, so Content, you saw the sprite patch. Try to, you need to use it, but don't use it too much.
24:21
Texture atlases, you saw how a simple camera, you saw how to do input. All that from this little guy. That's nice, huh? Okay, but there's more, and let's go move on to Forrester physics. That's when it gets interesting. Forrester physics, it's a collision detection system with realistic physics responses.
24:42
Why? It's really just a physics simulation. It's flat, it's 2D, not 3D. It allows you to do collision detections, and you can have objects of any shape. You can have a circle that hits a square, and you can have polygon shapes that can be any shape.
25:02
You have friction, you have restitution, how bouncy things are. You have joints, you can stick things together. Gravity, so we can simulate an entire world. And much more. So you can download Forrester from UGet. The source code is on forresterphysics.codeplex.com.
25:22
Not in GitHub. It's probably the only project I know that's not in GitHub anymore. And you can build from sources. Usually, when I use Forrester physics with MonoGame, I download the source and include it in my project, because in my head, that's the,
25:40
in my experience, it's the easiest way to get it to work. And also, I can remove anything I don't need. Forrester physics, it's a big library. It has lots of functions that I never used. So by including the sources in my project, I can pick the parts I want.
26:01
There's one thing to be aware of, and this is common pitfall. Forrester physics uses the kilo meters and seconds units. Usually, when we're making games, we're thinking about pixels. So say I want to use Forrester physics. I want a square on the screen in my world.
26:21
It's 100 times 100 pixels. So I tell Forrester, hey, make a square, 100 times 100 pixels wide, and it's supposed to weigh 10 kilos. And the square is not really, it will hardly move, because Forrester physics will say 100 times 100,
26:43
that's 10,000 square meters at 10 kilos. So it will be virtually weightless. So we have to convert between pixels and meters. You see the screen here, 1920 times 1080 pixels, and maybe want Forrester to see that
27:01
as 19 times 10 meters. So we use the convert units class. It's included in Forrester. We initialize it with set display units to sim unit ratio. So I can tell it that 100 pixels is one meter. You do this once, and then you can use a couple of convenience methods
27:25
to display units to sim units. That allows us to easily convert between the two. That's really, you must remember this so your games won't work. Oh, sorry. Oh, it's supposed to be maximized.
27:44
Okay, why did it do that? I'll just jump through it. Why did it do that?
28:03
Pause some slides to go through. Okay, so we'll do another demo. The more bubble bubble, this time with bubbles. It's still just, it's a very simple platformer, but it will illustrate a couple of important topics.
28:23
First of all, I'm gonna simulate a world, a game world. In Forrester, you have the concept of a world where the entire simulation runs. I'm gonna have my sprites, my dragon, the enemies, the bubbles, and the walls. They're gonna be objects in the world.
28:41
So they're gonna be bodies. That's the Forrester name of it. I'm gonna do collision detection. I'll show you how to do some interesting stuff with that. We'll do movement, many bubbles. That's the fun part. Okay, let's see if I can find my project. Bubble bubble two.
29:02
If we, I'll just add the enemies so you can see how it looks. And then I can go through the code afterwards. And, ah, sorry, I need to duplicate it.
29:22
I'll restart. Now it's on screen, yeah. So I still have the dragon. And now we can jump. And we have enemies and bubbles. The bubbles, we kill the enemies very easily now, but ooh.
29:42
So it's more, it's a platformer now. It's actually some sort of game. I want to show you one more thing. I'm gonna remove the enemies so they won't get in my way, so they won't kill me. And I'll just show you how the physics really work.
30:00
Now I'm gonna blow some bubbles. The black ones are heavy, ooh. And I have a, can you see that? Do you see that my dragon has a square around it? That's really my, the physics object in the game. And you see the walls have squares around them. That's also the bodies. And you will see the,
30:21
it's maybe, it's a bit hard to see, but the bubbles have a circle around it, around them. So you see, I have my simulation, but I'm not really drawing it on screen. Let's see if I can make the bubbles burst. It's fun.
30:41
Takes too much time, sorry. So I'm back in my previous project. It's the same, but I've included Farseer. And when I include Farseer, I also need to connect it to my objects.
31:00
So I start by creating a world. It's really as simple as running the constructor. So you see, I say, I want a new world. I want the gravity to be downwards. The strength is 20. It's really arbitrary what you choose. It depends on what you want to do. It fit my game now. So this is where I create the game world,
31:22
where I do the Farseer physics simulation. And I go to my drawable objects. Let's go to the dragon. Now it's called the game object, but it's really the same. You see, the game object has a reference to its world.
31:42
So it has the connection to my Farseer simulation. And you see, it knows of its body. And finally, you see the position. You see, I'm telling it to use the convert units. So I asked the body for its position,
32:02
and then I convert it back to display units. So when I read out the position, I get it in pixels, and not the Farseer physics simulated units. Okay, and my dragon is really
32:21
more or less the same as before. You see, I create a body. That's really the only difference that's important to know. So you see, I give it a width and a height. And these are the finite pixels again, 32 pixels. I tell it to be a dynamic body. That means that it's gonna move. You can have a static, usually you have static bodies
32:41
and dynamic bodies. Static bodies, they're like walls. You can't do anything with them except run into them. While the dynamic bodies will be affected by gravity, other forces, they can move, rotate, and all that. I tell my dragon to have fixed rotation, because otherwise it looks stupid. I'll show you.
33:01
And I have a collision detection. So you see, when I handle collision, I want to see if I hit the wall. So I'm checking, also I'm checking if I'm jumping upwards, not downwards, and I hit the wall. Then I check if it is a solid wall. I'm telling some of my walls to be
33:22
so I can jump through them when I go up. But when I'm landing on them, I can't go through them anymore. It's part of my game dynamics. So the collision detection, if it returns true, like this, there is a collision. Then the object will hit and something will happen.
33:42
If I return false, in this case, if it's not a solid wall, then there won't be a collision. So far, I would keep asking, is this a solid wall? Yes, yes, yes, yes, while I jump through the wall. But as long as I return false, the collision won't be registered, so I can move on.
34:02
I also have my enemies. You see, they inherit from the same game objects. Really much of the same. They have a rectangle body, blah, blah, blah, all that. And you see, if I hit the dragon, then the player died.
34:21
Quite simple logic, yeah? But I'm gonna show you a bit more of the physics. Now I'm gonna not remove the fixed rotation. So now my little dragon, when it goes to the edge of the ledges, then he will fall off.
34:43
I don't want my game to behave that way, but it's a fun demonstration that the physics work. Just gonna say, no enemies, okay. Let's start the game again. And it's on the screen, yeah. So you see, now I can jump through the walls,
35:02
but I can land on it. This is a solid wall, so I can't, but oops, I fell off. I still move. Do you see the little square around it? See now, when I go to the edge. So you see, we have collision detection. We're actually simulating physics there.
35:22
It's maybe hard to see when I don't do the debug. But we're actually doing physics. So oops, nah. So we don't want the game to behave that way. That's why I'm telling it to have fixed rotation, but the simulation is there.
35:42
Back to the fixed rotation. Okay, let's see. That's more or less what I wanted to show you there. There's a lot of fun stuff we can do here. I have, I'm not sure if you saw, some of the bubbles that blow, they're blinking. And when they pop, they explode. Blah.
36:01
So the enemies and bubbles go all over the place. I'll see if I have time at the end to show you. Don't think, it's taking too much time. But okay, so very quick introduction, how to use parser physics. You create the world, you add bodies.
36:20
No, sorry, I forgot one thing. We need to update our game. And my game world, and I find the update method. Just so I have shown you. You see my update? I tell my parser world to do a step, a time step. Again, we're not doing continuous simulation now.
36:43
It's tiny time steps. This will be in 60 frames per second. This will be 16 or 17 milliseconds. And it will update the game just a little, and a little, and a little, and a little. And again, again, again, again, again. So the game loop, it's important
37:02
when you're using parser physics as well. Okay, so we create the worlds, we have created bodies, and you all know how to convert between the coordinate systems. If you forget that, the game won't work. So remember to convert. But parser physics can do much more.
37:21
I'm gonna show you how to use polygon shapes. You can make a body, an object, any shape at all. You can also have complex objects where, for instance, in my final demo, I will have a UFO that's built up of a circle and an ellipsis. And you can use joints so you can attach bodies
37:40
to each other, build ropes, for instance. Lots of cool stuff. So we're gonna explore a cave. It's a really stupid game. You have a UFO with a chain hanging underneath it. At the bottom, you have a magnetic ball that will pick up crates, and you're gonna drop them at the yellow area. If you hit the balls, then your UFO will die.
38:03
So yeah, but there's lots of physics here. So for instance, my UFO, it's a UFO, so it doesn't care about gravity. I'll show how to attach objects to each other, and we're gonna build some complex objects. But first, let's start the demo so you can see.
38:21
Now it's gonna be zoomed out a lot, so I have to zoom in, but. Do that fast. Here, you can see the game world. And you see the UFO? I can control it. It goes downwards because the ball is so heavy. If I didn't do that, then it will just fly.
38:40
Now I hit the wall, bang. So I'll fall down. And you see the collision detection at the ground. It really follows the edges. Now if I turn on the debug, you see all the polygons? I have some code. I'll show you that. Really scans the entire world,
39:01
and turns it into a big object. So I have collision detection, but it's really detailed. Can't lie there. Go back to it. So first, polygon shapes. You're using magic to turn an image
39:21
into an object that you can collide with. It's really fantastic. Or you can use code. That's what we do. It's not really magic. What I do, I read a texture. It's really just one of the graphics in my game. I have a big picture, 2,000 times, 2,000 pixels.
39:43
It's the easiest way to do it. So I read it into an array of integers. And then I use the polygon tools to create a polygon. A polygon, it's really just a list of points that explains the entire outline of the object I'm scanning. I'm scaling it, just because I want the world
40:02
to be a bit bigger. And then I simplify it, because I don't want all the points. You don't need it in the simulation. So I simplify it. So I get rid of most of the points, but enough to keep the shape. And then I turn it into polygons. It's really a list of triangles that describe the object.
40:21
And finally, I create a force and a body. So I create a component polygon. So it's really just a list of triangles. If any of you have done 3D games, 3D graphics, then you're aware of how to use triangles. And this, you see, I use the body factory,
40:42
but I don't tell it to make a dynamic body. So this is gonna be static. You can't do anything with it, except to crash into it. Nothing will move it. So it really simplifies the simulation. Also, I want to go back to my game and zoom in on the UFO, so you can see how it's built up.
41:04
It takes a while to start a game because it's scanning and building the game world each time. Now, if we zoom in, move away from the wall and turn on the debug, can you see that? Do you see that? My UFO has a circle and an ellipsis, right?
41:22
Oops, I crashed. So the body of the UFO, it's not just a box, all right? Or a circle anymore. It's more complex than that. So when I'm building it, I add an ellipsis with a given size, a number of points around it,
41:41
and I add it to the body. And then I create a circle. So, and you can combine as many parts as you need to build objects. Finally, if you saw the chain hanging under it, that's lots of tiny bodies, tiny rectangles. And I use what is called joints to connect them.
42:02
A revolute joint will let objects, they stick together, but I can rotate around the point the joint is added. So I connect many small parts using revolute joints, and finally I use what is called a rope joint that sets how long can two objects be from each other.
42:25
So it allows me to create a rope that won't stretch forever. So there are many types of joints you can have. Weld joints, I use that to connect the crates to the ball in my game. You have motor joints, so you can simulate a car
42:42
if you want, and you can make your own joints. Depends on what you do. The possibilities are really endless. I think I have, yeah, a few more minutes. I have time to look into the code. And let's see, the screen is actually kind of small.
43:04
It's a nice computer, but let's see. The cable, you've seen the code for that. And so I scan the texture and make it into a polygon. And you see, I just draw it because it's, in my game, it is just a big texture. It's one graphic, that is the background.
43:23
So that is really simple. And where is my UFO? Here it is. It's the most interesting piece of code here. You see, I load some more textures for the chain links and the ball at the end.
43:43
And then I create the body of the UFO. So I add a circle, add the ellipses to the body. And then I build the chain, the ball and chain. So you see, first I define a path. It's just a line that I want the rope to follow initially.
44:03
And I distribute them evenly. So I add a bunch of bodies along the path. You see, I add 30 of them. And then I attach them to each other using the joints.
44:22
And then I connect it to the UFO body. And finally, I create the ball. And I connect the ball to the chain using another joint. And finally, I create a rope joint that sets the length of the rope. So if I don't do that, then the rope can stretch forever.
44:41
So it would be a strange, poor simulation of a rope really. So now I have a chain, I have a ball, I have a UFO. When the UFO hits the cave, I want it to, normally the UFO will ignore gravity.
45:01
It can fly, it can do anything. So, but when it hits the wall, I tell it not to ignore gravity anymore. So it's gonna fall down. I also use something called angular damping. If you do that, it will stop the rotation. It will slow down the rotation quickly. And I set it to zero.
45:20
It will keep rotating very quickly. Also, I set the mast. I tell it to be 100 kilos. It's gonna be heavy and fall down. So that's my way to telling the player that, hey, you lost, you crashed. And also the ball that picks up the crates. You see, I use a weld joint. It really just attaches two objects to each other.
45:40
They can't move at all. They just stick to each other. So I add it, and I tell the crate that it has a joint. So it knows, so I can't attach it more times. It's really just simple code. And that's more or less all there is to it. I'm applying forces, as you see, to move the UFO. So I'm telling, apply a force to the left,
46:02
and then the UFO is gonna start drifting to the left. Apply a force to the right, and it's gonna move to the right, and so on and so on. Also the crate is really the final thing I wanted to show you guys.
46:21
The crate is just a rectangle. And you see, I set the restitution to more or less zero. If this is a high value, then it's gonna bounce like a bouncy ball. You don't want the box to do that. I'm also giving it some friction. So if the box hits a slope, it won't just fall down.
46:41
It may stick on it, because there's friction between the surface. And that's really it. It's a very simple game, but it works. Okay, so you can do more or less anything you want.
47:03
You want to, all kinds of physics. So in the platforming game, I really more or less abuse it to just do, I do collision detection. I move the dragon, but I don't really do much of physics simulation. So you can use Farseer to do platforming games.
47:24
And in the UFO in the cave example, I do lots of physics. It's really a physics-based game. So the type of games like Angry Birds and what I call it, Angry Pigs, the one where you build the cars and planes. Those are typical examples of games you can build with Farseer.
47:41
They're really quite simple. Now there's much more to Monogame, and the day isn't long enough. 3D, Richard is gonna talk about that tomorrow. I'm gonna be there. I haven't touched pictures of shaders and effects. Monogame lets you, at least in theory, write a shader once,
48:00
and you can recompile it for other platforms. So it's quite useful. You have the support for sound effects, music. You can position sound effects in a 3D room if you want that. And you have input. In addition to the keyboard,
48:20
you have mouse, touch, and joystick. And you can combine them. You can ask for all of them if you want to. It's more or less the same as the keyboard. Let's see if I can show you a final demo with the keyboard. I think I have it. No, the touch. Touch, touch, touch, touch.
48:41
There it is. This is really another implementation of using the game input. So now I'm mapping touches on the screen to the same inputs as the keyboard inputs was in the other example. So you see, when I update it,
49:03
I'm checking, asking for the state of the touch panel. So I'm asking, what is the user touching now? So I go through the states, and I try to see if I'm hitting the areas. I compile the game with touch,
49:22
so you can see how it looks. It's easier than me doubling down about it. If I tell it to use, oops, use. Touch with a C, I think that's it.
49:46
Yeah, let's try. If I got it right, then it should start the game and display some touch inputs. It's really a circle on the sides of the game that you can touch and move like a onscreen joystick.
50:01
Did it start now? Try again. But I have to use the mouse now because touch inputs are disabled. So you see, I can move, jump. It's kind of difficult to control with the touch pad. But you see, it's really the same,
50:21
and it maps to the same things. Also, I can blow bubbles. Hey, touch works. And I can turn on the debug if I want that. So it's really, it maps to the same interface. So I can do the same thing very easily. So I just set up my game to use touch input instead of keyboard input, and it works.
50:49
I go back to the start, I think. Yay for... Okay, so input and touch and all that.
51:01
Finally, later today, I'll upload my samples to GitHub, and you're free to do whatever you want with them. I'll upload my slides to SlideShare if anyone would want to look at them again. And I'm here for the rest of the conference. So if anyone would want to talk about games programming and anything else, then you're free to come and make a chat.
51:24
Okay, thank you very much for listening.