Introduction to Game Development Using C# and Monogame Part 1 ... The Basics | Charlie Chiarelli | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Introduction to Game Development Using C# and Monogame Part 1 ... The Basics

teacher avatar Charlie Chiarelli, Experienced Online Educator

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

11 Lessons (1h 20m)
    • 1. Welcome

    • 2. Why MonoGame? ... Some Background

    • 3. What You Need

    • 4. Creating Your First Monogame Project

    • 5. Managing Content

    • 6. Displaying The Content... The Sprites

    • 7. Moving The Sprites

    • 8. The Velocity Vector

    • 9. Hitting The Wall !

    • 10. Drawing Text

    • 11. Adding Background Music and Sound Effects

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


Video games are on our computers, our consoles and our phones! Lots of people play them and every year more people are making them. If you have ever played a computer game and thought, “I wonder how they do that?” or, better yet, “I want to make something like that,” then this course will get you started. Game development is what got many developers into programming. But how many of us actually ever learned how to create games? Creating games can be challenging, but it doesn’t have to be that way! MonoGame is a cross platform gaming framework based on Microsoft’s XNA framework that’s extremely easy to learn. Best of all, games you build with MonoGame will run on iOS, Android, Mac OS X, tvOS, Windows, Linux, PlayStation 4, and more—write once, play anywhere.

There’s no shortage of options when it comes to game development environments. From full-featured engines like Unity to comprehensive and complex multimedia APIs like DirectX, it can be hard to know where to start. MonoGame is a set of tools, with a level of complexity falling somewhere between a game engine and a grittier API like DirectX. It provides an easy-to-use content pipeline, and all the functionality required to create lightweight games that run on a wide variety of platforms. Best of all, MonoGame apps are written in pure C#, and you can distribute them quickly via the Microsoft Store or other similar distribution platforms.

This course assumes that you’ve done a little bit of  programming in C# but  all the material starts at the most basic level. That means that anyone should be able to join in and work their way through the material.

In Part 1 we cover

  • Learn to use the MonoGame Windows Project Template
  • Run your first MonoGame program
  • Understanding the underlying Template code
    • Directives (using)
    • Game1 Class
    • Instance Variables (SpriteBatch)
    • The Constructor ... Game1()
    • The Initialize Method
    • The LoadContent Method
    • The Update Method
    • The Draw Method
  • Set up the Pipeline Tool 
  • Learn to add assets to our project using the Pipeline Tool
    • images ... bmp, jpg, png (best)
    • audio ... wav , mp3
  • Organize content into folders 
  • Create a place to store the images (instance variable of type Texture2D)
  • Load the images into the instance variables
  • Draw the images using SpriteBatch (object used to do drawing)
    • using the Draw command
  • Introduce the concept motion in Monogame
  • Learn how to use the Vector2 class to create objects which indicate the sprite location of our images
  • Use the Update method to change our Sprite Location
  • Use the Draw Method to redisplay our sprite at its new location
  • Introduce the concept of velocity
    • we add a velocity instance variable from the Vector2 class which will be used to move our image , instead of using a constant
  • Introduce/Review some basic Vector addition concepts from mathematics
  • Discuss the screen constraints
    • where exactly (X location ) is the right and left walls
    • where exactly (Y location ) is the top and bottom walls
  • Create a program which has the image bounce off any part of the walls it encounters
  • Learn how to create a Sprite Font using the Pipeline Tool
    • Edit the Font (XML)
  • Use the Sprite Font to display a count of the number of wall collisions
    • Using the DrawString command
  • How to add sounds to your Mono Game Project
  • First we add directives 
    • using Microsoft.Xna.Framework.Media
    • using Microsoft.Xna.Framework.Audio
  • Next add instance variables of the Song and SoundEffect classes
  • Next we load the sounds
  • Lastly we Play the sounds at the desired location in the program 
    • Background music (songs) can be started  right at the beginning
      • mp3s work best with songs ...
        • but can use wavs ... need to force pipeline tool to change processor type from wav to song
      • can't play two songs at same time one will cancel out the other
    • SoundEffects are activated at a specified point in your game like hitting an object 
      • wavs are used for Sound Effects
      • multiple sound effects can play at the same time... can play over the background music 

Meet Your Teacher

Teacher Profile Image

Charlie Chiarelli

Experienced Online Educator


Hi, my name is Charlie Chiarelli. I'll be your teacher for this course. I will spend as much time as necessary to help you do the best you can. But, for you to succeed you must be willing to work .

I am a retired High school Computer Science and Mathematics Teacher from Canada. I taught for 35 years, I have a BMath degree from the University of Waterloo.

I was a frequent speaker at educational conferences (ECOO) and seminars . Most recently my talks focused on E-Learning and the future of education (Flipping the Classroom).

I was the school webmaster and served on a number of school board committee , recently advising my school board (Hamilton Wentworth Catholic District School Board) on its online learning direction. I was also the contest coordinator for the Annua... See full profile

Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Welcome: welcome to a gentle introduction to game development using C sharp and model game. Hello, my name is Charlie shrilly. I'm a retired high school mathematics and computer science teacher I taught for over 35 years I've been teaching online for the last 10 years. The aim of this course is to have you create two D games in a non intimidating, fully coated experience way. This course assumes that you've done a little bit of programming in C Sharp, but all the material starts at the most basic level. That means that anyone should be able to join us and work their way through the material. And that's the good news. The bad news is, is that programming is hard work, especially at first. If you truly want to learn how to program, you're going to need to write programs yourself and struggle through some rough spots. Before some topics really click for you. Let me give you an analogy. I could watch a person ride a bike. I could read a boat how to ride a bike. I could watch a video, but, um, bike ride. But if you don't get on the bike yourself and fall down a couple of times and actually learn how to ride the bike yourself. You're never going to be good at riding a bike. Same thing with computer program. But having said all that, don't feel you're alone. I will be available daily for extra help should you need it. So let's begin, shall we? On to the next lecture. 2. Why MonoGame? ... Some Background: welcome back, and in this lecture, we're going to highlight the historical developments of model game and why you should want to learn it. Now If you'll indulge me for a few minutes, I'm gonna give me a bit of a history lesson. But that being said, I won't feel offended if you decide to skip this lecture and go on to the next one anyway. Here we go. So as you probably know, Microsoft C. Sharp and died out of my favorite development tools. My two previous courses on you to meet Focus on C Sharp now see sharp dot net there great for creating Windows desktop and Web applications. However, one area that C Sharp fell short was in game development, using the DOT net A P I is not pockets not possible to get the high performance required for gaming. A direct X is the way to go. It's used virtually by all professional games on Windows, but it requires the use of C plus plus Direct X allows low level access to the video card, which makes it the fastest method for drawing on the screen. For the PC. However, many people found a C plus plus to be kind of a difficult language to learn. Okay, so that brings us to around the year 2000 and six. Around that time, Microsoft gave us a new framework called X and A and what X unaided was allowed C sharp developers to access direct X directly from C shirt. So x UNAIDS kind of, ah, set of tools and libraries that made it easy to make games that could be run on Windows desktops, laptop computers and even the Xbox. So for many programs, this was the thing we had been waiting for, a system where you could create games that ran all over the place and without an insane amount of trouble for work. Now, still, C plus plus is still the go to solution if you need to squeeze the absolute last bit of performance of a P C. But C Sharp is now a very credible solution for gaming development. This brings us to around the year 2013. Around that time, unfortunately, Microsoft discontinued Exit A development. But thanks to the open source community, all was not lost. Model game was created. It's a compatible open source version of X in a that is still being supported. Even better. Mono Game is extremely easy to learn and is oclock cross platform so you can develop games in C Sharp for IOS, Android Lennox and, of course, Windows. Okay, so why model game? Why not unity or run riel or some other gamemaker? Well, when you're picking a game development framework er engine. To start with, you got to pick something that suits your development style. So let's take a look at the three main categories. Let's look at unity and unreal. They have a great editor. They're more of a gooey experience with some coding required, So you have to do some scripting, so it's a good fit if you like the dragon drop. If you're a real beginner, you might want to use scratch or gamemaker, and they offer a much more stripped down basic experience. Toe wet your appetite, although I've seen some serious projects built with these also, which brings us to xon a slash model game. On the other hand, there fully coded experiences, okay, so if you if you prefer to control all the bits of your game and not rely on things being done for you. It's a better fit, and at least they'll give you what's on idea what's going on in the background. Okay, so to me, if you have a little bit of knowledge and c sharp, give this a try as your first sort of foray into game development. All right, so that's a brief kind of overview of the historical development of model game and now on to our next pressure. 3. What You Need: Welcome back, everybody. In today's lecture, we're gonna look at some of the software you need to participate in the course we're gonna be using visual studio. We're gonna be using model game and the last one you might not be familiar with we're gonna be using on zipping program called seven Zip. First things first, let's download visual studio. So when you click on this link, it should take you to this site right here, okay. And the visual studio that I recommend is either 2015 or 2017. Whatever you feel comfortable using, uh, and I actually used the cheapest least resource taking, ah, piece of software that there is. I use the Express 2015 and really, that's all you need to make the games we're gonna be using if you want to. You can also use the express version for 2017. If you have enough room on your computer and you want to take the whole thing. 2017 community edition is also available, so whatever, when you pick, everything will work perfectly fine. So, for instance, let me load in the Express 2015 here when you press that well, that's gonna happen. Is gonna, uh, have you download a file? Okay. And I should say that somewhere in your hard drive. And I usually make a folder for the course and usually call it a lecture. Demos. You can put it in there, and it will store the execute. Well, they're after you store the execute herbal and run it. It should install for you. Visual studio. Now, once visual studio was installed, make sure it works. So somewhere either on your start menu or ah, Nikon on your screen wherever it was installed. Check it out. This is what it should look like when it starts up. Okay. And, uh, we're not gonna do anything right now, but if you clicked on file new project, you should see that there are things like windows forms on a few other things that will talk about It's part of this course. Okay, so that looks like it's ready and installed. Okay, Next we need model game. Now you have to do it in the order. I'm doing it here. Don't install model game first and then installed visual studio. Do it the other way around. So, visual studio first and then model game. So when you press on model game, it will take you to the mono gained sight, All right? And I've got it pointing directly to the down those directory. You can also go to the front page and take a look at what model game can do, which is kind of neat. I'm just gonna press on downloads. And the version. I'd like it. A load is 3.6. Okay, This one will work in 2015 and 17. Now, after you've got this installed and we're gonna install the model game 3.6 for visual studio. All right, It'll put a set of program on your hard drive after you've got that installed. Now, what you need to do is restart visual studio, Okay? Model game is in a program out by itself. It's sort of installs itself in visual studio. So what you do is you start up your visual studio again, and this time just to make sure it worked. Goto file new project, and you should see ah, little bit of a difference in the menu system. So your look Look over here, Okay. And what you should see now is under visual. C sharp. You should have a new entry called Montel Game. Now I like it a press it And when you press it thes appear OK so you could make model game windows projects which were going to do primarily in this course. You could make phone projects for originate you can make for Windows 10 Universal projects . You could make an android project on IOS project all kinds of neat things. But for the most part, we're going to concentrate on this one right here, so that installed properly If that is what you see now in most lectures, what I'm gonna do is obviously go through and teach you how to make a game. Sometimes you'll do it with me. And even when you don't and I just demonstrate that the demos every single one of those examples are always given to you as files, OK, so if you don't feel like doing something with me, you just want to watch one time. No problem. I have all the solutions and all the examples in each of the lessons. Now all of these are compressed because sometimes I'll give you 45 sample programmes and I do is I put them all into one file, so they all end with dot r a r, which is a format used for compression. Now, what we need to do right now, before we do our last part is download Ah, piece of software that lets us un compress these files. And that's where this 77 zip comes in. OK, so when we go to that site now thistles the seven zip site and there's a different a bunch of different formats for 64 bit 32 bit. You pick whatever is appropriate for your machine. All right, you press download like usual, store it somewhere on your machine, run the execute herbal, and again, nothing magical is gonna happen. It's just gonna be installed into your system, and then I'll show you how to access it and use it. Okay, so we have visual studio installed, model game installed, and this mystery sevens have been stole. How do we use that? Well, what we do now is we press on this, remember? This is like a demo file that would be part of ah ah, lecture. So we're gonna press it and Like I said, make a folder where you're gonna put all your lecture demos, which I've called lecture demos and I'm impressed. Safe. Okay, then go to that exact folder and look what you have there. Now you have this thing that has a bunch of books on top of it, which means it's a compressed file. But how do you access it? How do you expand it? Well, what you do, if you've installed the proper sevens, that program is you, right? Click on it. They're seven Zip. And I like to distract the files here or to a sub folder. Either way will work. I'm gonna press this one right here, and in a second, you'll see a folder created from here. Let's click on this. Oh, what's this? This is the key fire. That's a double click on this. If you've installed visual studio correctly, it should start this up. OK, in a couple of seconds, it will bring in this program, okay? And this is sort of our first model game program, and there's not much to it. It just makes a blue screen. But that is proof that model game is working on your system. that program actually installed. And just to give you a little glimpse ahead of time, this is the code that we're gonna be typing in and using to make programs like what you see here. Now, sometimes this doesn't work for you. Sometimes when you click on it, it doesn't automatically start up visual studio. So there is another way to access the programs. If you would've file open project, then go to where you saved your demos. Okay, so let's say you've saved him in lecture demos on your seat. Try and there's the folder that we unzipped. And there it is, right there, that file again. But this time you're accessing it through an open in this program. So let's double click on it. And of course, I've already got it loaded up, but it will load it up again. And, uh, let's just run it again. And there it is, just your blue screen to prove that it works. OK, so there's two ways to do it. You can double click on it in just your regular file explorer, and it should start up. If that doesn't work, then go file open right in visual studio. Okay, thanks for listening. And we'll see in the next lecture 4. Creating Your First Monogame Project: Welcome to the new section. Finally, we're here. Model gain in the series of eight lectures were going to cover. Ah, very basic introduction to how Monta GameWorks. We're going to incorporate some images, some sound effects. We're gonna do a little bit of animation. So what are we gonna do in our first lecture today? What we're gonna do is we're gonna learn how to make a basic model game. Ah, Windows Project template. Then we're gonna run our first model game program. You are gonna be so impressed. And then finally, we're gonna try to understand the underlying template code. All right, so let's get started. First of all started visual studio and make sure, especially during this 1st 8 lecture intro that we do everything together. Okay? I'm not gonna go too fast. I'm gonna do little short, little tiny lessons, not throw to my chat shit all at once, so make sure visual studio has started up, okay? And, uh, what you're gonna do every time we start a project is we're gonna goto file new project, and you might see the screen. You're gonna go. Oh, Where's Model B? I thought I had it. I am sure it installed it. So you look over here and you press model game. And here are all the different templates that you can pick. We're gonna pick this 1 99% of the time. Okay? Model game, Windows project. And what we'll do for this 1st 1 will call it. And it doesn't matter what you call it 1st 2nd 3rd whatever you want to call it, I'm gonna call it guano. Uh, one. Okay. Also, where it says location minds pointing to my temp drive. You can change it to point to anywhere it might point to a document folder. I don't like putting it there. So usually click on, browse and then go somewhere on your hard drive. Okay? Pick somewhere you like. And like I told you before, most of the time, I'm going to store it in attempt drive. Or I might even in this case, just to be consistent, stored and where I have lecture demos. Okay, so I can put it in there, and then I'm gonna press select folder. So from now on, all of my demos over the next little while be saved in that particular folder in the lectures. Demo folder. Okay, I think we're ready to go. We've given it a name. All right. Make sure it says model game Windows project, and then you press OK, OK, Now, as it's starting up, what you're going to see that's different than what we've been doing up until this moment in, uh, regular C sharp graphics and wind form applications. And that's what you were doing when you were doing the previous work on animation and graphics. Is that where is the tools or there are no tools? Okay, we're going to do everything by hand, so to speak. We're not gonna drag over Ah, button and things like that or a text box. We're gonna have to do that a different way. So that's kind of like the first thing you have to get into your your head, that there aren't tools here. We're not gonna drag over little widgets or anything like that. Okay, so where's the coat? Where is this stuff? Well, over here in the property section, everything looks pretty well like you've seen before. Um, this is like form one. If you want to think of it that way, and when you press it. Here is the code, and you're gonna go. Well, what if I get to see where is the actual look of the screen? Well, you actually are going to see it in a second, but there's not gonna be kind of Ah, a design mode of screen here. Now, watch. Didn't press start. This is our first program. We're ready. What? It's done. We haven't really had done anything, but watch in a second. You're going to see your first model game? Uh, hope it. Okay, so here is the screen, the blue screen. If you get this, we have success. Hopefully you've got it, cause I didn't tell you to type in anything and, you know, mess up anything yet. But there is your first actual output of a model game screen program. Okay, Now let's pull apart and look at each section of this typical model game template and see what each part does and how we're gonna use it. So this first section up here is called the directives, all right. And by default, we add just those three when model game starts up. But later on, as we need sound effects and background music, we're going to add to these sections here. These directives. Okay, so that's the first part of typical model game template. The next part in here is a constructor, and usually we don't do much in here. Okay, this line in here is very important. We're gonna be putting some pictures and things in there later on, so it's gonna expect the content to be in that folder there. Okay, Next slide down. This routine called Initialize, is really only called once at the very beginning of the game. And what you can do there is if you were gonna have counters for scores, you might initialize your counters in that section. Lo contents. Very important. Low content is where you tell the computer what your images air called or your sound effects or your funds, cause we we have to use a funt to type in text. Okay, so that's called low contact on low content of truth. Never used it. Okay, so don't touch. It may be in some more advanced things. You'd use it, but I've never used it. This is your bread and butter. This is the most important part of the entire sort of template. All right. And what you do here is you put in your things like, let's say you're moving an object. So you were in a store where the position of the object is at any moment in time. You also might want to store the speed, and maybe you'll update the speed to make it going faster. Okay, so this routine the update routine, it's called once every game cycle. And in model game, that's usually 60 times a second, so fairly fast. Okay, Other things that are done in the update routine are things like it handles input. Which means if you're using the keyboard to play the game, it's recognizing what keys you're pressing here you're using the most. It knows if you press down on the most, or if you press the right button or the left by. Okay, so basically handles most of the game logic except drawing, which brings us to dry. Okay, this is where what you do mathematically. Now you can appear on the screen and you notice we don't really draw anything. So how did we get that blue color screen? Well, that's this thing right in here, So why don't we rub this out for a second. So we are gonna do one little thing and I'm gonna press docked, okay? And I'm gonna pick Biscuit. I don't know what that color restart truth, but we'll see. In a second, I'm gonna press run again. This will change the background color of the screen to disk, and there is brisk. Okay. And later, one, instead of having colors as our backgrounds, we will have an entire image as our background. So there is a very brief introduction to the mechanics of how you start up model game, set it up and in a small way, make a few small changes to it. Okay, See in the next lecture. 5. Managing Content : welcome back. And in our second of eight lectures on an introduction to modern game today, what we're gonna do is take a look at managing content. Basically, the first thing we're gonna do is set up a special tool. It's part of model game called the Pipeline Tool. Okay, we'll make sure that it works in your system. Then we're gonna learn how to add assets to our project. Assets are usually graphics and sound effects. Okay? And for images, BMPs J pegs and especially P and G's are the graphics of choice. Okay, most of those work very well in model game. And for audio, I would stick with waves and MP threes. We're also gonna take a look at how to organize your content into folders for a later, more advanced application. All right, start a visual studio as usual. And look, we're gonna do is we're gonna load in the one we did from the previous lecture. We're gonna actually build on that one all the time, so I'm gonna go back to file open project, and, uh, I called it mano one, So click on it, and then this is how you reopen it. Mano one dot sl end. So you're loaded in that file, just like you do in regular C sharp. Okay, Now, what we're gonna do in a second is we're going to activate this folder called Content. And inside of it is a special thing called content M gcb. Now watch what happens when I click on this. All right, this is called the model Game Pipeline Tool. And this is how we're going to add content to our game now. Right now, I don't see anything in here. I'll show you how to add to that in a second. But what's gonna happen the first time you ever do? This is this isn't gonna pop up. You're gonna go. Well, you pressed it. How come it didn't work for me? So what you need to do the very, very first time you do this is right. Click on this and then open with and you'll see model game, pipeline tool and in brackets. Default. Now, if its not said is a default. Press said his default. Okay. And then press. OK, so, uh, you will not get this total pop up unless you do this. So, the very first time that you do this. All right. Right. Click on it. Click on open with picking model, pipeline tool and press said his default and then press. OK, now, from then on, when you double click on this, it should pop up. Okay, so there is the tool kit ready to use. Now, what we're gonna do is do a little bit digging. I'm gonna go back to my folder where I have this program safe. Okay, So you have to work your way down to the temp folder wherever you decided to put all your lecture devils. And I'm gonna go inside a model one for a second and inside of this folder. Oh, and there's the fuller context. This is where you're gonna put all the content that you have for your games, All your images, your music files, whatever your sprint funds, which I'll talk to you later in a boat. A lecture or two from now. That's where you gonna copy them. So where do you get these images? Well, I just happen to have an image here. Uh, level up from here. Okay, So I went on the internet and I downloaded a picture of Daffy duck. Okay, if you've got an image you want to use, go and find something on the Internet or you can from my demos go and take them from there . But just for fun, find something yourself on the Internet and use it. So what you do is you cut it or copy it. I'm just gonna copy it, and you're gonna work your way inside this folder inside content, and they're gonna paste it in there. Now. What you do is you go back to visual studio here and when you double click on content, remember that pipeline tool starts up. What you're gonna do is you're going to right, Click on content, go to add an existing item and click on Daffy. And now Daphne will be part of your image library, so to speak that we're going to access in our next lecture. Okay? And always make sure you press safe. So that is how you deal with content and how you put it into your actual project. 6. Displaying The Content... The Sprites: Hi, guys. Welcome back. And today we're actually gonna finally do some coding what we're gonna do today's first of all, create a place to store these images. It's a special kind of variable called a texture two D. Then we'll take those images and put it into that variable. And then we'll finally draw those images using this Sprite batch object. Now, it's really important as we go through these applications that you actually do it with me. Okay, let's build these applications together, especially in this first section where we're just littering the mechanics of how model GameWorks. And don't worry, you're going to stumble. That's okay. That's how you learn. And don't feel like what if I stumbled? I can't fix it. Well, every single example I do in this whole course, and you probably know by now I will give you, uh, the zipped up file, the compressed file so that you can look at it after So, uh, trust me, everything we do, we have all of them for you. All right. So, as you go through each lecture in this section, there's gonna be a model intro to 38 Whatever. So today we're gonna do two and three. So if you falter somewhere along the line, they're there for you to use and Peru, so to speak. Okay, lets go and grab the project. We worked on last lecture. Okay? Hopefully you have. It's called model one. If you don't have it or you didn't want to do it, remember, you can load in my demos, and they will have the same solution right there. But I'm gonna use the one that I did with you guys mano one. So let's load it up. Okay. So, like I said today, what we're gonna do is take that daffy duck that we put into that tool pipeline on. Now we're gonna put it into the program we're going to display. All right, Now, just to make sure we've got we're on the same page, we're gonna click on the content pipeline, and you should have Daffy there. All right, let's do some Cody. Okay, so now we're gonna just close this off, and, um, we've gone through all the different sections, but I didn't really talk too much about this in here. Last lecture. So this is an important class. The Sprite batch class that's we're gonna used actually draw our object on the screen, right? It's already set up for us. And they're gonna be there's gonna be an instance of the Sprite batch Charest called spray Batch, but just the the S is in lower case. Okay, right underneath that. What we're gonna do is make our first declaration of a variable that we're going to use toe . Have the computer remember our image. Now, if you remember in the previous lectures, when we're doing regular C sharp, we actually had an image object. Well, no such thing in Monday in Model game, those air called Texture two D, right. And we're gonna call our sprite texture. Just spray texture like that. You can give it a name later on. Maybe later on, we'll switch it to Daffy instead of that. OK, but there is our declaration. So this is the instant object that's going to remember our image of Daffy Duck. Okay, so that's the first day. Second part now is toe load that image into the computer. All right, so what you do now is you use a special command. But first of all, we're gonna tell the computer that it's gonna go into this variable, we just create it, and we're gonna use a new command called content dot load and then use this funny thing Angle brackets, Okay. And in the angle brackets, you're gonna right. It's a type texture two d, All right, And then outside the angle brackets, you're gonna have a bracket with quotes. Now, you probably remember it was called Daffy. You might even think that it had an ending on it, like P and G. But you don't include the endings, OK, so don't write the ending on it just right, the first part of the name and then some equal. Okay, we're not getting any errors. That's a good sign. So that's the second stage. So we declared a variable. We have now loaded Daffy into that variable the image, and now it's time to show it off. And to show it off, we go down to the drama routine. Now in the drama team, it's not just a one step process. The driver teen, What you have to do is set it up. So you have to tell the computer, begin and then end. All right, so what we're gonna do there is. Remember our Sprite batches called sprite batch dot And then we type in the word begin, and then inside here we draw, and then we end it. So I'm gonna put the ending part in right now to just so you know, that there's a beginning and an end. Okay, so in between, those two is going to be all the draw commands. If we had multiple objects, you'd have four or five lines of draw commands. Okay, Now, here's how you do a draw in Monday. What you say is sprayed batch again dot Yes. You guessed it dropped bracket. Now there's eight versions of this draw. Command, we're gonna show you probably three or four in this course. We're gonna use the simplest one right now. Obviously, but we're going to do first is tell the computer what we want to draw, and our object is stored in Sprite texture. Okay, then, comma. Now we have to tell the computer where to drive, and I'll give you a quick lesson on this in a few seconds. But basically, if you remember your screen coordinates, remember, the left hand side of the screen is 00 and the corner down the bottom. We don't know the exact number, but I'll show you roughly how to estimate that later run. But anyway, I want to put something at 00 so I just can't go 00 which we did before when we were doing draw image in regular see shirt. Now we're into some fancy terminology we're gonna do is create a new object. It's a vector. Okay, Almost like a little bit of physics going on here. And then you put down zero comma zero. So there is again a new twist in model game. You just don't put down the coordinate. You do it that way. And the last part is we're gonna use a basic color. This would blend in with whatever's on the screen. It doesn't really affect the answer. That's the safest way to present it. Okay, I think we're ready. I'm always a little nervous, so I always like to do a save all first, just in case something really messes up and then won't run it. And there is Daffy and you're going Well, he's not really at the right corner. But remember our theory from before that corner actually is there. But Daffy. The image of Daffy was really a rectangular image enclosed right there. So that's why you don't have Daffy right at that corner. I guess we could have tried to put Daffy and negative location what you can do, but for our instance right now, that's fine. Okay. And there is this. There's Daffy, located at 00 And there is your first graphical display using monarchy. Now, you may have noticed for today's resources, I have another image in the resources this one right here. OK, we want to do next just to make a small, incremental improvement to the the program we just did is have two images on the screen. But as things start getting messier, what I want to do is make it more organized by putting them in a folder so much what I'm gonna do, um, gonna sneak into here, okay? And I'm gonna go into my own game content, and, uh, I'm going to right click and make a folder called Images. Okay, so in a second, I'm gonna put Daffy mean I could put him in right now, but I'm gonna do something first before I do that And so that's gonna be the place where I'm gonna put these two images. So let me just drop this down for a second. Because what I'm gonna do now is they're going to go into the content, uh, pipeline tool and this daffy I'm gonna delete it. They're gonna get mad at me. Um, you sure you want to leave it? Yes. I'm gonna delete it. Okay. And I'm going Teoh save nothing, obviously. And then I'm gonna go back to here. And now I'm gonna take these two objects, and I'm going to copy them into this folder that I've made called images and put him in there. Okay, so when you start making more complicated games, you're probably gonna have an audio folder on Images folder, maybe even a sprites folder. Okay, so it's just a more organized way to work. Not gonna do this every single time, but I mentioned in my last lecture, so I wanted to show you exactly how it works. OK, so now what you do. So now you go back into, uh, your program and you started the content manager again. And, uh, we're gonna right click like we did before we're gonna say, add existing item. We're in a press on images I'm going to say open. Okay, so now we've got a full her with images inside of them. Okay? And it were set, and now we press safe. We close it. Now, let's go through the mechanics again. But this time, give them more reasonable names. So instead, is texture to the sprite texture. Let's actually call it Daffy. Okay? And now we're gonna have, um, e gets the most. The name of it isn't months. Some will go back to that in a second. Okay, so there's your two textures. Okay, down here. Now it's yelling. I mean, because there's no such thing anymore. This is going to be daffy, but we're gonna have to make another small change to this. Daffy isn't right at the content level anymore. Daffy is in, uh, a subdirectory, so to speak. Okay? Called images. I think I spoke with images within s If it isn't, we'll fix it in a second, okay? And then the most same thing. We're gonna go looking for it in that subdirectory. And here's the thing. I don't think I called it most when I got it off the Internet. I think it was called Khar tune. All right. So even though I think it's a most picture, it's called Khartoum, and it saved. All right, Now, let me just say this for a second, cause we're almost ready to display it. Just a double check when you go back in here. All right? So we have a full day, call images now cartoon. Okay. And then Daffy. Perfect. All right. Now, at the last stage, now we have to take these images and throw him on the screen. So it's not called a sprite texture and more, and it's more reasonable to call it Kathy. Right? Because that's what we're looking for it. So when you refer back your code have a better idea? You know what exactly is being placed at a particular spot And the other ones of most We don't wanna put it the same spot. So I'm gonna basically guess right now, because I don't know how big my screen is, but I got a rough idea where I want to put this. Okay? And if it doesn't look right, Okay. Got a big problem. Okay, so we're now ready to display this. Okay, so there's Daffy Top left corner, and there is the most above 400 pixels over in a couple 100 pixels down and good quality images. And, you know, from before try to look for transparent images that have transparent backgrounds P and G's air. Always pretty good for that. Um, so that's the way to go. Okay, So there you have our next sort of incremental skill displaying images, putting them in subdirectories and put them on the screen. Okay. There you go. Thanks for listening. We'll see in the next lecture. 7. Moving The Sprites: Have you gotten the bug yet? OK, so we just learned to put some characters on the screen. Let's make them move now. So in this new lecture, we're going to focus on moving sprites. We're gonna take a look at the concept of motion and model game. Specifically, we're going to do today is take a look at how to use the vector to class to create an object which will indicate the location of the object on the screen. Then we'll go to the update routine and we'll update this new vector location, object. And, of course, then we'll go to the draw method to re display it at the new location constantly and constantly and constantly as it moves across the screen. Okay, so, as we've done for the last couple of lectures, let's load in the current incarnation of our model program. And again you could resort to the downloaded demos if you want to or do the one you've been doing with me. Hopefully. Okay, so we're gonna load it up, And just to remind you what it looks like, it's got the two images of ah, Daffy duck and the most okay, probably not going to use the most. Um, gonna take that. Oh, I'm just gonna, in this particular lecture, move Daffy across the screen. Okay, so if you're thinking back to how we did animation before in regular C sharp withdraw image around here. So first of all, gonna comin out the most around here, What you'd usually do if you wanted to do animation where things were moving, you couldn't have a constant number like 00 or 55 or something. You had to have something like a an X and a Y, and we would have those continually being updated so the X would move over a couple and the why would come over a couple so you'd be going across and down or whatever. Okay, Well, like I told you before, there is no such thing now. Is numbers there? That has to be a vector, too. So somehow we've got to create some sort of variable that's going to go in that spot right there to take the place of annexing warrant. So let's slide up. And don't worry about that. Error will fix it in a minute. Okay. We'll slide up here and what we're gonna do First is now introduce a brand new variable type. It's an object of the vector to class. OK, so we're going to save Vector to We're gonna call it Sprite location. Okay, that's where you declare it. Now, where do you use it? Well, in the update routine, that's where all the math happens, right? That's where all the collision detection happens. That's where you update the things before you actually re display them. So what we're gonna do for the first time is now add something to the update routine in the update routine. We're going to tell the computer to somehow move the Sprite location over a little bit and down a little bit. Now, how do you say that? Like, can't say X and y. So we've got this new variable called Sprite location just for fun. I didn't impress the doctor. And look at all these choices here. Who in one of them? This thing Right here, X. That's good. Equals two. We're gonna read it almost like a math equation on. We could have written a bit shorter, but for now we're gonna do it this way. Plus, let's go over five. So what we're telling the computer now is this Sprite location, which has basically two components and external. Why move the X component over above five? So we're gonna go over to the right, and then obviously there's gonna be a why dot Y equals and then Sprite location. Why? Plus cells when he maybe go down one. So what we're telling the computer now is move across the screen. Five and down one. Okay, So what's next? One more thing We have to now take this daffy duck and move it. According to that Sprite location. So this is what makes this so cool. Sprite location. Dot dot Exe and not downwind, despite location. That right there is the vector incorporated. Inside of there is the X and Y movements. That's it. That's all it's gonna take. I think we'll seek cable press save all. And I remember not pregnant then the most anymore, not displaying the most. And there it is. There is. Look, it's gone already. Come back again. This Let's write it one more time. All right, So there's the daffy duck going across the screen, and we're gonna have to worry about it hitting the wall in a few seconds, but we'll worry about that in a future election. That's it. That's all it takes to move something. So let's recap very quickly. What takes is to move an object is to first of all, define kind of Ah, variable, a special kind of variable vector. And that vector has an X component in the Y component sort of buried inside that object name. The update is where all the action happens. Remember, this is where every 60 times a second it comes back here and updates whatever calculations you are putting their and what I've done here is made it move a certain direction. Okay? And then obviously you have to redraw it right there. Okay. And they're quick and quick. Fast is ah, quick introduction to how you make objects move on the screen. Now you want to have some fun as I finish the video, how about you try placing the duck somewhere else and making it move up or down, just like we did before in regular C sharp. You know that now, by now, and it's gonna be very easy. All you have to do is modify these two locations. Just fool around it to see and make yourself feel more comfortable with movements. Okay, Thanks for listening. And I'm to the next lecture. 8. The Velocity Vector: Hi, everybody. In this short lecture, we're gonna make one small tweak to our ah sort of progression of programs in this lecture , we're going to take a look at what we call the velocity vector. So we're gonna introduce the concept of velocity, and then we're gonna add a velocity vector instead of a constant. So you know where we're adding five over and one down instead of adding those Constance, we're going to do it in a more structured, formal way, and we're gonna talk a little bit of haute vector addition, and you're gonna see some sort of introductory math concepts. All right, time to low back in our program that we've been working on for the last couple of lectures . And when last we left this program and I'm still calling it one on one, we had introduced a bit of ah movement, all right. And right there, we were making the object in this case, Daffy moved five over to the right and one down. What we're gonna do now is add another sort of variable, okay or instance variable up here. Now, we've got this vector to sprint location, and I'm going to formalize this just a little bit. What I'm gonna do here is I'm gonna put in that it's set to zero. So Vector Two and then 00 I didn't do that last time. Didn't matter. It by default was 00 But it's nice to include that. Okay, so there it is now, the introduction of the new variable. So I'll put some comments here, just so when you refer to it, you know what I'm talking about. So we're gonna add a velocity variable. Okay? So instead of using a constant number, we're gonna make a velocity variable, which will be used to move the image, okay. And basically, it's gonna be a vector to again. So we're gonna say vector to and we're gonna call it, uh, Sprite velocity and will be setting it toe a value that allows us to say, move five over and one down. So it's gonna just basically repeat what I had in my previous lecture, but in a more formal structured wait. So the way we're going to say that it's five common one. So what's going on inside of here is that there is ah, an X component in a white component, and we've now put them in a an object called Sprite velocity. So what else do we need to change now? Well, let's go down to our update routine. Okay? Where we were doing this and we're gonna do is we're gonna comment these out, and we're gonna add kind of an unusual line. So first of all, we're going to still update the Sprite location. OK, But we're not gonna do it with a dot Exe and out. Why anymore? We're just gonna write it like this. It's gonna be kind of neat plus this new and will go back up to refer to it. Sprite velocity. Okay, now you're going to say, Well, where's all the math going on there? I don't see the numbers. Okay, so remember this object basically has an X and y component, and this one here also has an X and y component. So if I conduced a little about your screen for a second and sort of review some, um, dr, uh, A theory. In essence, this first Sprite location has an X one y one component to it, and we're gonna add it to the Sprite velocity, which has, uh, call the X two. Why two component to it? So what? These two lines air doing together is joining this x one and X two. All right, so we're finding this some of those two, and it becomes the new X component for our location of our daffy duck in this case. And then when we add the y component of the 1st 1 to the y component of the second, that will be the new Y location for Daffy Duck. Okay, so this is a little bit like we call vector addition. Okay, so it's kind of neat that we've been be able to put it in one little succinct statement like that is not cool, Okay? It also reduces all of this lineup there. What's left the drawing. Do we have to do anything special on drying? Not really. Because we've already got the Sprite location. So when we run this for stalling me, save it when we run this not notice much of a difference. Let's take a look. Right. So there it is, moving across the screen again. So nothing really changed. It's just a more succinct way toe. Add it. Now, what's the point of this. Well, it's nice to have a central location where we can update the code because of refer to movement somewhere else in the program, maybe in four or five other spots. Is that you having to actually hand right each one of those spots? You now have sort of a master variable. That will change, although so if I decided to change it to let's make a go a lot slower so that you can see it moving across the screen. So let's make it go one across and one down and let's see how slow that looks. So I'm rooms just changed that from that master location. Okay, so it's going a bit slower that way. Why don't we change it one more time? Let's make a gold one over and three across, and that will be our last change. Okay, so we're changing all from that central location. All right, so there it went down quickly. So there is this new idea of the sprite velocity and how we're gonna incorporate it into our animation. Okay, short little sweeten. Quick lecture. Thanks for listening in on to the next section. 9. Hitting The Wall !: hitting the wall. I hope you actually haven't hit the wall yet. But what we're going to do now in this next lecture is figure out how Daffy Duck knows when it hits the wall, cause now we want him to bounce off the wall. So we're gonna look at the stream constraints, figure out exactly where is the right hand side of the screen and the bottom and the top on the left. So that's gonna be the focus of this little small lecture. Okay, let's load in our favorite program and continue from where we left off. Work our way back up here and loaded model game. I'm gonna get something off my chest first. Every time I've been demonstrating this to you, the main screen is a little bit off to the left, and I've been sort of waiting to show you this little technique until now. Just to show you that I was being driven crazy by that. How always having to slide it over. So the first thing you're going to see me do here is I added this line here. And if you want to add it into you can basically, you know, in a regular C sharp. We had that sort of in properties center screen where you could have the form appear in the Senate. The screen. There's no such property in obviously model game, but this is how you do it. And then these numbers, I kind of guessed so roughly for my screen set up, I haven't moved 400 over and 200 down, and when you press start now, you're going to see Daffy Duck in the middle of the screen. Thank God, because I hate it always trying to grab it, show it to you. Second thing I want to do before we get rolling here is Let's put this back to something I think I started with and I think I had there five and a one. Let me just run that again and see what that looks like. Okay, so that's pretty decent going across the screen in a nice speed. And finally, it's in the middle of the screen now Screen constraints apartment while I do it a little bit on your screen. And as I discuss exactly how do we know when we're at the edge of a screen and we've covered a little bit of this kind of idea already in the first part of the course, but I want to show it to you here. Two. So let's pretend this is Daffy Duck and he's just about to hit the wall. Okay, so how do I know when he's hit this side of the screen? Well, first of all, when we're tracking Daffy Duck were basically tracking this number right there, which is the exposition and the Y position in any moment in time. So what we're gonna need to do is add how wide this spring is. Okay, so there's a with property, So our, uh, I think I called it sprite texture. What we'll do is check it with a dot with, add it to the position that were at and see if we've hit the wall now in a regular C sharp . We had this dot with or some other different techniques in model game. It's fairly a long, drawn out word, and I will type it in for him a second. But it's graphics Die graphics designer device dot vieux port dot with OK, so it's a most full, and it's basically the same with dot height So that's gonna be how we're gonna figure out that we've hit this wall and then we'll make the direction reverse and we'll start going the other way. Course, After I finished this, I'll give you as a challenge, make him come straight down and bounce the other way or make him hit up here and bounce the other way or make him go this way and bounce the other way. Okay, so once you learn the 1st 1 the other ones are pretty straightforward. All right, I've planted myself in the update routine. That's where all things like collisions, wall detection, character movements happen. So we're gonna decide on when we've hit the wall. So obviously a decision starts off with the word if, okay, and we're gonna track where we are at any moment in time. And if you remember the way we track where we are today movement times with Sprite location . Now we're going across. So we're worried about the X right now. That's not enough. We also need to know how wide Daffy Duck is. So where we are at any moment in time, plus the with a daffy duck is gonna be the crucial value. So Daffy dock with. I want that to be slightly greater than the edge of the right hand side of the screen. And this is where that multiple comes in. So you type in the word graphics dot and then graphics device dot vieux port docked and the width and that's the size of the whole screen. Now, once we've hit the edge of the screen, what exactly do we want to do? Well, I'll put a brace bracket, but I want you to do one thing in here right now. Later. Wrong way. We could make a sound effect. Makes a sort of explosion a graphic happen for now, we're just gonna do one thing. We're gonna reverse direction. So how do you tell the computer go in the opposite direction that you were going? Well, remember where we are when we in that location called Spring Location X. How are we moving? But Maurin a bit more in a bit more. That's that velocity stuff we did in the previous lecture. So we called that velocity stuff Sprite velocity and we're just worried about the X. Okay. Has two components right in external. Why and what we're gonna tell the computer is make it go in reverse. So if you know your math, what you do to say something in reverses u se minus, we're gonna say Sprint velocity Die X and that's it. That's the whole process. This is going to check for the wall. If we hit the wall, we're gonna make the amount that we're going across by become minus the amount that we're gonna go across by. So that means we're gonna go backwards. Let's give it a run. Okay, Now, we haven't put in the other collisions, so you notice that it goes off the wall? That's why I'm saying to you, once you feel comfortable with this one, you would have a series of four if statements to worry about every other condition. Okay, so the left hand side of the wall obviously would be zero. The very top of the wall would be zero for the why. And the bottom would be basically this line here, but with the word height. Okay, so there is your basic theory on wall collisions and how you can reverse directions. And again, we're gonna tweak thes and get a more sophisticated, but each one again. Baby steps. I'm just giving you a little bit of enough of an idea just to get you going. Okay? I leave you with the challenge, work out the other four other three of the four or combinations of hitting the wall and make it move in any way you want. Okay, Thanks for listening. And we'll see in the next lecture. 10. Drawing Text: Welcome back, everybody. And today we take a look at drawing text on the screen. So we're going to create what's called a sprite fart using the pipeline tool. And then we're going to edit it and maybe change the font style or the bold italic and be the size of the farm. Then we're gonna take the sprite font that we've now set into the computer, and we're going to display ah, little text on the screen indicating how many times maybe we hit the right hand side wall and we're going to do that with the drawstring command. You know how we put stuff on the screen with the sprite batch dot drawing? Now there's gonna be a Sprite batch, Doc Drawstring. Now, I'd be remiss if I didn't take up the challenge I gave you last lecture. Okay, remember, this is a gentle approach to game development, so I don't want to leave you hanging. If you tried it and you couldn't get it or if you tried it, you just want to compare it to my answer. Let's take a look at it right now. So I left with you with the challenge of making the object bounce off of all four walls, Not just the one on the right hand side. So I want to show you the solution, just in case you didn't get it. And you can freeze the video at this spot if you want and type it in. But here is basically what we left you with last lecture. Just having the daffy duck hit the right hand side wall and then bounce back. What about all the other combinations? Well, what if Daffy Duck moves his way back to the left hand wall? Well, when we get to zero, because that would be the location of the left hand wall, we're going to reverse the direction again. So if we were going negative and now we're going to negate that negative. So two negatives make a positive. So we're back to going to the right. Okay, so that's that particular location. What if we hit the bottom of the screen? Well, this is the if statement for the bottom of the screen basically the same as the going to the right. But this time you're figuring out the top location of Daffy Deaf duck's head. Then you add how tall Daffy Duck is so that's the height. And you see if that's greater than the View Port height. And if that's true, he reversed the wind direction. And of course, the last one is if you go and hit the top of the screen, OK? And if that few ducks had hits the top of the screen and he was moving upward, which was a negative direction, we're going to negate that negative. So two negatives make a positive, and then we're going to make it go back down. So that is basically how that works. Just do a quick run for a second just to prove to you that it works. So now you see Daffy Duck down, seeing off of all of the screens. Okay, so that was that little problem I gave you. So again, remember, ride the bike, fall off the bike, fix your problems. If you can fix him yourself even better. If you can't, at least try it and then come back and we'll take up the solution. Now, what we're gonna do is we're gonna add some text to our screen display. So what I'm gonna do is put a little title as daffy duck moves across the screen and I'm gonna have ah, constant score indicator. And what we'll do in this particular example is, every time, Daffy Duck, it's the right hand side wall. What I'll do is update the count and keep just track of that particular number. Now, to do that, we need to incorporate what's called a spread farm. And the way you do that is you start up the pipeline tool, right? Next, what we do is we right? Click on the word content and now you know how we said add an existing item. We're gonna add a new item in a press new item and here our choices We're gonna pick the one that says Sprint Front and we're going to give it a decent name. So we're gonna keep track of the score. So I'm gonna call this font that score find and I'm gonna press OK, and then I'm gonna press, see, and that's it. That's how you set it up Now I don't want to get to two confused yet eso I'm not gonna modify this. Whatever the funt was, it's just a default fault. I think it uses aerial. We'll come back to this and then we'll modify it in a few seconds. Let's go back into the code now and add it to our program. So next thing let's slide up and we're gonna add a couple of new variables. So the most obvious new variable we're gonna add is obviously this new thing that's called a spray front. So you take in Sprite fart like that and we'll give it a variable name. Fucked. Okay. Doesn't have to match what I called it in that program. The pipeline to Okay, you'll see where connects in a second. So we're just gonna call our generic fund fun just about like that. And you heard me also say that I want to keep track of how many times I hit the wall. So I'm gonna have a new variable called account or counter. You can call it anything you want. Okay, so that's the next step. Next, we need to add this fund into the computer. And you know how we loaded in the images here? We're gonna do the same thing with the funds. Remember, our fund is called fucked, and we're still going to use that word content dot load, and then we're still gonna angle bracket. But, uh, this time we're not gonna angle bracket, uh, texture two D. Obviously, we're going to angle bracket a Sprite. Funt. Okay, And then in quotes, we called it to score. So that's where the score word comes in. And then cynical and again, you don't put the ending on. Just leave it like that. All right? Now it's a draw that actual fund on the screen will say something. So we'll go down to our draw our team, and it's gonna be just before the end. Put it right here so we'll start out likely other ones spring, batch dot draw, string and then bracket. And now what you do is you. First of all mentioned the font you're using. So we're using this variable call front, and I'll just say, Welcome. That's it, OK, and then comma. All right. And now the next thing you need is where you want to put it. So knew that there were familiar with this already, and I'm just gonna guess I'm gonna go with the 400 over and 200 down. And then the last part is it that color white and then some equal. All right, so I think we're ready to display. Let's give it a quick run. Okay, so there it is, kind of in the middle of the screen. Hey, wait a minute. Didn't you say you were going to score up there? Yeah, I did. What do you do that? Remember, anything that involves calculations happens in our update routine. So I left this on purpose with the squiggly little brackets there when we hit the right hand side of the wall just for fun. How about we update the count by one just to keep track of that score? Okay, but just that one. Nothing else. And then down here, where it says welcome. What we're gonna have to do now is attach that score, uh, variable to our particular calculation. Okay, now, score appeared to string. It's not called score. It's called Count. Okay. And that's why it was yelling at me, all right? And we are ready to going to put a little space here. Just so it's not stuck right together when it runs. And here's a quick little look at it. So right now, zero there goes the one. And then to etcetera. Now you don't like the weight. You don't like that fun. You don't like the size. No problem. That's what we're gonna do next. So let's say we want to change the color from white to something else. Will that change is easy breaking from your face, so we'll change it to, Let's say Green. All right, very easy fix. Give it a quick run. And just like that, our text is now green. But what if we want to change the size of it? The font style, things like that. That's where we got to do a little more digging now. To change the actual fun, we're gonna have to start up the content pipeline tool and, um, click on once the score fund. But then right click and now hope this is gonna match on your computer mine when I press open starts up note pad, and there's an ugly mess there. But that's the format of this, and it's written in XML. If you're familiar with HTML, it's kind of a tag based language, so you notice it always has a tag. At the beginning, there's one called Funding and then slash font name and there is the fun in the middle and what we're going to do, right there is type in one of the only other rather funds I know times New Roman. Okay, it's fairly common. One that everybody knows about. How about we change the size? There's the size tag to 24 instead of 12. And here it has the style that says we can use regular, bold italic Let's go and make that the word bold. Okay, so this is what it takes to update the funt in this XML code, and then we press file se okay. And just in case we need to save again press save there and that's it by press run. Now let's see what it's gonna look like. So there it is. 24 fund size times new Roman and Bolt. And we've still got our color green from before. So that would be what it would take to change the look and appearance of the text. Okay, guys. So there you have a nice introduction to how you incorporate text into a mano game. Take care. We'll see in the next lecture 11. Adding Background Music and Sound Effects: Hey, guys, welcome back. And today it's our last lecture in this section on an introduction to model game. And, of course, what intro would be complete without talking a boat sounds and we're gonna do. Today's talk about had add background, music and sound effects into your model game. So what were first? It'll do when we do, this lecture will talk about how we add the directives, those air those things at the top of, ah, see sharp program with the words using. So we need to add a few new ones there to make sounds work, and then we'll make some instance variables. Okay, there's a sound class and a seven defects class that will talk about then, of course, you've got a load the sounds into the program, and then we'll lastly, we play the sounds of desired location, the program and the two key parts of the lecture. Today was gonna be that could be background sounds, which are usually MP threes and then sound effects, which are usually waits. In case with those, they're gonna be our two main components. All right, so let's get started. Let's do some prep work first in the lecture resources for today. I have included two files once called aero dot wave and the other one's called intro dot mp three. And what we need to do, first of all, after you've downloaded him on your computer and I've already got them on mine, is we need to copy them into the content folder for Project. So let me just do that right now, and you guys should do the same thing. So we're gonna go to mono content and we'll just pop it right here. Now, if we make a more sophisticated game later on, we can put him in sub folders. But for now, that's fine. Next. Now let's load in our program for the last time in this section and we've been using, of course, mano one. And we'll load it in right now. And our next stage is gonna be now to double click on the content to start up the pipeline tool. And we're gonna add those two sound effects. The wave in the MP three. All right, so here's our pipeline tool. We've got images, we've got a sprite. So now we're going to right click on content and we're gonna press existing item cause they're already there and we're gonna click on Arrow, and I'm gonna press the control key and intro and then press open. Okay, so now we've got those two sounds in the computers. Ah, pipeline tool. We're gonna press, save, and we're gonna close that. Now we're ready to code. And as I mentioned in the opening, we need to add a couple of directives at the very top. Okay, so what I'm gonna do is try to copy and paste, because we just got a changes fall little thing on each one. So we need to load in two directives. One is going to be for the songs, and one is gonna be for the sound effects. So we compress docked, and I'm looking for media. All right, so that's the 1st 1 we need. Okay. And I'll put a little comment here so you can remember. But I'm doing this for So you need this for, uh, song game class. All right. And we'll do it again. But this time we need it for the sound effects. So, uh, you might want to see this when you press dot OK, so there's a one called audio. And again, I put a little comment there for you needed, uh, for the sound effects. Okay, so those were the 1st 2 things you need. So model game and even the old ex today did not always add this automatically. Okay, so you had to physically do that yourself. Now I'm gonna focus just on the song class first and show you how it's used primarily for background sounds, but you can use it also for sound effects. But let me show you that one first, and we'll sort of really do a nice job on that one, then will switch over to sound effects. So the way you declare the sung class object, as you basically say's Capital song and then whatever you want to call your object and that's it, that's the declaration. Now, what you have to realize with this song class is that it plays throughout, uh, game and doesn't support multiple instances. Now, What that means is that another thing happens while this is playing. This one totally stops, and then the other one plays. So it's kind of not good for sound effects. So you'd like to have a background music plane and then this is just doing his job. And then you have the other thing, which I'm gonna teach in a few minutes called sound effects, shooting bullets and whatever else. But if you just use song, one will stop and the other one will start. So, you know, you got to be careful how you use it. So let me just finish off this comment here, okay? So just so you remember what I'm trying to show you Now we move down and we load the song in like we've loaded pictures and everything else. Okay, so in the load content section, we're in a type in the word song and uses the same basic that set up the content dot load. And then you use the angle brackets. And of course, this one is a son. So there is actually in capitals song class in there and then bracket quotes, and I think the one that I want No, it was an MP three called intro. Okay, So MP threes, uh, work best with the song class. Okay? And they're used mostly for background. Now, let's say this is the background music for a game you could actually start it right here. If you want, or you can put it in the initialized routine is a couple of spots where you can put it. You want it in a place where it's only executed once. Okay, so I would say, Put it right here. Great. So how do you play it? Well, you actually access what is called the media player. Okay, there's a dot play, and then in the bracket, you write down the name of the song. One playing actually called their song. So that's it. That's how you get it to play. Let's tryto so there is the background music plain and our animation still going, and it's still doing our logic to figure out if it's hit the wall and we're still updating the counter in the score in this case. Okay, so there it is working. Now there's one more feature I want to mention about the song class and in this case, the media player. Let's say you've got a song that's kind of short, like it's maybe 30 seconds and you're game. You're gonna last forever. You could make it repeat. So what you can say here is you can say media player dot and then, uh, is repeating. And then you want to make it equal to Troop. And what that will do is keep repeating the song kind of loop it, All right. And I'll even put little coming there. Uh, loops song. Okay, so that you can keep playing it over and over again. So it's a nice little feature. Now, that's not gonna really be, you know, necessary for this miss A fairly long song, but that it would repeat if the song ended. So you would never get in trouble of stopping your music while people are still playing your game. Now we're going to start messing around with the song class. We're not going to the sound effects yet. What if I had found some great music I wanted to play, but it was a way file instead. So I wanted to use a row dot wave instead of intro. Okay, so I just wanted you to see that screen before I actually do the coating. So it wanted arrow instead of, uh, intro. All right, let's go into the code, and we'll fool around with it. So first of all will keep the song okay. We'll just keep that one there. It's no problem. And we're gonna do another song, and we're gonna call it New Song. Okay, so there's no problem there, and then we slide down and we're gonna load it. So see where it says song, We're gonna say new song, and then we're going to see if I can just copy and paste here to save me a little bit of time, Okay? And it's not called intro, obviously. Okay. Remember, uh, it was called general. All right, so right in here, I will put the word Pero And then instead of playing that song, I'm gonna play the Aero song. So it will be my background music, and it's probably not a very long thing, but I just want to play that instead. Okay, let's see if it actually works. Okay, let's press start. Oh, no mistake. Right now. I did this intentionally, but it just shows you that the song class kind of wants to work with MP threes. And if it's really forced to work with waves, you're gonna have to make a small adjustment to it. So we haven't really, technically done anything super wrong, but we're gonna have to make a little modification. And it's the problem with Aero being away file. So let's stop this for a second. And where we're gonna make the modification is work, and I have to go into the pipeline tool, which has classified songs a certain way and wait files a certain way. So if you notice when I click on the MP three down here, it says Song and wonderful stretches out a bit more. Yet it's a song type Monica Gate, all right, and with Arrow, it's a sound effect model game. But watch when I press on this, it lets me change it into a song. That's a really important change if you end up finding a way file that you really like, and I'm gonna press safe and close it. And now let's see what happens. That was it very short. Okay, Obviously, he wouldn't use that as your background music, but that was that sound effect. But now it has become a sound object, which you could use if you had a nice song that was buying by chance Away five. Okay, let's do another tweak. I got another idea how boat we take this song or in this case, kind of a sound effect that we had as a background music and leave it alone commented. And what we're gonna do instead is when the object hits the wall, we're gonna play that sound effects that might be kind of cool, and it be more appropriate and hearing along music sound So right here when I reverse directions and give myself point for hitting the wall or whatever, I'm gonna play that sound effect. Let's that that sounds like that's kind of cool. Okay, so you might say Great, sir, this is in a solution for our sound effects. But here's the problem. Okay, what if you have a nice game that has background music and you want to implement a sound effect for any in the wall? But you use a song as opposed to a sound effect, which I'm gonna show you in a second to finish up this lecture. Let's get Botham going the same time. Then you're gonna start to appreciate thing about multiple instances and how they conflict . So let me uncommon this and actually, not that one. We're gonna play the background music, so it's this one right here. So this is gonna play the background song, and then we're gonna hit the wall with the sound effect. But watch what happens when they do this on the background. Music stopped. Okay, so that's what I mean. A boat. When you use the song object, only one or the other can run. Okay, so that's gonna keep going. Now the other one stopped. It's too late to bet. Now if we somewhere else in this program started playing the background music again, this sound effect would stop in the background. Music would play until we got to the wall again. So we need the sound effect to help us out. All right, let's finish up and give you an idea of the sound effect technique. Okay, so let's go back up to the very top. And this time it will do, is we'll declare a sound effect as opposed to a song. So right in here will type in the word sound effect, can give it a name. Um, we'll just call it sound effect again. Spell it in small letters like that. Okay, so there's the first section. You declare your sound effect and of course. Next we have to load in the sound effect. So it's almost like right in front of me already. So it's ah sound. And then in effect equals content dot load and then angle brackets. And, of course, inside the brackets sound effect. And then outside the bracket, we got the brackets and then Carol. Okay, so there's our declaration. All right? And then what's left to do? What? We have to play the sound effect wherever we want it. Now, I'm gonna tell you right now, uh, there was an issue with sound effect when I uploaded version 3.6 of model games so it might not come out to clear when you hear it on yours is not gonna be in error anything. But hopefully it'll work properly and loudly on your system. Remember, uh, this was the stupid way to do a sound effect at that moment, and we'll had the proper way, and it's pretty straight for its very easy and, uh, succinct sound. But the fact is that what I called it right dot and then play. That's it. Okay. Time to try it. Oh, and, uh, you might not hear it clearly on the screen when I show it to you. But hopefully on your system, you'll hear it. Okay, Another mistake. I'll tell you what happened. You know, that little thing I was fool around with when we did the song? And I said, OK, pretend we wanted to use away file as the sun. Well, we had made the way file into a song type. So what we could do now is go back into our pipeline tool and put it back to what it should be, which is a sound effects. And let's go back in here for a sec. And these were things that could happen to you, right? Eso you notice arrow right now is kind of like a a song type. So we have to put it back to what it should be. It should be, uh, in effect. OK, sound effects. So there it is, right there. And I would proceed again and we'll give it run this time. You're not going to get an error. I don't know if you're gonna clearly hear anything. Oh, so now this thing right here has to be commented out because we're no longer using it. Okay, which is no problem. We're just fool around like we've done it. Quite a few changes here. So, you know, I just comment that it's kind of the sneaky way to say, Leave that alone, Okay? And then we have Daffy Duck and then you hear that little noise there. I can just barely heard how my speakers Hopefully it's not a glitch that showing up on your system either. But there you have a nice little introduction into sound effects and songs. Thanks for listening. And we'll see in the news section. Hey, that's so fast. Just before you go to the new section, make sure you try the quiz it I've got at the bottom off this section does a nice little review of some of the important concepts we covered in our first shot at Money game. The next section will basically be a recap of a lot of these concepts, but will introduce this idea of object oriented programming so it might feel like they were doing the same stuff again. But trust me, it will be incrementally more challenging and will introduce this object oriented idea of using classes. Okay, take care. We'll see later