In this module, we're going to start talking about how we use XNA to develop games. The module learning objective through this module are provided here. So first we're going to understand the different methods that are contained in the game1 class and that's what we're going to talk about today. And then we're going to over the course of the next couple lectures we'll learn how to draw sprites, load sprites, develop games using existing classes designed for use in XNA and so on. So in the previous module, we learned a lot of stuff about classes and objects. And I made the claim that object oriented analysis and design and implementation is very useful in the game domain. And we will see that here as we start dealing with XNA. As we're talking about XNA, you should understand though, that even though we'll talk about some XNAs specifics, there's lots of stuff that we're going to talk about that is about game development in general. It will be applicable to any game development framework you use, not just XNA. With that said, you should start off with an in lecture quiz. Okay, so ignoring XNA, there are a number of general things that we do in any game that we build. The first thing we do is we initialize the game. That could include setting score to zero. That could include sort of initializing some information that we're going to need throughout the game. But we do something to get the game into its starting or initial state. We also load content. So when we talk about content, we mean things like the graphical assets that you're going to use in a game. If you're using a 2D game, those graphical assets are typically called sprites. If you're building a 3D game you might have models and textures that you're importing, so and audio of course. So if you have music and sound effects in your games, those are also considered content. So usually, not always, but usually we think of content as the thing that comes from artists and designers, not programmers. Programmer-developed art is always interesting, but not necessarily what you want in your high quality game. So one other form of content is things like level specifications. If you have a level building tool and you have level designers building levels, you might load that content, you have to load that content, before you actually run your game. Now, content loading generally, we do some up front, early on and regularly we will find ourselves loading more content as we go through a game. So for example, we might load the initial level, and then once the player has completed that level, we're going to need to load the next level. We don't usually load all the levels all at once, because that takes too long, and players get bored as they wait for that to happen. So we load content throughout the game too. But, we're going to find that usually, there's some content we need to load upfront. So we do this initialization stuff and then we load content that we're going to need at least initially in our game. And then we enter what's typically called the game loop. And this game loop basically runs until the player quits the game. So the game loop is [COUGH] excuse me, the game loop is, update the game, change the game world. So that means moving a rubber chicken through the game world. If the rubber chicken happens to have velocity, it means having non-player characters do planning for how they're going to come get you. It means all kinds of stuff where we update the game world. And then we draw it because updating the game world without actually showing the player those updates to the game world leads to a fairly boring game, right? It's all invisible. So we update the game world then we draw it. You will sometimes hear that called rendering. And then we update the game world and then we draw it and we update and draw until the player quits the game, essentially. Now sometimes we move between playing the game and dealing with the menus and those kinds of things. But we're still updating and drawing, updating and drawing, updating and drawing as we go along. So those are standard ideas that happen no matter what game development framework you're using. However, let's fire up XNA and look at how XNA supports those things. So I open up the environment, and I select New Project over here on the left. And then I get a set of possibilities for the new project. None of these are mono game games. But if you look under the visual C# templates here, there is a Mono Game section. So I'll select that and I'll select Mono Game Windows project. I will rename the project IntroToXna and then I'm going to browse to a reasonable location to save it and click OK. And then we'll come back and look and see what template gets generated for us. You may find when it generates the new project for you that there's no code actually shown over here in the blue pane on the left. So, we could just click on game1.cs. And it will show us the game1 class that we actually want to look at. Okay. Before we actually look at these details, I would like you to go do an in-lecture quiz just to make sure that you internalized those ideas of the game loop. Okay, so let's talk about the first few things that get supported in XNA. I am going to zoom in, of course. And you saw this template before, though I didn't zoom in before because this is what XNA gives us when we say we want to do a Windows game. Right here is the constructor. We know about constructors. They're used to instantiate objects. So if there's stuff that we want to do when this game object gets created, then we do it here in the constructor. However, that's a trade off because we can also do those things right here in the initialize method. So we talked about initialization, setting the score to zero, those kinds of things. That's what you would put here in the initialize method because what happens is, the sequence of events for XNA games is the constructor gets called to create a game object. Then initialize gets called to initialize the game world. Then LoadContent gets called to load that content we were talking about, graphics, sound effects, those kinds of things. And then XNA enters the game loop. So these first three things Constructor, Initialize method and LoadContent support those pre game loop activities that we do in pretty much every game we build. So this is a good opportunity for you to go do another in lecture quiz to make sure you understand what LoadContent is all about. The next thing we'll do is we will go to the update method. We're going to skip the UnloadContent. For the games you do in this course, you'll never have to use that. For larger game, of course you would unload content so that you didn't have everything in memory as you went along for the 23 hour play session or anything like that, because that will slow people's computers or consoles down. So there are certainly periods in which we unload content in games. We're not going to need to ever do that in this course. So we move on to the update method and the update method gets called every frame in the game no matter what. So even if the game really starts to slow down, what will happen is the update method always gets called and the draw method which we'll look at soon, the draw method gets called as it's possible to call it. As long as it's not going too slow. Again, unless you do something really nuts in this class, you're never going to end up with a slow running game where you see frame drops and stuff like that. Okay, so here in the update method there's some prebuilt stuff. Notice it, well it may not be clear yet, because we haven't even talked about how we use the Xbox controller, but this basically lets you press the back button and leave the game if you choose to do so. And then we're going to add all our world updating logic here. And we don't need any of that right now but this method will get called every frame so we know whenever we need to update the game world, this is where we do it. So you should go do another in lecture quiz that asks you an XNA specific question about updating. And then finally, because we're inside the game loop now we update the game world and then we render or draw it. And so here's where we draw our game. So update gets called and then draw, and this by default clears the screen to a CornflowerBlue, that's why we get that CornflowerBlue when we run it here. Let me run it just to remind you. So we get a CornflowerBlue screen drawn, and then we'll add some drawing code here when it's time for us to actually draw stuff. So the draw method will draw all the visible entities in our game. So there's one more in lecture quiz that will ask about your understanding of pixels in general. We're going to focus, in fact I will say we are exclusively going to do 2D games in this class. Stepping to 3D is absolutely possible once you've built a good foundation of expertise. But is definitely not beginning programmers stuff. So we'll do 2D games here. And 2D games we regularly think about, therefore, 2 dimensional sprites that we're going to display and 2 dimensional sprites have four components as long as we're going to support transparency or opacity. Those four components are a red component, a green component, a blue component, that's the RGB stuff you've heard of before, and an alpha component. And so you should now go do the in lecture quiz to tell me if you understand what alpha means. Okay, I am not going to save that particular project. Don't worry we'll build one next time that we actually end up saving. In fact, I've already pre-built it. So to recap for today though the standard game stuff that almost all games do include initialization, loading content, updating the game world, and drawing the game world. And that update and draw is contained in what's called the game loop, and it happens until the player ends the game. We also took a look at how XNA supports those different activities within the template that is provided to us when we In Visual C# 2010 Express, say we want a new Windows game and so next time, we'll actually use XNA to build a, I hate to call it a game so I'll put it in quotes, to build our first game in XNA.