Python Game Development using Pygame and Python 3 | Attreya Bhatt | Skillshare

Python Game Development using Pygame and Python 3

Attreya Bhatt, Developer

Python Game Development using Pygame and Python 3

Attreya Bhatt, Developer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
17 Lessons (2h 15m)
    • 1. Installation

    • 2. Creating your first game window

    • 3. Title Logo Color

    • 4. Adding an Image

    • 5. Movement and Motion of Graphics

    • 6. Interacting with our game using Keyboard

    • 7. Boundaries and Bounds

    • 8. Creating the Enemy

    • 9. Enemy Movements

    • 10. Adding a Background to our Game

    • 11. Shooting Bullets

    • 12. Shooting Multiple Bullets

    • 13. Collision Detection

    • 14. Creating Multiple Enemies for our Player

    • 15. Displaying Score

    • 16. Adding sounds

    • 17. Game over

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

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

In this course, we will be learning about game development using the Pygame library of Python. We will start with very basics. Such as creating a game window and adding a image on it.

Then in the course we will go on to learn 

  1. Graphics and Input Controls
  2. Creating Motion and Movement in our Game
  3. Shooting Bullets
  4. Detecting Collision between objects
  5. Add sounds and background music to game

You will be able to create your own games by end of this 2 hour course.

Meet Your Teacher

Teacher Profile Image

Attreya Bhatt



When I was a kid I saw this YouTube video on how to make a folder invisible on Windows. I have never looked back since then. My love for technology has only grown.

I started with security since that was one of the areas that fascinated me. Then i went on to win the award for designing using Photoshop at Cofas '2012. On the destructive side, I always made scripts that used to mess up the systems at my school. I was almost suspended. I learned my lesson and vowed to do only constructive things. To make people aware of security issues, along with 2 friends started a Facebook page and group called YAP

To make things more interesting Web development came into my life which helped me get into the most prestigious chapter at my college IEEE. This helped me master different things... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
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.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

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. Installation: All right, guys, welcome to the spite on game development. Video Siris on. We'll be using the famous spy game library off, Fight on to create the school space and really game on. We're going to go really in depth into the spy game and learn about a lot of different concepts on specifically, we'll be learning a lot about, like, new parts off pipe on that. You haven't exploded on new parts off by game, like moving characters, shooting bullets and standing game concepts like game loops and stuff like that. So if you haven't ever created a game or you have only created a very basic game, this would be a very good starting point for you guys. So before we get started on all of that cool stuff, learning about game, the Le Pen and stuff like that, you should make sure that the basic stuff is in start. So first basic stuff is obviously by Toronto. If by phone is Norden story, if you're using, fight on for the first time, just goto fight on door or and then click on downloads and just download the leader dispersion off. Fight on after downloading fight on. We are going to be using i e. Which is basically a cooler way to write code off, Fight on. So I'm going to using by Chomp on if you don't want to buy the professional version, although you have a 30 day trial, which you can use for this course. But if you don't want to buy it, just download the community was in, which is free, and you won't need more than the community was in. But if you're using something like sublime text or maybe the mean fight on terminal, that's also fine. It won't matter. But if you want to follow along completely, make sure that you don't buy charm. And totally you can just have a look at the game website that you're going to be using to create our game so you can just have a look at it. It's not really necessary, but you just have a look at what has been done with this by game on. Look at the games, maybe, and, you know, just kind of get ideas. So let's get started. Make sure that you have downloaded by jump after you have downloaded by jump. It will look somewhat like this. Now that we have everything installed, we need to make sure that we have this new project over here. So for that, just go to file, click on New Project on, then ride down the project name over here. I want to be created the project, and I'm calling it space in reader because it's the game that will be creating on Probably have already played this game when you were a child, but the main idea is that there's a ship at the bottom. I'm going to hit the enemies that are on the dog by shooting a bullet, and every time you hit the enemy, your point increases and the enemy slowly come down. If it touches the spaceship, you lose on the final score is what comedy and muse you have shot. So that's the basic idea off the game. But you'll understand mood as you go through the videos. So after you have created this project, we are going to create a new file over here, and rest can call it main because most of her court is going to go inside this mean God fight on five, and after that, we need to install by game. So if you're using terminal, you can just open up your terminal by typing in CMD and you get a statement pip install by game. And this is for people who are not using by chump or you're using something else likes to blame, takes or fight on terminal. But if you're using by Chum Ward, you would do is you would goto file and then you would go to settings on in settings. You would goto project name the whatever name you have given if wanna follow along, called Space and read up and then go to Project onto Britto and what there you can see have already installed by game. And if this, by giving, is not already in story, just go to this plus sign over here on Search for my Game by game, and then you can select it and click on Install package, and this will install by game onto your computer. Now already installed by games. I'm not gonna install it again, and after that you can just type in by import by game on. If this doesn't show on whether that means that my game is installed on your computer so this is pretty much it. This was a pretty small video, just an introduction video. If they're going to be doing other cool stuff from the next we do, we are going to be creating our team. We are not going to go into a jury and stuff here that's going to start with practical stuff on actually start creating a game. So we're going to be creating a game window next time. So, as you can see, the spike has a window right now. So we're going to be creating this kind off a window in the next video with the cross button over here, so I'll see you over there. 2. Creating your first game window: all right, guys will come back. And just to recap, you were treated in the last media. What installed by game. And in this video, we are going to be creating our first bite on game window using hiking. So obviously the first thing we need to do is import by game into our program and hopefully have already created this means or my file. If you haven't just created right now on first of all, getting to import by game. And then we need to initialize fighting toe access, all of the code methods and all of the other stuff that is inside the spy game. More deal. So to initial eight this I gave more deal. What we need to do it just type in my game dot in it. So when you go from no one who create a game or create a new game, just make sure you act the slain. Otherwise, your fight on my game court is not going to work. So let me just act a little bit of coming over here saying initialize my game, all right, so after initialization we have to create our screen on my game, makes it really really easy. It's just one line of code. It's crazy. So it is going to ride screen on this is are available on we can just right by game on. This is to access the methods that are inside this by Morgan on needle ancestor display dot said more matured. And then inside these brackets, we need to add another bracket. So this is a pupil. Make sure you act in the bracket inside it. Otherwise, it's not going to work on our people. Mess up over here and then ask why they're not working is because you haven't 100 another bracket over here and then inside it is gonna take a Duke values the height and a bit off the window that you want to create. So I'm just gonna give it for no no value off 800 pixels off height and 600 pixels off it. So this should be good. And let me this comment create the screen on Let me just for my just probably so this is all you need to create a screen, but as you'll see after we run this program that it has won me back. Think about it so as you can see the game window was created. But after a few seconds is just went away. Let me show it to you guys again so quickly Complete stays there for, like, one or two second. Then it goes away on. This is because our fighting program goes through these three lines and then just exits the program. And therefore, you can't see that screen for a long time because it just takes one or two seconds for this program run, and that's it. So when we do bypass, that is just create an infinite loop over here on this also has problems. But just to show you guys that it works, I'm gonna do it. And I'm gonna make sure that my task managers open because this will hang my computer. So make sure that your past managers are open because this will Hank the window, at least that you're working on. But just to show you guys, I'm gonna run this and you will receive that the window is dead, but it is totally hand so you can see the window is there. But it's nothing is walking over here on this Crawford and it's not working. Let me just go back over here in close my my window, Click on and Task, and it has been closed. Now why is it hanging? Why did not just closing down by pressing this cross? But it is because we don't have an event off a quick function over. Yeah, there's no we do quit the program. Our program is just inside this. If I look on snow able to end on windows, make sure that that program gets hung. That's why we need toe adequate functionality to our game. We know, just like this window has on pressing disclosed, but in this window closes. So for that, we're going to be using something known as Erin's. No, we'll get into evidence more a little bit later, but for, you know, just understand that even is anything that is happening inside. Yogi Brendle, My game window. I just mean a window inside which your game is being played. So anything happening inside that game window is basically even so. For example, if you press arrow keys or anything on your keyboard, you move your mouse. That is an event I'm even when you press this close button. That is also on event in again. So this pressing off the clues but actually known as a quid, even in again. So we're gonna make sure that we exit this loop when this close button expressed so far that what we're gonna do ESPIRIT is gonna create very bill. Let's call it running on. We're gonna get a value off true on inside this by Lupita instead of just having invited True to make it an infinite loop. Pearson call it running. And you know we want to break outside of this infinite loop. You're just gonna turn the variable off running into false on its will automatically break this by Liu. So if you don't know the basics of fight on our programming basically vile through grants infinitely. And when this value off truest Toronto falls, it comes out on the loo. But we're not gonna go into much into that because that's just like very basic programming . Anyways, after writing by running, what we need to do is go through the list off events that are happening inside that window . So for that, we're gonna create a for loop and create available event on. Then we're gonna look through all of the events that are happening inside our game window. How do you do that by game? Makes it really easy. Just typing by game. Don't even don't get and the brackets on this make sure that all of the events that are there that are happening getting so this I game not even dark get and then we can loop all off these events using the for loop on one by one. Check if this cross button has been pressed on women with this cross, but it is being pressed you just doing this by Lou into false. So this is pretty easy. So inside this fluttering chick, if the close button has been pressed and how you do that, just aping if even dot type equals equals two and then we're gonna check whether the event in my game is quit or not. If it's great, then we're gonna change the value off running into faults. This is pretty easy. So we have changed our value off through into force. Whenever the close button is being pressed on this close burden is basically occurred. Event on. We're gonna look through all of the events to find this quit Even so, we're gonna go into mourning to events a little bit later. But for right now, just understand. This is what we are doing. Lists display this, understand? But it's working or not. Let's see. So right now you can see that video system is not initialize. It's giving us on better. It's a spy game. Don't even don't get all right to The problem is that we have misspelled this. It's not my game dot small letters Quit is just my game dot quick and has pretty much it. So when you were dealing with a lot of syntax, you have to make sure that your current one but small problem there's gonna click on play. And now you can see that this is working on our window is not going anywhere. That computer is not hanging. It's looking pretty good. Alright, guys, let me just go through this once more what we are doing over here. So we have created a screen. We have initialize are my game on. Then over here we have created a game loop. Let's actually call it the game. Look about here. We're gonna add a comment that say's came loop so This is an infinite loop, which makes sure that the game it's running always and the window doesn't close down on. You know, we want to do something like move a bullet or move a play or something like that movie human being inside a window. We have to make sure that we do stuff inside this by Infinite Loop, which only exists when disclose Button is pressed on. We have implemented that close functionality over here by pressing by getting the events, all of the events using this by game got it, went, don't get mattered. And then we're looping through all of the events. So if more events are added, for example, if somebody places and I took you to move forward, that is also going to be looped. And thus I game got urine dark loop, and then we can add under condition that if he is pressed, move that player. But more of that in the future, for I know this understand? We looked at if it went door type because to him quit. Let me change the running into falls to make sure that we come on this way. Look and I know guys, I'm revealing a lot of stuff right now, but this is like the B six off game developments. I want to make sure that you guys understand properly. Anyways, Guys is pretty much it for this video In the next video. We are going to change the idle and at some stuff into our game window. So and we look forward to that. So right now it's just black and it's just saying I get window. It's not good, so we're going to look into that in the next video and see you over there. 3. Title Logo Color: All right, guys will come back. So in the last video, we learn how to create this game window using my game. So this window is a little bit not personalized because it saves by giving over here. The background is weird. The lower is not dead. So in this video, we are going to be learning or three main things. So first thing is how to change the caption off this window instead of my game window. We'll make it something saying something like space and radios. We're going to learn how to change the logo off this window. Right now, it's like a sneak on a total or something like that on how to change the background color off this window. Now, these three things are very basic, but obviously very important when you're creating again. So let's get started on that. On first thing we're gonna do is obviously just coming died so that you guys can come back to the school on Look what's happening. So we're going to write a comment title, and I can. And after that, we're gonna change the caption or the title off window, and my game makes it very, very easy. You just writing by game don't display because we had meddling with the display off our windows. We have to write and don't display And then dot said underscored caption, and then it requires the title of the window. Little just call it space in readers because that is what we are created. And then we're going to create the image. So you must have been seeing this year four dot PNG image Over here, we are going to be using this image and just the thing, and I'm gonna show you how you can get this image. But before that, let me just add this icon inside our program so far that this is also very easy. First of all, what you can do if you want to get the same image, is that you can goto this That site known as flat I couldn't dot com on then search for spaceships on any kind off Aiken. So I have sourced for spaceship and anger disc You'd ufo Aiken. So download this. You can just click on download collection on make sure that you select PNG and then 32 by 32 big cell sites. So whenever you're working with an ICANN and by game, make sure you select that 32 into 22. I haven't experimented with 24 or 16 pictures. It might work, but I'm just gonna go over 32 in 32 pixels. You can select any other I can if you want. So I selected this. I can, and I just downloaded it into my project. On here is you and four Don't P and G No, Add this inside our fight on a program. It's pretty easy. You just type in. I go on equals to buy game dot image because you are using an image. So we're going to be using the image, Mondial added Inside, by game on, then dot Lord, we want image to Lord and then we just write the name of the image. So in my case, it's you have four dot p and G. So you and I use that you have four dogs, PNG, and then the next line is pretty simple. We are going to use the same dot display that we did with the title and he was gonna write that over here and then just said it's not showing but I think it's safe underscore I can, so you can use that. And then you just type in the very believe off I can over here that we have created, and this will make sure that the ICANN has, Bean added. So let's just run this on, see if it's working or not. So, as you can see, the Aiken is also working on the space in readers. Is this so this is looking pretty good. We have learned how to add an image. Not exactly an image just off Aiken over here and change the title off window. So this is looking pretty good. The 30 minute to learn is how to change the look or the background off window. So for that, we need to do something known as screen Don't fill. So we're gonna go inside our while running loop, and over here we're gonna write scream so anything that you want to be persistent insider game window, that you want to make sure that appears continuously, it can be an image, or it can be some text. It has to go inside this running infinite while you That is why we are going to change the color inside this running in tonight by new. So we're under state screen. Don't fill on them inside this, you're gonna create a pupil. Make sure you act under bracket inside it. So there are two brackets and then you give it three values off RGB. So we're gonna give it. I'm gonna explain what RG is in just a second. I'm gonna give it a value of 000 right now. Joe, Just to understand this RGB means is red, green, blue on. Basically every color in this world is made up off these three values. On one more you can see a pacer t, but let's not go into that. So RGB basically stands for red, green and blue on. This is the value. These are three values that you can use toe basically implement any color on the screen. So this make sure on this value goes from 0 to 2 55 so you can make it to 55 but not more than that on you can use it in a combination. So they say we want just a pure red color. So we'll say that we want to 55 on green zero and blue zero. And similarly, if you just want a green color began, say 0 to 55 on blue zero. What if we wanted a light, light green color? We can lowered on this value to maybe playing 1 50 So this will be a lighter version off pure green. So this is how it works. Basically, Andi, just to show you guys are more diversion off RGB or what you can do with RGB if you haven't understood it properly, let's go to Google and you can just type in color toe rgb on go to any website. What? I'm just going to go to this vapid tables upside and over here you can see these are TV values. So obviously I told you, read is 2 55 00 Lime is 2 55 0 this Onda similarly and so on. So let's go with this right below right now on you can choose any values on. There are a lot more colors. You can even make your own colors by trying on different three values. So just experiment with it a little bit, so I'm gonna just use the red color. So we're gonna go back to our court and I'm going to write down to 55 but it is not going to work even though we had try it. But this is not gonna work, just telling you anyone, so you can see that it's not working in just a black screen. So over here, we need to use something new has update. So right now, our display is not updating. So that's why my gimp awaits a method known as display update to make sure that if we add anything inside our display window, it gives updated inside this while running blue. So before that, it's pretty easy. Just make sure that you add it after every game, so it's by game dot display. So that's just a display dot update, and that's it. So you have to add a couple of flames inside your by Eitan Game Court First Line is this innit line, and also you need to make a scream. But two lines that are always going to be there is this innit line on the the second line that's always going to be There is this update line because you want to update your screen because your players is going to meet with The bullets are very moving. Amy is going to move. Moving the score is going to be changing. So you want to make sure that your display is always updating on by display. I just mean the game window that we are working on for this program. It means this screen very been so anyways. So now we have obliterated less, given a short let's click on play. And as you can see now, it's in color. Looks good. We have changed the title. We have changed the logo and our screen is updating red. I don't like red. I just wanted to show you guys that you can change the color and maybe we'll change. Do something a little bit more funky in the later videos. Right now, I'm just gonna go with Black, that 000 and that's pretty much it. So guys are seeing the next video where we are going to be finally adding images on our player that this may be a spaceship, some kind inside our game window on de. So I'll see you were there where we're going to learn how black images inside our game so 4. Adding an Image: All right, guys, welcome back. So the last video we learned how to add a caption on a logo on how to change the background screen off our game window. In this video, we are going to learn how to add an image to our game window, which is pretty cool on pretty easy because of figure. But first of all, let's look at the player PNG, which were going toe Add insider game window, which is kind of a spaceship, which is shooting beams sort of its arms. So if you want this image, you can just go toe flat. I couldn't dot com on download this image. Obviously, you can use any other image you want, but I'm just going to stick with this image on You can go to download collection and also the search for our kids space over here. If you want this exact image and then choose PNG, choose that 64 by 64 picks it Obviously you can't decides it and by game, but I have seen that it's better if you already get the image of the science that you want . In this case, I wanted sex Table 64 by 64 pixel version. So I'm gonna take that. And I wanted he added it to my project or here after you have done that over here, then you can come back and we can start adding the image. But before we even start that, I just want to discuss What is this? 806 100 I have here. I wanted to discuss this, but this 800 is the weight on the 600 is the height. I think I might have said something wrong about this in the starting videos. This eternity is actually the wit and not the height. And the 600 is the height. So if you look at our window, this is the X axis. You can think off this window as an X and Y axes window. So if you go from left to right, this is an X axis. And if you could go from top to bottom, this is a wide access. So it's always starts from zero comma zero, which is on the top left corner, and then we as we go on the right hand side, the X value starts to increase on on this top right going on. The X value is 800 because that's time. So what? And now if you go from top to bottom, the value off by increases while the explanatory means to seem so over here, the value is 600 but the value off X zero. So if you don't understand it a lot, don't worry about it. Just think off it as this left left to right is basically X on the value. Right now, off this whole window is 800 in terms off. Its wit on the value from top to bottom is 600 on the value at the bottom is 600. And if you want to go into into the middle, it's approximately 300 not approximately exactly 300. So I'm telling you this because we want to place our image in a particular position. So that's why we need to give it its that coordinates. Obviously, you can experiment with Garden. It's a little bit, but we'll go into it. So let me just add a comment over here so that we know that we're talking about the player and then we need to add the player image, which is pretty easy, like we have done it in the dumps of the local. Let's just copy and paste this over here on change the UFO to play a dark P and G and then we're going to give it the X and Y access where we want the image. Toby Coalition. Let's create more very birth. Let's call display X on. We're gonna give it the value off. 3 70 on. I'm going to go into why we give these values to Player X simply away. So these were it builds basically a presence of cartoonist that we want. And over this we're going to give the vital value off for 80. So why have you done that? So if you look at this window, we want a clearer image to appear somewhere over here, which is exactly the half off the screen. So we wanted to appear at the starting off the game. At least we wanted to appear in the middle on. We wanted to appear in the lower half off this window, so the Y axis should be closer to 600 because this point is 600. If you guys remember this law art So you wanted to appear a little bit about what? So we can give it a value of about 4 80 or for 50 whatever you guys want. And then the X value, giving it 3 70 which is a little bit half less than half off the grid. So the weight is 800. And if you go a little bit less than this, this is 3 70 because we have to consider the size off the image itself. If you give it exactly the value off 400 snorkel defict perfectly. That's why we have given these values so you can see that the 3 70 is somewhat half off, 800 on Disparity is close to 600. Obviously, when we change the values, you understand this concept better and feel free to change these values and see the effect it has Now, after this bill is going to create our function and we're gonna call it Blue, I'm gonna go into why we are creating a function by Let's just get a function for now and then we're going to use a matter Nunes cream dot bleidt. So it basically means to draw, So we're drawing on image off player on our screen on this screen is actually known as the surface off Give we go into what it is. It's office, which later I No, I'm saying that a lot, but it's not living to this video. But just understand that we're drawing this image off clear, dark PNG on on game window by using this method known as thought, blip on dot blade blade actually means to draw, so we after learning the image, you also need to draw it on the screen. But that's why we're using the screen door lead mattered on over here. It requires two para mitos our values. The flip first value is off the image itself. So we're gonna give it the image and the seconding it requires are the coordinates. So we're gonna give it the cardinals off player X and clear white. So the X and Y coordinates after this, we're going to call it. I'm just gonna ask you a question. Where do you think we should call this place? He wanted this player toe appear in every frame off the screen. We don't ever want this player to disappear. If you guys said inside this my loop. You guys are correct. So we're gonna call this player method inside over here, so let's just call it on. We're gonna just call it over here like this on. Make sure that display emitter discord after this cream dot film, 1/3 of the ways this player wound appear on the screen. My do you think that is? This is because the screen is drawn first and then on top of the screen, we draw a player or a spaceship. If the opposite waas to then the spaceship would be drawn underneath, Just get the screen, not the skin. But then it would be drawn underneath the screen. So that is why we always want it to be drawn after screen dot fill. Actually, let's change. Let's remove this position toe from there to over here somewhere so that we guys know where this So because we are going to be adding a lot off images and stop. That's why we need to make sure that this screen Dark Phil is just about everything on all the other things. I'm drawn on top of the screen. Alright, guys. So this is pretty much let me just add under comment. I don't know where he disappeared. The standard for RGB 100 a green blue Just to make sure that you guys, it's still remember what this is? All right, so this is looking pretty good on a player should appear on the screen, So let's run it on. Then we just go through all of this stuff again to see what is happening, all right, So as you can see, our image has appeared on the street. So first we loaded the image in display, an image available, he pointed out, the X and Y values and the X and Y values were dependent on the screen size that we give over here. 806 100 because he wanted it to appear in the liquid. Disclosed this one, the old one all right on because he wanted it to appear in the middle. That is why we gave it the value of approximately half off the screen. For example, if I gave it the value off, let's say just to experiment, let's say we give it the value off. Let's a 7 50 that is close to write and say we re loaded it on Let's with you can see it appeared on the right inside. You can see that the X value has increased. And similarly, if we decrease the toe, let's about 30. I'm just showing you this Duke guy so that you guys can understand the X and Y positions. Clearly, you can see that it appears on the left hand side. So lets you do back to about 3 70 on similarly, and why, If he changes to maybe 30 you will see that it appears on top of this cream instead of the bottom of the screen. So as we get go down, we are getting closer to that 600 value. So we're going from 0 to 600. So let's bring it back to four. Ready and hoping. Now you guys have understood probably the meaning on this X and y axes. So anyways, after that, we created this function known as earlier on in Scrape that we do this so image onto the screen and it required to and use the image Tex and Y coordinates on. Then, to make sure that display here is always shown on the screen, we added it to this wild game loop in finance flu. So there's this is pretty much it for this video. A mind repeating a lot of things a lot of times that my real illiterate irritating for some guys. But hopefully you guys understood it properly. In the next week, we're going to learn how to move this. So blow from left inside, right inside, using our arrow keys on a keyboard. That's going to be really exciting. Let's wait for that. So I see the next video. 5. Movement and Motion of Graphics: Oh, right, guys, welcome back. In the last week, we learned how to add an image inside our game window. And this we do. We are going to learn how to move this image left side, our top or bottom. So basically, we're concerned about the movement. Often object inside on game window or anything that we draw. It can be image. It can be on text. After you watch the video, you'll understand how the mechanics off movement in a game works. So just to make sure that you guys understand it, I've created an image so that you guys can understand what we are going to do it on the basics off, movement, off on image or anything that you want. So obviously we have created a game window. This is our game window. It is 800 white, that is 800 X axis and then it's 600 is height, that is, You can see it. This as by access on our special currently is at 3 30 pixels, as we have. I did this over here. That is a player excess at 3 70 pictures. If you go back to image, what if we wanted this image to move from over here. Toe here began. This are five pixels towards already existing 3 70 pixels on this image will move in the right hand direction on now. What if we added five pixels continuously? So this five pixel, If we are continuously, this image will continue to move towards the right hand side. So, for example, we can add a functionality which adds five pixels to our existing 3 70 pixels in a while. Loop something off of I look on. This will happen continuously after every iteration off our new. Similarly, if you want to move it to the left hand side, we can just decrease some value from a 3 70 pixel value that does. We can decrease some X player X value and will move towards the left hand side. And similarly, if you want to move up, we can subtract some my values. So currently the y value off this is for 80. So if you subtract some value from this for 80 it will move towards up direction. And if we add some value if we move in their downward direction, so adding and subtracting values from X and Y coordinates off a current position off the object or, in this case, patient can lead to a movement off that object on. You have tow added toe a while loop because we wanted to happen continuously. So if you go back to our court, we need to add one thing before I can show you guys how we can add values to our player X and player by. Are we hoping and subtracted? So before that, we need to make some changes because currently, there is no way to manipulate the X and Y coordinates from our while running blue on. If you didn't understand what I meant by this over here, don't worry about it. When we actually the court, you understand what is happening and what I mean by increasing the X value to move towards that, I can direction. Basically, if you move it very, very quickly, it won't seem that the image is moving. It will just seem like that the spaceship is continuously moving because off the effect off persistence and I can't see things that are happening very, very quickly. Like magicians do the decree delusions by moving things real quickly on the persistence and I'd Elsa's. That image hasn't bean raised and then created over here. It just assumes that image has moved on the NYT hand direction f You're adding the five value to our already existing X coordinate. Anyways, we need to do something so that we can manipulate the value off Clear X and Clearwire from the running by Lou. So what we can do is go to this death player function and over here at X comma Why? So that we can send in the values off the new X and by cordons that we want and then insula player X and we arrive in just on x and y so that the values that we sent to this player instead off the the last values that it got from Player X and their white instead of that the new values that we send in off X and Y are being shown on the screen or being drawn on the screen. So now we have to go back to the place where we're calling this functions over here right now. Let's just writing player X and player by, and you will see that there has been no change. So let me just exit this first and then play it again. Let's play it. So you see that there has been no change because you're not manipulating the player X and player by you right now. So let's go through this once as to what's happening over here. So first it goes to escort it creates the spaceship, then takes the coordinates off the X and Y off the player of the spaceship on. Then there is this player exchange. Let me remove this right now. We don't need it. And then if we go down, we have created this function off the player X com away on. Then this is being drawn on the screen. So this court hasn't been executed yet because it is inside this one vial turning blue. But the program just sees that this exist when we go down over here than this player thing is called and it takes the player X and player by value from hell on sends it to this death player function and inside x and y Currently the 3 74 80 exists So this image is being drawn. Actus coordinate. What if we change the value insider buying turning function. So, for example, let's say we increase the value off player X by something small. This let's let's increase continuously by five. So this will move really, really quickly and you won't be able to see the image moving doors right hand side. But I just want to show it to you guys for the speed so you can see how quickly moved. I hope you got it just a slow down and is gonna give it the value of 0.1 so that you guys can see properly and you'll see that it is moving in the right hand side direction slowly. So where is this happening? So every time this vile group is running, the player X coordinate increased by 0.1 on this, valueless said over here in this function player function on. Then it is sent to this nuclear function on the new image is basically drawn on. A new coordinate on the original image is being removed. So what example? Let's also just let's make it 0.2. And this time we're also going to print out the value off Player X so that you guys can see that the player X value is increasing from our rotation value. So here you can see that being increased by 0.1 and it's going on. Let's stop it right now on. Let's actually try it to move it in the left hand on left hand side direction. So let's give it a minus value of 0.1. So now we want to decrease the value. So instead of increasing the value, we want to decrease the value and move towards the left hand side. So let's play it again this time on. Hopefully, let's just removed the play up the print function because we don't need it. So now let's played and you can see it's moving toward the left hand. Say similarly, if we do instead of the X coordinate, we do, the Y coordinate and decrease its value is gonna goto us the up collections. Let's reload it and you will be able to see that it's moving. Tow us the up direction and similarly, if the AG stock it was going to go down So hopefully you guys understood the mechanics off a movement often object just to reiterate why this movement happening by is when when we're decreasing the value and why it's going up. So because at the bottom, the value off by coordinate six hundreds if you decrease the value it was going up. So over here it's about for 80. And if we decrees it more, it's gonna goto us direction. And similarly, if increasing go, go below more than 600 coordinates. So right now, you can see there are some some fallacies with this system. Right now, we can't control where this is going on and you really see that just goes outside the screen. So we need to do a couple of things first. We need to make sure that we can control this movement off the spaceship in the left and the right and direction using a arrow keys on the keyboard on. A second thing you need to do is add a boundary so that the spaceship doesn't go beyond our game with the right nights just disappearing by going outside the game window. So we'll be handling these two things in the next under coming videos and then actually, we're going to learn how toe add keyboard support to our game. So basically we are going to control our spaceship using arrow keys. And that's when we really exciting. So answer you in the next video. This is pretty much it for this. 6. Interacting with our game using Keyboard: All right, guys. We come back in the last week, we learned about the movement mechanics off the objects in our game window. So, for example, if you do player very close to minus equals 0.1, then it will move in the direction. So if I run, this man you can see that are spacious is moving in upward direction. But right now, we don't have any way to control the spaceship. You can't control it using our keyboard. And this is exactly what we'll be learning in spirit. So what we'll be doing is that many places left arrow key on a keyboard. The spaceship is going to move to us the left hand side. And when we pressed the right inside a rookie, then a spaceship is going to move on the rest tonight and say so what is the algorithm to do that? So, first of all, we are going to check whether any stroke is being pressed on our keyboard on after we checked that we're gonna check with acute stroke breast is either left hand side, arrow key or the right hand side Iraqi. So we're gonna do that. So let me just write down and if condition, let me just remove this over here. We don't need it. So after that, um, let me just tell you one more thing. So any keystroke that is pressed on a keyboard is actually, And it went on, as we have discussed before, that event is anything that is happening. Insider game, window, any kind of input control. So, for example, if we move on Mama's, we click somewhere. We close this window. So this is a great event, and similarly, whenever we press any key stroke on keyboard, it is a key stroke. Even so, for example, every even gets locked inside this by game, not even don't get on me loop through all the events that are being stored inside it on, then after every interrogation. So, for example, let's say in the first iteration off this by loop are keystroke is not being placed, but on a tent, a creation, a keystroke is being pressed and will get stored inside the spy game, got even, don't get and will be able to look through that on check. Whether a keystroke has bean placed or not. Who's inside this? I'm just going to write an if condition, which say's actually before that. Let me just come in so that you guys understand what we are doing. I'm gonna write if, uh, keystroke key stroke expressed chick with the is right or left. So this is basically what we'll be doing. Donkey stroke a keystroke. Oh, God. I'm gonna miss of my spilling. All right, keystroke. I get this feeling right. It's all right. So, anyway, is how do you check with their keystroke Is being pressed or not by game makes it really, really easy. It's kind of an event, which is my game dot g down. So this basically check if any keystroke, it doesn't have to be left or the right. It can be alphabet, a even backspace or space. It basically checks if any keystroke is being pressed. So first we're gonna do that. We're not right. If he went door type, which we did inside this if condition. So we have to go actually, inside this for loop. So you just press this button away here less prestigious. So now you're inside this event for Luke, and now we're looking through all the events that are there, and if the event dot type is equals equals to buy him dot key key down. Then this means that a keystroke has impressed on a computer. And now we have to check whether the keystroke that what's pressed is left or right, So this is also pretty easy. We just again type event dot This time we type in dark key because you want to find out the key that is repressed. And we just type in my game dot He left. We left on this will just check whether the key that is being pressed is the left arrow or not. If that is the left eye releases for right now, Brenda left at all is pressed. After that, I'm going to write again. I'm just gonna copy and pieces over here like this. Andi, over here. That's going right, right. And instead, off k underscore left. I'm gonna act the right. All right. So basically what this does is it checks with any case stroke is pressed, and then it checks whether the keystroke that is being pressed is left or right after that , we're gonna check when the keystroke is being released. After pressing down on the left arrow key when we remove our finger from the left arrow key that is known as the removal of the key stroke or the key up so cute down is pressing that key or pressing any button on the keyboard and key up is basically releasing that breast. So we're gonna check for that over here. If you meant dart type equals equals two pi game dot key up. So hopefully we'll be able to find that key up for him. And then we're here. We're just gonna check if it was the lefty on the right arrow key, and then we're gonna print something, so that is pretty simple. We can just copy too strong here that's copied this base this on. We're gonna give a condition that if the left or the right arrow key was pressed breaking just copied this from him on put the school in mark. And then over here, over here, just going right. Keystroke has bean released just to you. So you guys know what is going on on? I want you do like this, go down and then actually tried out yourself so that you guys know what's happening behind the scenes So now we can just press on play and over here is gonna do nothing but on our Prince King. Over here, we're printing all of these things. So let's press the left arrow key and see if something happened. So we have to First we are window over here and then we can press the left arrow key and you can see that the left arrow is pressed on when I remove my finger. It says keystroke has been released. What if I keep pressing on the left Iraqi? If I keep pressing, it will just say left out of this place and the keystroke has been released. And similarly, if I press the right arrow key, it states right Arrow expressed. But if I press any other key, it prints nothing. So let's actually bring a statement over here. Do let's say, a keystroke expressed so that we know when any other key expressed it also runs. So what? Here began. Just rest left Iraqi again. As you can see, a keystroke express left arrow keys pressed hankie stroke has been released, But if you play something else, let's say Endo. It just says a keystroke is pressed and not the left on the night. Archy on. That means that a keyboard strokes are working. So now we can just minimize it, and we're going to create a new very below. Here on this will signify the change that we want an egg. So if you want the eggs to move in right direction, we need to add value to this 3 70 existing. Manu And we wanted to move on the left hand side direction. We need to decrease its value from it. So I'm gonna just call it over here, create a new available and call it player X underscore. Change equals two. And right now I'm gonna give it value off. Zero on inside our if conditions. When the left key is pressed, I want it to increase by 0.1 on when Sorry, decreased by 0.1 on. We can change the cedar 0.1 number. It basically signifying the speed with which you born the object Move in this case, the spaceship. How quickly want a spaceship to move and we're gonna change it later on. Even in this video, we'll see how it goes if it moves too slowly or too fast. But New Year's right now, we're gonna decrease the value when the lefties place and increase the value in the right key expressed. So what kind of change do we want in our ex when we want the left arrow key expressed? So we're gonna just right over here Player X, and this could change. And we want to increase the value by 0.1. Let's say on when the right arrow key is pressed, we want to increase this change by to your 0.1. So let's remove this minus value from where, here and when. The key is At least we want a spaceship to stop moving. And that is a morning change, Toby. Zero. When are keystroke? It's policed. So we're here. We're gonna pieces over here, so this is looking pretty good. Let's actually remove this comment from here on. But then we can just add this player exchange to our existing player X X coordinate. So I'm just gonna right there. X plus equals two on Blair exchange. So it doesn't matter whether we're adding over here because we have genital value off minus 0.1 on or he'll be giving it a positive values available. Something is added on. The value is negative. So I'm just gonna give you example, all right, so that you guys can and standards arithmetic properly. You might be thinking that way. I think we're here because we want to subtract 0.1, right? So let's say a current value is 3 70 Let's say, Actually, take a smaller let's take at Player X coordinators five. And then when we do plus, uh, equal roots of this basically means equals 25 plus and then the value that is playing excellent school change. So right now, this value is minor 0.1. If the K left is operated, so this value will be actually minus 0.1. So after this automatic is processed this way, don't actually do so. Let me just a rookie. This will actually turn into find goes to five minus 0.1. And similarly, if the ad the addition is pretty or pretty Blake obvious. So we can just add 0.1 and this will remain the same just 0.1, and the value will be 5.1. So this is how this operate over here books, so we don't need to worry about whether we are subtracting order, adding, If we have added our arithmetic operator over here in this case, it's mines. So this should be working. Let's run our main door by a file and see if it is working. So let's actuate it on over here when you press the left. Araki, our ship is moving on. When we press the right arrow key, our ship is moving and we when we released the key stroke, it is still moving by this type of case. So let's go over here and see. All right, so here the play extra, let's go change 0.1. So the aptitude here to value zero because we don't want to move, you get actually 10 to 0.1 to see how it works, how the spaceship is stopping. So let's try it again. Now, when you move in the right direction and we relieve the keystroke, the ship actually stops. So this is looking pretty good by the sleek. The speed is a little bit slow, so I'm gonna increase the value to 0.3. And now if you don't end speech should be sufficiently well. So this is looking pretty good and future. We'll change. 0.3 toe are higher value, been used, the clock concept but we're not using it right now. So this is looking pretty good. Spaceship is moving perfectly. And just to the cab operated in this video was first. We checked whether any keystroke has impressed on the keyboard. And then if the left keystroke is pressed than the increase or decrease the value of player exchanged by 0.3 on if Ira right case president increase the value by 0.3 and when we are keystroke has been released, we make sure that the player X coordinate stops changing. And that is why we have given in the value of zero to make sure that the spaceship stops under the go on. And then we just use this arithmetic thing over here which increases the value off player Extra Decreases the value off player X depending upon the value off this player. X underscore. Change Eso this guys is looking pretty good in the next year. If you have any creatives, please ask them and questions. So this very logic for this video in the next video, we are gonna give our spaceship and enemy because recognized the space. It's looking very lonely for a spaceship. It's just going up in the space, and it's not finding any planets or any enemies. So it's thinking about this existence and the meaning oflife. What's happening with me? So we're gonna give it a meaning in the next video, so and see you. 7. Boundaries and Bounds: all right, guys will come back. And the last we do, we learn how to move our spaceship using our keyboard and the left and the right hand side direction on this we do. I was about to give it some enemies, but then I realized our spaceship is just moving out off the stream when you go to the left and then we go to the right. So why is this happening? So then it goes to the right, this train border off the spaceship off guardian window. It actually reaches the 800 wit that we have said. And when it goes beyond this 800 it goes to maybe turn it then and 805 pixels. So this no restriction right now to the spaceship movement in the left and the right hand side direction and similar leaving it moves to left. Inside it goes, Albert, lesser than zero Angers goes into minus territory because this extraordinary is an individual. This that's why it's can go toe negatives on even it can go to minus 4 50 or something. So what? What should we do? So what we are going to do is that when it teaches zero coordinate. Then we are going toe. Any time it goes into the gator stuff, we are gonna make sure that it stays at zero by using an F condition. So we're gonna basically tell our spaceship that Hey, if you're X coordinate reaches zero or less than zero, make sure it turns back to zero. And similarly, on the right hand side, we're gonna tell our spaceship. If you're X coordinate reaches this 800 x coordinate back then, I don't want you to go beyond it and change your X coordinate toe 800 again. Every time it goes beyond 800 it's gonna I just did itself and go back to 800. But it's gonna happen so quickly that the eyes won't see it. It looked like that the spaceship can't go beyond 800. So let's do that. That's right. An if condition just beyond this admitting operator we have over here on. As I said, we're gonna play an X. If this player X becomes less than zero, that is, the X coordinate becomes less than zero. Then we're gonna change the value of Player X 20 And similarly, if our left, right. And if and if Player X becomes greater than are equal toe 7 36 pixels. So why are we taking the same hit? 36 big cells instead of 800 pixels. So because our pixel, we have to take into consideration the size off our spaceship. So if you remember the PNG size off, this patient is 64 by 64 pixels. So the bit off this spaceship 64 pixels at this time of year, subtracting 64 from 800 on, that means 7 36 pixels. So if we chose any other number, for example, 800 they will stop at this point and not before that. But we wanted to stop over here and not allow any part of SpaceShipTwo appeal beyond the game window. So that's why we're choosing the 7 36 picks a number we just attracted 64 from 800 and we're just gonna change the value off whenever it goes beyond 7 36 We wanted to again go Santo Tobacco 7 36 x coordinate on this will mean that it will look that it cannot go beyond, which is actually, but it is deleting that spaceship and creating a new one at 7 36 x coordinate. Fix it. So let's check this out and hopefully it works. Well, let's reload it on the Steve. It works or not. So, as you can see when I press the right arrow key doesn't be on this on. Feel free to try it yourself and change the X coordinates. Just experiment with it a bit. The last beauty was pretty long, and this video is pretty short. So that's good. So the next video, we're finally able to create an enemy for a spaceship so and see you over there. 8. Creating the Enemy: all right, guys would come back. And the last video we learned how to create boundaries for spaceship so that it doesn't go out off bumps. And this video we're going to give it our first enemies already downloaded an enemy image which looks like a happy space in Rada. It's not gonna be so happy when we shoot it with a spaceship, But anyways, let's get this cycle from flat. I conduct calm just like we always have on search for Space and readers. And I'm going to go with this red space and reader. You can select whatever you want and download the 64 by 64 picture. As usual, I was in the PNG format, so now we can go back to our court. And just like we did with a player, we can add this enemy dark PNG inside our courts. Let's do that. Let's just copy this whole code on just added below the player changing to enemy. We're gonna change everything to enemy. So we just have to rename everything enemy. And then I was gonna copy and paste this in the remaining areas. So let's just copy and paste everything and instead off the player door. PNG. We're gonna call it the enemy dot PNG and make sure you re named the PNG file. Otherwise, you tried. If you read any Meador, PNG is not gonna work. But anyways, so we need all to create this function against the less just copy and paste stoop So basis over here instead of a player, we're gonna call it the enemy Andi. Everything else should come in the same. That's formatted. Probably anything is in Bytom if you want to format everything properly. If you have written good, that's not formatted and doesn't look good. What you can do is you can just press control old on l on. It will format everything properly inside your court, so it's just control and you can see it say's imports optimized. It will just make your court look good. So again, the commanders control plus old plus l on your keyboard. So anyways know that we have our function off the end. Me, Let's just go down below and add the enemy over here so that we can call the function while our my group is running. So let's add the enemy on my hair and instead off the player X legis. Call it enemy on instead of the player X. We're gonna call any me x on instead of player. Why you're gonna give it over and off and we buy so they know you can see that the coordinates are the same as on the spaceship. So this should overlap on spaceship. Let's see if it's overlapping or not so that no, it's not a lapping. Let's let's actually check out Why is that happening? So this is because inside the enemy function, we have not renamed this toe enemy dot AMG. So let's do that. Let's rename it any me dot image and then just reloaded on the should. Probably. So now you can see that the enemy is in top off special, but it is not we want. We want the enemy to be like somewhere on the top. So maybe in the middle, but on the top so we can let the enemy X remain the same. But I'm gonna change the and move I to something else. Elizabeth Value off 50 I wanted trying to note on 50 looks pretty good. So let's see how it looks. All right, so a special is moving and we have an enemy. But the problem with this enemy is that it's not moving. It's very boring. So we're gonna fix out in the next video. But for I know what I want is that this enemy should appear in the random places. So whenever we kill an enemy, it is going toe up your again or in the gimp tones is going to respond again. So I wanted to respond in different places, maybe on different x access. So maybe, like maybe over here over here, after it's killed on may be invited should also appear in different places. So maybe next time over here, next time over here. So you wanted to appear in different places every time it kilos. Basically, we wanted to appear in different places and even at the starting off the game and should not be constantly should we don't lead. And, um, So what we're gonna do is we're gonna make this any X and any me? Why, actually random. So we have to force right down the line. That actually helps us randomized values. So we are gonna important package known answer random. And it's pretty easy to do. So let me just minimize this over here and they're going down. And over here, we're just gonna write instead off 3 70 Yes, it's gonna write random dot brand. And so this is a method inside the random package to choose a random in teacher between two values, and then we have to give it the value that we want, so we want a starting value and value. So in our game, we want it to appear anywhere between zero on 800. So we're gonna give it the starting value of zero on the end value off 800 and similarly with why we wanted to give a value between maybe 50 and 1 50 So let's changes to 50 50. Should be the starting point. So the minimum height should be 50 and they can go down over here. That's a 1 50 It's approximately 1 50 So I'm gonna give it value off 1 50 from a reggae. So this is looking pretty good. Let's just run it again and see if it works. So let's run me. All right. So this is working it respond over here. Let's reload it to see if it responds somewhere else, let's just spilled it on. See where this time it appears this time it appears over here. Let's try that time. So time is a charm. Need always works at this time. It appears over here. So our program is looking pretty good. We have created on enemy on. It is this morning in different places. So this is just looking pretty good. The next week we are going to make sure that any moves. So right now, our enemy este Surely it's not moving from the left or the right on. It's not going down. So we are gonna make sure that we rectify that in the next video is gonna be really exciting. So I'll see you. What? 9. Enemy Movements: All right, guys will come back. So the last video we created our enemy and made sure we applied random ization to our enemy so that when it kids destroyed and created again, it should appear in random places. So, as you can see, when we deal with, a program is going to respond in a different place. So this would you were gonna make sure that our enemy is moving, So imagine that there are multiple enemies right now. They're just when one enemy and we haven't created multiple enemies. So there is not any problem. I would imagine there are multiple enemies and they're moving from left to right on there. Also, when they hit the boundary, they come a little bit down. So that's what we're refocusing under day. We're not going to be creating multiple enemies, but we are going to be focusing on the movement off this one single enemy, and then we can apply it to multiple enemies. But let's for right now just focus on one enemy. So what exactly do we want from this enemy? What kind of movement do we want? So what we wanted to do is move from right to left in X direction. So, for example, this and mean will move in the right hand side on when it hits the boundary that is about 7 36 or 800 pixels. It should change its direction and move towards the left hand side on very traces. The left hand side, that again minute hits that zero coordinated X coordinate that I should again changes direction and moved towards the right hand side. So this is the movement in the extra direction, not There is also a moment in the Y direction. So when it hits a boundary, but it can be right boundary or the left boundary, then it should come a little bit down. So that matter. There are multiple enemies and we're tryingto shoot all of those and meets town. So how will the game get over? So whenever these enemies hit the boundaries and come down at one point off time, they're going to hit the spaceship as they're coming down. And then we'll make it came who are like in the classic space and reader. So we need to execute the X movement and as well as we need to execute the Via movement. This always is going to be very easy because you already know how to move the spaceship, and they're going to do the same thing that we did in the player. So first of all, we'll just crawl up. Let's make meisters over here. So we're gonna slow up on because our enemy is going to have the exchange as well as a movement. So I'm just gonna copy this over here on. Also, make sure that we find movement no enemy exchange over here. We're gonna get the value of 0.3. Maybe in future, we'll speed it up because our spaceship is also active. Speed off on exchange off 0.3. Maybe we'll change it up on future. But right now I'm just gonna give it a value off 0.3. Now, I'm not giving it a values. For example, in player we haven't. We have just giving it a value of zero. We're here on below. Over here, we have changed its direction by typing in negative and positive. You're not gonna do this, but any media is gonna provide the value of 0.3 over here. No, If it's go along we're just gonna do the same thing that we did with our player. So for example, over here we made sure that if it hit the boundary So this is the algorithm. Basically, you can call it the algorithm, but it's pretty simple. So whenever it hits, zero coordinated, we change its value zero and minimal. It gets greater than since six. We make sure that it coordinates get to send 36 again. And this prevents the spaceship from going out off bombs. So this is a kind of way off checking the boundary so we can do the same thing with our enemy. So let me just copy and paste is over here on instead, off everywhere players, they're just gonna call it enemy. So you should be in a smart So we're here also. We just copy, actually, and me and piece it everywhere. There's gonna make sure that you save up some time, not a lot of time, but so let's face this enemy over here. I wish there was a quick way to do it, but it's not so any of these non, which is gonna add a commander where he off so that you guys can't understand what we are talking order with you. So checking boundaries off spaceship. So it it doesn't go out off bones. I know what you're weight is not right. Maybe enemy movement and movement on this looks pretty good. Instant off, restricting us. What we want is, whenever a boundary is hit, we want it to go someplace. So, for example, when it hits that left boundary, we want to increase the value off exist that it starts going in the right hand side direction. And similarly, when it hits the strike and signed boundary, the me one degrees, the value off eggs on this will keep on happening because it's inside are by. So now we're going to use the same arithmetic operation that we used with our players. So if he screws up a little bit, you can see when we wanted to change directions, we give. When he wanted to move towards the left, we gave it a value off minus. And when he wanted to move to us, the right, we give it a positive value off 0.3 and then we just ended because off this admitting property so we don't do the same thing over here. So instead of enemy X equals zero, what we're gonna do is we're gonna night and meet. Exchange equals 20.3 on so so that basically, when it hits this left inside, that is zero coordinate. It can start going towards a order of protection that it should start increasing the X value. And similarly, we want When we want it to go left hand side, we're gonna change it to R minus value. So we're gonna get the value off minus. And this should be enough guy. So and actually, if I screw up, you can see that report the value off enemy extender School change equals 0.3. We can leave it to zero or we can do 0.3. Doesn't really matter. So let's run it and see if it works. Let me just close down the previous implementation so that we don't get confused on understand it again. Run main and hopefully the and mean start moving so you can see that the enemy is moving from left hand side to right inside. Actually, this looks pretty awesome. So now you can see that it's not moving in the wind direction is just moving in the X direction. So what we want is that when it hits the right boundary, it should move downwards. And even if it hits the left, bond rates should move a little bit downward. So what I'm gonna do is I'm gonna go over here, I'm gonna add. And the right change equals 40 so that we can move it down by 40 pixels. So why, when do we wanted to move down? We wanted to move down. When it hits the boundary, that is the view. Coordinate Order seven thirties X coordinate. So in just increase the value off by over here on that should be enough. So I'm just gonna write in me Why plus equals do Onda. We want me by change. Just let it let's just based over here and then we can do the same thing over here. That's not it, is that it's just added over here. So now let's just be loaded on and see how it looks. Now you can see when it hits the boundary, it actually goes down so you can imagine multiple enemies when they're hitting the boundary . They are going down, so it's gonna be a little bit difficult for a spaceship to eliminate all off them. But it's going to try its best on Ben. This enemy teaches the spaceship. We're gonna give it our game over on, depending upon how many enemies we can hit with a bullet which will be creating mostly in the next video or in the coming up videos, depending on how many enemies he can eliminate With that bullet, the score is going to be according to that. So you can kind of get the idea off the game, that this video as to how the game was going to look, so that's pretty much it guys. 10. Adding a Background to our Game: Alright, guys, it's entree from building, I found, until they were going to be learning about adding background image to our game. Right now, if you open up a space invader game, you'll be able to see that we haven't and me. We haven't spaceship, but it's happening in the black background. It doesn't look that good. We need to add some kind of a space background to make it very cool. So what I'm gonna do is I'm only dollar an image off a background that is background or PNG and somewhat looks like this. So how did I get this image? So what it was having to the strip site for free pick dot com p i k and then free free pick dot com on I searched for this text with, say, its colorful spaceship back Trump. Obviously feel free to get an image from here and what you want, but make sure you get an image that's 800 into 600 pixels by that size, because our game window is that size, you can see we have made a game window off this area. So what I did was I went over there and you can choose any of these images. But the image that I chose was this one on. Then I used Illustrator so free because of website was gonna give you a lot of illustrator for the shop stuff, and you have to edit it out to make it your own. So I removed all of the beard stuff that we didn't want. For example, this rocket, this text and stuff. So I moved all of that stuff on. If you're no illustrator, feel free to make a new image on your own. So what I'm going to do for you guys, if you're not able to get this image on your own, is that I'm gonna attach it to the description or attach it somewhere so that you guys can get this image. Just look at this Videos. Oh, fixed. So what I'm gonna do is after we download this background image toe our project folder, make sure you do that. Then we're just gonna add it, toe our windows over here. How do we add images? Toe? Our program is just by my game. Got image? No, I'm gonna do that. Someone had a comment, Let's say and, uh, we're gonna write just background. It's just background. And then I'm gonna create available called background. I'm gonna do the same thing that we did with the rest. So I'm just gonna copy and piece it over here. And instead of UFO, I'm gonna write background. So obviously my images off 800 to 600 pixels, so make sure it is off that states. So now that we have added it, if we run it right now, it's not gonna appear because it just appears for a second and then it disappears. We wanted to persist. So how do you make it process is by adding it to our loop. So we need to make sure that we go to our my loop over here on. We're gonna add just below the screen door, Phil, because if you don't, then this black color is going to be on top off our background image. What you don't want? So what? I'm gonna do it. I'm just gonna add another coming over here. It's gonna say background image and we forgot to be So let's that be on, You know, we're here. We did not do the screen. Just typical thing we do when we want to add an image, which is screen don't Bleidt. So basically draw the background image and then we need the variable off the image. So that is background. And then we need to add the coordinates off our image. So we just wanted to appear from the top left corner. So we're gonna add zero comma zero and that should be pretty good. So let's round our mean dot by program. Let's around me and you revert to see that our background is dead. But the problem with a background under NP and a spaceship is now that they are moving very , very slowly invested. So it proposes. We do and figure it on your own. Generally pretty cool. But I'm just gonna explain it over here. So are backgrounder PNG's active 26 pixels SRE to 26 Gabi's. So it's a little bit Harry. But what happens is when this violent group is running every creation off this vile. You previously used to happen really fast, but now, because it has lured this heavy background image, the immigration off this via Luke, every situation is a little bit more slow, so that is where venom of your increasing the value over here. So, for example, we are increasing the value off player. It is too small. So when our this wild Lupus going is just increasing the value by 0.3, it's very slow. And that's why it's not able to move around a lot. So what we're gonna do is we're going to increase the value to five off our players, and I'm gonna change the value off our enemies. So let's see and me. So here on me, I'm gonna give it a value off, Let's say for I just want these and means to be a little bit slower than a spaceship, because when they're going to be a multiple enemies, then we don't want them to appear like, really, really fast. Let's related now, anti if it works, so it's still slow. Why is this happening? A special pass increased its ah movement, but the enemy is still slow. So let's see if our somewhere are your values. Astor assisting so enemy We have changed the X value over here, so let's go up and see where we have not changed the value. So when he had the enemy exchanges still 0.3. So we have to change it. Oh, you do? Let's make it for now. We can reloaded and you'll be able to see that the enemy is moving at a good speed. So now we have the background image. We have our spaceship and we have any. The only thing missing is the bullets. Because we don't have the bullets right now to kill this enemy. So the next we do, we are going to make bullets are get started with making our but so answer you for that. 11. Shooting Bullets: Alright, guys, in this video, we are going to learn how to shoot our bullet inside our game windows. So, as you can see, I'm shooting a bullet on the enemy. So right now, the bullet is not hurting the enemy because we haven't implemented a coalition yet, but more on that in the future videos and this video is going to learn how to shoot a bullet. So let's get started. But before we get started with the good, I just wanted to explain a couple off things, and the first thing I wanted to explain is wants to starting position off the bullet. So when you're in the middle of the window that is at 3 70 pixel X coordinate approximately . It's shooting from the top off our special, but if you move left, it's still shooting at Dub X Coordinate off a special. It doesn't matter where our spaceship is. The X coordinate off The bullet is going to be always equal to that off our spaceship. Just the starting positions. For example, if you shoot the bullet right now, even if we move a spaceship, the bullet is not moving with our spaceship. That starting position off the bullet is equal to that off our special. So that is the first thing. And the second thing is that as we shoot the will, it the bullets why value is decreasing because at the bottom the value is 600. By coordinate on as we go up the value of by decreases and at the top it's actually zero. So and the dog the Y coordinate off, why off a bullet is going to be zero. So we have to decrease the value from about 40 pixels. So because this for a coordinated by coordinate on, we're going to decrease it as we go toe us the top, so they know you can see that is disappearing at the top. So the third thing I want to talk about before we go into court because it's so important to understand, is to state off bullet. So right now, when you can't see the bullet, it state is at ready. But when you can see the bullet, state is going to be at fire. So right now it's not appearing on the screen that that means that we're reading the bullet for fire on when it shoots you can see the will it, and that means the bullet has been fired. So let's not do between that fighting period anything. So this is what it means. Obviously, you're going to understand more as we died down the court. So let's get started with that. So the first thing we need to do is act image off a bullet inside our project folder. Now, already added, as you can see on the left hand side, bullet dot PNG and it kind of looks like this. So how can you get this image so you can just go toe flat? I could dot com, like we have been previously, and search for this bullet, and you can just download this bullet from here. And obviously you can choose any bullet that you want on even through Google or something, but make you when you download this image. It's 32 by 30 pixels that this bullet is not the same as I'm using. But if you want, you can just go to the sixth or seventh page off this flat. I can dot com and you'll find the same image, but feel free to use. This image doesn't make a lot of difference. So now we have downloaded this bullet dot p and G, make sure it's still you do by 32 pixels. Did we just close this for the shop? This is the Bagram. You made the last video. So after I think the bullet or PNG, we're gonna add it into our by court. So we're here. Just build any media's gonna copy this enemy because we don't want to create everything again on instead of anywhere is gonna write bullet on. We're gonna replace everything off our enemy with our boots. So let's call it a bullet. And then I'm just gonna copy and pieced everything. So that X bullet Why, Andi, Uh, just based it. But it exchange and some of these values we are not going to use. For example, bullet is not going to move in the extraction. So using Vicks X underscore changes useless. But still, we are gonna just keep it over here just for this sake, off conformity. But anyways, in this bullet X and bullet, why, we're gonna give the value off zero bullet X because we are going to be changing the value , insider Lou. But bullet, why is going to be at 4 80 pixels by start. Because our spaceship, as you can see as clear why is that? 40 pixels. So at that live in the bullet is always going to be shortened. So if I don't just mean program over here, you can see that a spaceship is over here and what's happening to her enemy. Let's reloaded that, See if you have done something toe enemy No. So, as you can see, when we move our spaceship, it's not moving in the wind direction. So we need to shoot our bullet from its stop office knows which is at for 80 pixels off my coordinate. That's why we have put in this sport 80 over here, and then we're going to add another available is going to be bullet steak. So this is the state I was talking about a few seconds ago. So we're gonna add available bullet stayed on. We're gonna give it a value off ready. So let me just add a comment actually over here so that you guys remember what this city state is, what it's wasted. So ready state basically means you can't see the bullet on the screen Onda fire the bullet . It is currently moving. All right, so this is the state we are going to be using two basically different shade between whether the bullet is in motion or it's in a state off constant on its not being fired right now is gonna help us decide the movement dynamics off our bullet. So now we have created in a double that state courts ready. And now we're gonna create a function known as Fire bullet that is going to be called we know of you press our space, but in our game, when we repress our space bar off bullet is being fired. So that is what we want. I'm pressing the space bar, but it gets quiet. So on what happens beneath press space Bar B one dysfunction off fire under school bullet to be called on. We're gonna do the same thing over here. We're gonna call the X and Y vegetables on just below that, we're gonna access this bullet. Underscore state. Well, bill equals two really insider function. How do you do that? You need to create this bullet underscored state function as global so that it can be accessed inside this function. So I'm just gonna write global and then quit state on. Now we can exist the value of this bullet state from insiders function. So after this, after we press space, the bullet is actually being fired. So now you can see it on that screen. So we need to change the state off. The blood equals to file. So now it's not ready is actually being fired currently in motion. After that, we just need to make sure that it appears on the screen. So I'm gonna write skimming Don't let me to draw the bullet on the screen and then I'm gonna write the name off our bullet image bullet image, and then we're gonna right the coordinates off. Where do we want to appear? So we just wanted to appear on X com a wide the values that we are getting from the function. Now we want this values to be at X plus 16 on bipolar step. Why's that? So let me just for my everything properly and you can press control plus l if you're using by jump to make sure that it looks good. So why are we doing this? Express 16 by plus 10. This is to make sure that the bullet appears on the ST office patient. If you don't know, plus 16 is going to appear on the left hand side of the spaceship a little bit. I've already tried it out. So that's why I know Section is the correct value on this way is just make sure that it appears a little bit above spaceship just to give it an illusion off the bullet being fired from the top off the news and not from the center of the spaceship. And now, before we go into the Via loop, I just want to change the value off Changing. Why? Because I'm pulling is moving in the Y direction, and this is the value that we give to the enemy. We don't want ability to move this past. We wanted to move at the speed off, so let's close this window. No and pleasure go below on. What we want over here is that if an arrow key off space, not a rookie, if a keystroke off space on her keyboard, this place, then we want to call that fire in the scope Willard function. So let's create that over here so we can just copy and paste this line. And then at the end, we can just add the value off space. Okay, Underscore space on this way to make sure that we can capture the value off space and what we want. Many presses pace. We want a fireball, it function toe be God, I know one of the values inside this. So right now we're gonna give it a value off player X, but you'll understand why this is strong. But this is just like a logic editor, so I'm not gonna worry about it too much. But I'm gonna tell you why it's strong and we're gonna fix this in this video. So that's traded. If even darkie pie game darkie under school space firing less Coppola Player X. So that's run this right now and see how it looks. Obviously it's not complete, not even close to compete. But we're gonna look how it looks. So I know you can see bullet is not there. But when we press the space, nothing is happening and the enemies appearing for some reason Over here, if you speak if you seen yet near the spaceship the enemy's ability because we haven't changed the name of her image. So let's go to the our bullet. And over here, instead of enemy, we're gonna call it bullet. I know. When I was recording this on you, I was just writing the this line. You guys must have screamed that. Hey, that should be buller dot PNG not know is we have changed their value and if you come back , you can see that you can't really see the bullet over here, but it's actually appearing, but it's appearing so fast that you can't see it. So actually, let me just change it to enemy again so that you guys can at least see it's happening behind the screen. So let me run this on a very press space. You can see that the enemy is appearing at near the spaceship. You can see this. This is happening. So this is how the bullet is also appearing. But right now you just can't see it. So let's change it back toe bullet are PNG. So we need to do a couple of things. So why is it appearing and disappearing so quickly? What we need to do as we need to make sure that it persists in the background and when we need anything toe persistent by Gaby added to our influence by loop. So right now, this court is only being coiled. When we press the space bar, we want this bullet toe appear on non disappear. Literally pretty. So we're gonna add another comment over here on. We're gonna call this bullet movement bullet movement and we're here. We're gonna just changed the values and first check, maybe the state off our bullet. So right now our state is very press the space bar. Then the state changes to fire. But at the fort, the state always remains at ready. So as you can see that the bullet in the score state is equal to ready on when we press the space bar, the fire in the school bullet function is cord. And inside the function, the state changes to file. So I'll say it over here began great and condition. If bullets state is fire, then we can actually move. Double it in front, off the spaceship on, make sure it decreases in white. So we're gonna add some values and we'll call this fire bullet function again over here. And we're gonna get rid of value off player X on. We're gonna get a value on why, on just below this, we're gonna decrease the value off our bullet. Just like we discussed on the starting off the radio minus plus minus equal minus equal to Will it change which it's currently dead. So let's run this program now and see if it works. So this is our spaceship on what's happening to her and me right is going crazy. We just reload this. What's what's up with this enemy? So now you can see that the bullet is moving. But this there is there to problems in this first being, only fire one bullet so you can see after we have fired one bullet, we can't fire under the bullet. So that's one problem. And the second problem is that when he fired the bullet when we move our spaceship the bullet, it's moving with us patient. Just to give you guys an interview, when you press pays, the bullet is going. And when we move the spaceship, the bullet is actually moving with the spaceship, so we will be solving both of these problems in the next video. For right now I'm just gonna give you a free capsule that you guys can't understand properly. What is going on? So let's go for the moment, Depressed the space part. So very press the space bar, This even off space bar is triggered on the spire. Bullet function is called on over here we sent to values that at the current position off player X and a bullet by value the bullet values for 80 my cornet and the player eggs is the movement where the spaceship is the X coordinate off the spaceship And that is partly the reason by the bullet is moving in the direction of the spatial where they were going to tackle that in the next video before. Right now we're calling this fire bullet function when it with the space key is pressed and you transfer the value of player X and bullet by to our fire underscore bullet function. Now, this fireballer function is to changing the state off our bullets state underscore to fire so that when we execute this by Luke, all the school can be executed. So we're finding fighting the bullet on provide ability first need to show it on the screen . So we're blending it out or drawing it on the screen. We have seen the value off 16 on Why? So just to show you guys might be actually in the value, let me actually remove the X and Y values so that you guys can see the difference. So I'm gonna play and I'm gonna shoot a bullet. As you can see, the bullet is being short a little bit from the left hand side, and we wanted to be sure from the middle of the screen. That is why I did that. So in the middle of the spaceship, not in the from the middle of the screen, to be exact, but anyways, after we did this fire in the school, bullet function is being called the blood state has been returned to file on. Then we go to this infinite value, which is running. But it wasn't running because before running the space by our before pressing the space, but the bullet state wants ready. So all of this court was not getting executed. But after pressing the space bar, the bullet state handedly changed to file. So now we can pull blade this out on the screen by calling this finder's complete function on. We can start actually changing the location of the Willard by moving it in upward direction by reducing the value off. Right? So, guys, this was the logic off our bullets in the next video. We're gonna tackle the two problems that we have discussed in this video, so I'll see you there. 12. Shooting Multiple Bullets: All right, guys, welcome back. The last week we learned how to shoot a bullet, But there are a couple of problems that are program right now. We can shoot only one bullet at a time. And that said, that's it for the whole game. That has a pretty big problem. And the second problem is that the bullet is always following our spaceship. Doesn't matter where you go, bullet will follow it, and we want it to have an individual parts. So, for example, we wanted to have we want the bullet to have the starting point off our spaceship the X coordinate on a spaceship. But when we move the spaceship, that bullet should continue on its original X coordinate and not off our current spaceships . So these are two problems. We are gonna start lifts, told the first problem, first off, having multiple bullets. So for that, what we're gonna do is we're gonna add an if condition. So right now, if you watch away here when the bullet goes up, it goes to the zero coordinate on. Then you're not doing anything to a bullet, so it just keeps on going into negative values on We're not removing the bullet from our screen. So what we need to do is as soon as it crosses the zero coordinate, we need to make sure that it resets to the value off for 80. So as soon as soon as it goes above zero card and two things are gonna happen first is gonna be set to 4 80 pixels off. Why, on a second thing is because you can't see it on the screen anymore because it has gone beyond zero. Why coordinate? We're gonna change the state off a bullet to ready again so that we can fight it the next time. Let me just add an if condition beneath this bullet movement which says, if bullet, why it's less than equals to zero because above zero is gonna be negated Values on over here. We're gonna do think two things first is we're gonna he said the state off the bullet that is the bullet. Why should be decided to 4 80 again on The second thing is, we need to change off the bullet state, so billet state is going to be ready again. Onda, let's make sure that we don't misspell anything on we're gonna format just properly. Press enter and now let's reload it on. You will be able to see that bullet is multiple. So right now you can see we are short one bowler. Then we can shoot another bullet and it keeps on happening. And now that you're fix up first problem, let's focus on. The other problem on that is that the bullet is following our spaceship. So why is this happening? This is happening because in our court we are still using the player X value. So if you go to our space conditions So after President Space, we are using the player X value and even in our violent if condition code off over here, we're still using the player expel you. So it's already that we want the starting position off our bullet to be active spaceship. Let me just removed recording things. So at the starting position, we want the bullet to be at the X coordinate off spaceships of any press space. The bullet starts from the spaceship and not from somewhere else. So, for example, over here we want X coordinate off a bullet, Toby that off the X coordinate off our spaceship. But when we move after fighting the spaceship, the X coordinate shooting followed the spaceship. So that is the problem that we are having so hardly soft. So instead of using the bullet, the space player X value everywhere, which is just used, many press the space, but one value off the X coordinators should be just saved. So we don't do that. We're gonna write Bullet X behind. Use this variable yet on we're gonna save the value off, cleared X over Hill and then insert off Player X. We're gonna send the value off bullet X to our fire bullet function on. We're gonna do the same thing over here in our conditions. So instead of player X, your used a value off billet eggs and that's your solve the problem. So let's run army program again and see if it works. So this is a spaceship on now. If we move our spaceship, the bullet is not following our spaceship. So yet what we have done as vendor space, but expressed, Then we're saved the current spaceship X coordinate inside a bullet x variable, and then we are using that everywhere, instead of just using player X So now that fixed that there is one more problem to fix, which I'm just a light. So the problem is that after pressing if depressed about space but against, for example, the oppressor space. But the bullet is going. And then if you press the space bar multiple times, this bullet is going to change. Just keep on moving according to our spaceship. So multiple space bar changes its X coordinate. And why is that happening? So Lyinto bullet is in moving condition, It's in fire condition. Even in that condition, we can press our space, but so we have to make sure that we can only press the space bar when it's in ready condition. We're gonna add our if condition. Over here. It says if bullets state is ready, let's edible coats for the strength. If the bullet status ready, only then we can fire another bullet. Otherwise we can't fire the bullet. So after our bullet goes above the zero coordinate or our bullet is in very state, only then we can fire a bullet. So now if you play space, all the others have bean fixed. Except this Force one. I don't know what happens to it sometimes. All right, So let's shoot. And you can see that after it has crossed the zero coordinate and it resets to 40 Why cornet again? Only then we can shoot on a door, will it? So this is looking pretty good. Guys were finally completed. The bullet more. Doing this for a pretty long more deal because there were a lot off complications in it and a lot of things to understand. So let me just recap so that you guys can understand everything properly. So if anybody has understood everything perfectly, you guys can just stop this video. So what happens? Many presses paved when better space. But first checks whether a bullet is already on the screen or not. If it's not on the screen, then it make sure that it gets the X coordinate off our spaceship. Let me just add it coming so that you guys can understand get the current six Gordon it Oh , the spaceship. So it gives the current X corn or the spaceship and stores it and say this variable bullet X and then it fires the bullet using this bullet ex terrible on this bullet. Why variable basically which we have said before that stent. So we want the bullet move at the speed off 10 or change its survival new at every while, Alteration at So after we do that, it goes to this fired bullet function on or they changed the state to fire on. Then it creates that bullet after his changes state to fire in course to this Why Lou filtration and change it say's if bullets status, fire on it keeps on fighting the bullet. If we don't have this fire underscore bullet statement and the well, it won't appear on the screen. So anything that we want to be persistent inside on game needs to be included inside at biloute. That is why we have dysfunction inside our value. If this statement was not that the bullet wouldn't be dead. So that is why we need to make sure that the bullet is continuously appearing on the screen after a reiteration off you. So after it fires a bullet and it keeps on changing its why coordinated because off the statement, it happens that it goes above the screens after it goes above the screen. This condition is operated on it resets the bullet for every by coordinate on Dene research the bullet state ready again. And then we can express the space bar again on everything happens again. Basically, it's safe again the X coordinate off a spaceship. But I'm not gonna go into all of that. So, guys, that is pretty much it for this video. In the next video, we're gonna create my tipple enemies. So right now, there is only one enemy. So it's very easy for our spaceship. Or maybe depending upon what I want. And maybe I'm gonna teach you guys how to shoot this. And right now, this enemy can pass through the bullet and nothing is happening to him. So we're gonna probably discuss that in the next video. So I see you. 13. Collision Detection: already bite on game delivers. Welcome back to the spite on my game video series in which we are creating a space in readers came so the last week will be created. Multiple bullets instead of shooting just one bullet began, showed multiple bullets at the enemy. And we don't have to, you know, just just shoot one wheeler during the whole game. But as against er, bullet is going through the enemy and it's not colliding, and nothing is happening when the bullet hits enemy, not the score is increasing on the and me is also at the same place. It's not this morning anywhere which we want. So in this video we are going to learn about the collision concept, how to make sure that the two objects have collided on. That's a very important concept in gaming. So what we're doing is that let me just actually reload this game so that we can see the bullet and enemy properly. So what I'm gonna be doing is we're gonna calculating the distance between the bullet on the enemy. If their distances shot enough, then we're gonna conclusively say that the bullet has collided. So the bullet has an X and Y coordinates when it goes up through the screen. And similarly, this enemy also has an X and Y coordinates when it goes through the screen on left, right or up and dump. So we're gonna use all of these four coordinates. That is the X coordinate on the X coordinate off bullets and the Y coordinates off both our bullet on an enemy to calculate their distance between them. So now what I want you guys to do is go to Google and type and distance between coordinates and you're gonna take you to this website, matt planet dot com. And over here there is this equation with say's distance equals toe X coordinate minus X coordinates off the object squared, plus y coordinate off. One object on Dwight cornered off the object square and then a square root off the whole thing on this extra and x one doesn't matter what ever is that, friend. Because by the end of you, Davion squaring this So obviously you must have learned this in school or in college. But if you haven't, don't worry about it. Just go through this article a little bit. You just need to execute this court in this equation in our fight on. So even if you don't understand what this is doing, we're going to learn how to actually implement our equation and fight on. So that is going to be really helpful for you guys. So keep this equation in mind on Let's go back to our court on just beneath this far underscored bullet function, we are going to create a new function, and we're gonna call it is Coalition. So this function is basically going to help us, but define whether collision between the bullet on an enemy has occurred or not. So it's not a for values of X. Coordinate off the enemy the y coordinate of the enemy, the X coordinate off the bullet. And similarly, the y coordinate off bullet. And now we're gonna create a very balloon as distance this distance will store their distance between the bullet on our enemy and how we calculate this distance. Obviously using this equation so distance equals two and then we're gonna do a square dude . So do a square root or do any kind of mathematical operations. You need to import something known as Matt. So if you go up a hound imported Matt yet. So I'm just gonna night import Matt. Somebody import that. And then, first of all, we want to do the square root. So let me go here on just right, matt dot sq rt. So this is basically the function or the method for doing square root and then apply some brackets. Now we need the enemy X on the bullet eggs and meaning receptor acted according to the formula. But before even that we need to square. So if you go back to our equation, you can see after the square root the X two minus X one is being squared. So we also need to implement that mathematical formula. So it's gonna right, matt dot u w So this time for power and that it requires two values the X and the y. So we're gonna do that. So we're not just stayed calm because he wanted to be squared on, then over here, we are gonna give it the value off enemy X minus enemy white. All right, so this is looking good. We have executed the first part of the equation. Now we have to execute the second part of the equation, that is Plus, why do minus my one under squared. So we're gonna go back over here on inside our math adore part. So this is this part math dot by extra on this is enemy. Not any. Why? This is bullet X. Sorry about that. And then we're just gonna write. Plus, and then we're gonna night, Matt, Dark power again Because we need another power and requires to devalues first is the part value. So we wanted to be squared again, and then we just need to subtract the enemy enemy. Why me? Why? Minus bullet? Why on this shirt gave us the value. Obviously, we need to close this myth math or square root. So we're gonna apply the bracket, but looks like it's an extra bracket. So what we're doing is matt dot how we are doing X two minus x one or x months explained minus extra. Doesn't matter. Squared it on, then. Matador park by my house. My wants squared. So just to make sure that these two are separate, we're gonna apply on at the bracket over here. So I'm gonna also do this with this one. Let's not go. I learned up. All right, So there's some problem or here. So this is the problem. So let's apply a packet away here and there. And this is looking pretty good. So what we're gonna do is we're gonna right? And if condition, if this distance is less than 27 pixels, then return us the value off. True, that is the collision has occurred. Its bitterness, the value off faults. So we're gonna write F condition on return faults. I mean, you didn't need to write the same condition. We could have just returned. False. Oh, yeah, but I just wanted to make sure that you guys understood. All right, let's formatted properly. Obviously, beauty form are needing in by charm. Make sure you place control or plus l ls for I don't know, lose something. So make sure you place control oil, plus l. If you're using by John issue format everything. Beautifully. All right. So are his collision function is complete. So now what we're gonna do is we're gonna screw down on. We're gonna right inside our while infinitely over here, just below this enemy X or even the politics. We're gonna add a comment That's gonna stand for pollution so that we know that we're writing the court for collision on over here. We can just check with the collision. Was happening are not. So it wasn't a create available called core division. And then I'm gonna call this escalation function and what you were gonna say, the value off enemy X and Y, And over here in all of the score, inside this Why? Look, we are manipulating the value of X and Y off enemy and the bullet. So this is the right place to call this escalation function. So we're here. We're just gonna write bullet X com. A bullet. Why? All right, so this is looking good. So this is collision is going to restore the value off true and false. And if the collision has occurred, is going to store the value of collision off. True in collision. All right, so this looking good, and then we're gonna write a condition if condition. So what do you want us to do if the collision is occurring? Basically, that is water program is asking. So what do you want after a collision has occurred? So the first thing that we want s totally said the bullet to its starting point. So we're gonna reset the bullet by act for 80 and then because the bullet is not being shown anymore, we want to change the state off the bullet ready? Let's change the state of the bullet already by knighting bullets, State equals two. Ready on. The last thing we want to do is obviously increase the score. Something's gonna create a new variable. Let's say let's actually just go over here so that it's close by on didn't write the value off score equals 20 All right, this is looking pretty good, so I'm gonna just scroll down. I know what he I'm gonna write. Score, score missing the very below score square plus equals to what? So this will increase the value by one every time we hear our enemy on. After that, we're gonna bring out our score, so I'm just gonna print it out on screen. So now let's just it on our program and see if everything is working on North. So I'm just gonna run the mean program on over here. We're going to shoot our bullets on Hopefully if it hits and I'm not a bad player. As you can see, the score increased by one. So let's try to hit it again. And as you can see, the score is increasing by one. But when we're not hitting in, the score is not increasing. So let's try to make our score a least five. All right, All right, so the score is five. So what? One thing you must don't notice is that the enemy is still on its current part on its not least pointing to its before locations, So we need to fix that. So what we're gonna do is we're gonna change the value off player X enemy X and the nearby here, so I'm just gonna screw it up and check out where we have declared the value off enemy X and you buy some. Just gonna copy this on when basters inside our If collision obviously like this court can be optimized, we can create a new function for all of this stuff that is happening over here. But maybe we can do that in the later videos on the optimization classes and functions, we'll see whether we do that on normal is not such a complicated program, but maybe so. Now what will happen is that the enemy X and the enemy why will get restarted on respond to a different location and respond to a random in T J. That between leader to 800 on by 51 50. Obviously, we already discussed what starts basically gives a default position to the enemy. So let's hear it a short again and get under mean again and see if it works. So let me just wait for it, all right? So our enemies actually just going back to its new location. All right, let's just wait for me to come back a little bit down so that we know that our God is working. Probably. So let's shoot it. All right, So our game is responding. Probably our enemies respond probably, and it looks good. So one thing you might have noticed that when it comes to this right hand side of the screen, it just drops down. Even if you're trying it on your own. If an enemy response towards the right hand side off that window off re Lloyds goes down, why is that happening? That is happening because when we respond on. And me or just people were creating the media, giving it a value of zero toe 800 on. But insider court, we have written in over here that if the enemy X is greater than 7 36 make sure you change its y value. There will be no more. Our enemy is responding with a greater value than 7 36 It's immediately going down without a chance to go left. That's why we need to make sure that over here, when we're creating the enemy that we don't increase the value of 800. Only 7 36 and just about safety. We're gonna write 7 35 So obviously we need to make sure that the 7 35 also goes in when a collision has occurred. So I'm just gonna copy that. You do? All right, so this looks good. We have also fixed and enter, So this is looking pretty good. All right, so All right, look. Enemies responding. Probably let me to shoot it again. All right. So are I Guess that is pretty much it for this video. In the next video, we are gonna learn how to create multiple enemies. So right now there is only one enemies of the game is pretty easy. Just play it really easy. Naturally, it's pretty fun to play while I'm recording medium most plane. But anyway, guys, let me just recap, actually quickly so that you guys Canada's time. So if you already understand, the video does go to the next video. But for people who have not understood, probably so we have created a function card is collision where you have four coordinates to off any coordinates and off bullet coordinates on. We have used all of these four corners in this formula which we got from typing in distance between two continents. This formula and then we try toe execute this formula, insider. Good. Obviously, before you shot, start doing this man thought scored, make sure that important, Matt. And after that, we made the square root on. Then inside this week, using the dot bowel function, we squared it just like we have done in this formula extra minute exclave squared. So we needed to make sure that we squared it and make sure that the brackets are correctly place. Because if you guys are typing the court, it might it might. You might mess up somewhere, so make sure you guys are typing this court properly. Labeling. All right. What? Obviously, I'll upload all this Korb on get up so you'll find it somewhere with that on the by the end of the Syriatel uploaded after recording on the radio so you can wait for it a little bit, or you can find it in prescription or attachments or something. So matter piney X minus politics. You guys understand all of this stuff, and then how this 27 there. Welcome booking, Toby. So I just trying to state what was the proper number for distance between enemy and bullet to call a collision on just by trial and testing. I came on this number of the distance between the bullet and the enemies less than 27. I'm gonna call it a collision, and then if the collision has occurred, it will return true. And obviously we are calling this function. We're here if collision. So if a collision has a good war, do we want from a program? The first of all, you goingto reset the bio doublet for 80. That is the starting position on the spaceship. And then we're gonna change the state on course to ready because you can't see the bullet anymore on when you can't see the bullet anymore. The status ready. And then we increase the score by one. And we printed out the score. And then we make sure that the enemy respond to its new location. Alright, guys. So this is basically our way toe just to track back a little bit. This is just a way to kill the enemy and then make sure that we also create a new our guys . That's pretty much it for this video tanking for hanging out in the next video. We're gonna learn how to create multiple enemies, so I'll see you there. 14. Creating Multiple Enemies for our Player: All right, guys will come back. And this we do. We are gonna learn how to create multiple enemies. And in the previous video, we learned about how the collision system works. So, for example, if he should, enemy is gonna respond to a new place as well as increase our score. So how do we make sure that multiple enemies appear on a screen? So, for example, six enemies What we can do? One idea is that we can store all of the six enemies in a list or in a day, but in Ireland is calling a list. So we're gonna store all of the enemies in a list on display them one by one on the screen . But it's gonna happen so far that you re look that all the six enemies are appearing simultaneously on the screen. So we're gonna done all of these variables in tow list available on How do you do that? You simply copy the very blame on equal on brackets. So this signifies and the list there is nothing inside this list on. We're gonna use a for loop toe put values inside this list, but we have to do it but all off the variable. So let's do that. So let's do it with Enemy X and then enemy. Why? So? So copy. This could be this based over here. Let me just copy everything first. And then I'm gonna act of square brackets, not the new display, but the quickest way. And then I'm doesn't copy all of these square brackets quickly. All right. And how do you bad values inside a list? So right now, this is an empty less how the ad values to a list is by using a method known as start up. And so instead of equals two, we're gonna use dot upend over here. But even before that, we're gonna create available, known as number off enemies stand for number off enemies. I can change this variable whenever you want to increase the number off enemies. So we're gonna create a for loop for I in range. On inside. This were an important number off enemies. So this look, for right now I'm gonna around six times on six off. Our enemies are gonna be created. Obviously, we want all of these One used to be added to the list that were created off the variables. So what we're gonna do instead off equals We're gonna I don't offend. And there's going toe ad our current value inside a list. So, for example, the first enemy image is gonna be stored inside this enemy image list. So we're gonna do all of this with all of the variables on. You don't need to do it with any change, because these are, like, constant values, but well, just for the sake of simplicity, we are gonna do it with all of them. All right? So let me just do it with all of them. I'm gonna copy the start up end everywhere. So just to do it quickly again not don't need to speed, but the quickest way. And that is what we born just a quickest rate on. Let me just on the blackest after everyone so that there are no errors on it. Looks steeped. Alright, guys. So this is looking pretty well, so whenever accorded going around, it's gonna go through this as gonna create six number off enemies. But if you school down inside our why, Luke, you can see that we don't specify which any extra we want to move. So this is the court that we're using for me to move towards the left inside on the right, inside on a downward movement. But if you don't specify which enemy X we're talking about, Because if you notice above, we have declared six any X because we have created available corn as enemy X, we have created an empty list. So east time this for Lupus. Gonna run is gonna enter a new value off any exit inside this and me X list. So we need to make sure that program understands which enemy X we're talking about. So we're gonna create another for a loop over here, and we're gonna do the same thing that we did. A dead number off enemies on. The idea is pretty included. You just need to change every value over here toe basically inside a square back and displaced five, which value you're talking more and this is aware to reference something inside a list. Obviously, if you know less, you probably already know about this. So anyways, we're gonna do this. We haven't I I bracket everywhere soul, and we just copy and pieces everywhere. So that program news, which Anyway, we're talking about which enemy Why change we're talking about? Let me just copy this everywhere. All right? This is looking pretty good. And then we also need to make sure that the collusion is also inside our enemy. So we're gonna copy all of this court from over here on. We're gonna place this and site are while you Because we need to make sure that we can relate the collision for every meeting spaces. So you can sit over here that currently are collision is it's not inside our for Luke, but actually inside. It's actually inside a fall. But make sure that it's not inside this left condition or if condition other way, it's not gonna work. A lot of people make this mistake that they don't face the collision part correctly or don't base anything properly. Anyways, after making sure that your base that is probably inside her for Look, we're also gonna change these. Oh, just press it. You're going to make sure that item program knows which and me X coordinates were talking about. So let me just based little way here. All right, so this is looking pretty good. We also need to make sure that we are here. So basically, video, we are talking about the enemy or the coalition. You need to make sure that our program knows which coordinate on which any me we are talking about. And then the last thing we need to do is better. We're calling the enemies, for example, over here calling the enemy function. On this, we were basically bleeding the enemy. We also need to make sure that we are Which image do we want to be blended? Right now? It's not specifying. So we're gonna pieces inside our and me for a loop on. Make sure it's not for space. Stay inside if condition it's pasted inside our loop. So inter nations matter on, then we're gonna send the value off, according with specifying which X and y goodness, we want to be printed on the screen, basically which and maybe you're talking about. So if we go up to our enemy function over here, you can see we haven't specified. I value, So we need to spend find a value on also the which image any imaginary want to drop. Obviously, you must be thinking there's only one image, but Actually, there are six enemy images because you have created a list off enemy images to that you can see over here. Alright, guys. So this is looking pretty good, I think, almost off the court system. So let me just play it on. Then we'll figure out what we have to recap. If there are any errors, we get started. So that's played and see if it works. All right, so this is looking really good. We operated on six enemies on when we showed them. So let's try and shoot one of them and to back earlier. All right? So many assuring them are. Collision is also working. They are responding. All right, so this is looking pretty good. So how it doesn't game gonna hang whenever open on the space and readers come and hit the bottom of the spaceship or basically hit the 4 80 by access, Then we're gonna end game so we'll just keep shooting and increase to score on greater. There's no place where we are displaying the scores and the next video. We're gonna make sure that we display the school on the left hand side, top corner. So we'll be working on that in the next video 15. Displaying Score: Oh, right, guys, welcome back. So the last video we created multiple enemies on our game is looking really, really good. So the score system is working, but the score is not being currently displayed on our game windows. So we'll fix that in this video. We'll make sure that the score appears on the top left corner off our screen. So how do you do that? So that is simple. We used a foreign object that is inside bagging, So my name is actually going to help us create fun on text on the screen. The first thing we need to do is go to this bullet image on. We're gonna actually remove the score variable that we've created over here. So instead of that, we're gonna just spends intell on dried score so that we know we are trading score under this statement. And then right now, we're gonna create available, known as core value on where the liver, the value off. Zero. And obviously you can see with this red symbol there is some error. That's a score plus one. We are doing it away. Yeah, we need to change this to score value, and then we can you remove the print statement? Because we don't don't need it down. So let's just go up now and then we have to use the score object or the by game front object. So that is pretty easy. You just create available units formed on, obviously probably know only what funders point is just the type off text or the style off text that has displayed How much weight off the line often I Yes. Well, actually, depending upon the front, what kind of for your use? So first, we are going to define what kind of phone do we want. So how do you do that? You just use the by game dot formed method that is inside by game by game, dark phone don't capital for on inside this, we're going to give it to values. The first list which formed we want so inside by again there's one free form which is known adds free sense board. So right now we're just gonna use this point on dark. Tpf is the extension of different, and then we're gonna give it a sites. So we're just gonna give it a science off party. Do Then, after that, we're gonna give it X and Y corners off. Very want this takes toe appear. So we wanted to appear in the top left corner somewhere, but not just attached to skin a little bit away from the scheme. So we're gonna give it a value off text text with X, coordinate off in vixens and then text. Why off? That is the y coordinate Also off 10 Now, just like we did with this player. By any means, we have to create a function that are going to show this core value on the screen. So let's do that. We're gonna create a function with Bianca called Show. Scored Pretty easy stuff on inside dysfunction. We have to give it to extend my value, just like happen. It's everything else. On one difference is that, for example, you can see how you're bleeding the image inside this deaf player. Instead of letting the player trying the player on the screen, we are going to render the text on the screen. So to show you what I mean by that, So we're gonna create available off score on inside this. We're gonna right front door Riendeau. I will require some values inside it. So this is what I mean by instead of blading, we're going to render the text of show the text on the screen. So using this foreign object we have created over here, we're right phoned on trend and then I'm gonna require a couple of values. The first value is what text do you want. So we want our text to be first of all school on. Then we want to score value in front, off the text. So we're gonna right? And actually, we have to convert it into a strength. Right now, this core value is an anti Joe, so we have to use typecasting on inside this tow. Basically, we're converting this in either. Valued was string by writings. Str in front off it this concept and by donors known as typecasting on actually in programming, this concept is known as and costing. So inside this, we're gonna write school value on Then after that, the second values required. It's true, so we can displayed on the screen. And then the third reading requires is what is the color off for that you want? You can show whatever color you want. Obviously, we have to use RGB values, which we have discussed before. But I'm just gonna use the white color that is 2 55 to 55 green and then to 55 blue. So this is looking pretty good. Let me just for Mattis, probably. And then we're going to show it on the screen and how they show it on the screen. So first we are going to render the score or trained other text, and then we have toe Blake this text on the screen or Broadus text on the screen. That is why I said this is a little bit different. Forced you after I know. Then you are public it on the screen. So we're going to use the same concept we have over here. So actually, me just call me this from here, feasted on Instead of image. We are going to render our school so this time is not an image. It's a phone for the next, and it quite x and y value, which we are parading through this function. And no one last step that we have to do is pretty easy. We just have to go down on anything that we want to persist on us. Came. Obviously has to be called insider. Why? Look, So I'm just gonna call our shows core function and X y is text X on next wife. All right. Okay, so this is looking pretty easy. So let me just run it and show you that it works. And hopefully it will run without any errors. So our scores big explained on the top left corner on when we shoot someone, let me just show someone. Advocacy are score is increasing, so they just sure that up a lot more enemies of space and widows are again. So this is looking really good at score is increasing and these are being respond and a game is being created. So one last thing I want to tell you guys is that how do you add extra for? So I know if you go to our foreign. So, for example, here is a port. This is the only foreign that is inside our begin. Just close this. How do you act other phones inside this? So what you do is you can go to a website or something and down your phones and they will give you a foreign that is off extension door tpf, and you can just download this, place it inside your project structure and just write the name off the phone. So, for example, what you can do is you can go to this website known as D A for on this gives a lot of fun for free to get download just any of any phone that you want and going to give you a zip file. Just extract that file on. It's gonna give you a dot pdf file, then basically purified inside this space invader project. Follow on. Just write the name over here, and then you can use that for inside your bag in. So that's pretty easy on this stand for the font size. So let me just increase for saying something crazy. 70 very. It's not that crazy, but as you can see, the score has increased to 76. But let's get bit. Let's keep it small, tell you to pick since. Alright, guys. So it was pretty much it. So let's just to recap a little bit. First we kill the score value. We added a phone object. Then we created the X and Y coordinates off the foreign very wanted to appeal. And then, inside a show score needed two things were rendered the phone on. Then we blizter it or through it on the screen and render we applied. Or give it three values have scored the true and the color off our text so you can change it to green. So let me just show you guess rgb So GB should be 55 then we can make both of these values zero rate on blue on This should make it green. That's played on that. You can see it's green, but we want to invite color white. I think it looks good on any game. So let me just change it to 2 55 again. All right, let me just give us space over here and then we dread on the screen and then the last thing where it waas before changing the value off our score. So after collision, we need to make sure that the score value is increasing by one. After we hit, they mean by a bullet. And the second thing is we call the show on the score function that is pretty standard. Alright guys. So in the next video, we are going to learn how in the game so they know the game is not ending, is just keeping going, even if the enemy it's constipation. One thing I notice is that the enemies are not moving very fast, So we'll also include the speed of the enemy a little bit in the next video on. We make these minor changes so and see you know what? 16. Adding sounds: All right, guys will come back, and hopefully you're having a great day. And today we're going to learn about how to add sounds and music to our by game on greatly . There no sound insider games. It's looks pretty simple. But what we're gonna do is we're gonna treat type of sounds, the foot sound in the background song that's gonna play continuously in the background. The second is the shooting off the bullet found in this case. I call it laser dot wave, and the 3rd 1 is explosion dot Wave that's going to be produced by now. Lays a bullet, hits our enemy on just to show you guys how it sounds. I'm gonna play this main door bip on file, which I wanted to change the good off so that you guys can see what's happening inside. I'm gonna play it. You can see All right. So you must have seen their tree sounds. First on continuously goes in the background second laser or the bullet sound. And the third is when our bullet hits our enemy. Now, how can you get all these three fellas? Look, I'm actually make sure that the cold is original on the last one that we have used on. Now. How do you get these three dr. File So what I want you guys to do is I want you to go to get her dot com arthropod space in readers spiking on. You'll be able to get all the code that I wouldn't allow and along whether you'll be able to get the dot Bay files that I have been talking about after downloading these three files , or maybe the whole court and you can download them by clicking on this clone or download and done down. Make sure you add the sound files to our your project by going to space and reader and just basting them over there. Now let's get started with adding background music into our game. So first thing we need to do is import something known as a mixer from a my game library on . To do that, we just ride from my game in Boat makes up import this mixer, and what is this mixer? This is basically a class that chances handed all kind of music inside our game, but they can be repeating our music, loading our music, anything that want. So you have to look inside this class whenever you want to do anything with sounds are music on then just below this background, we're gonna have a background sound. So let's write our comments that so that you guys can know in future what we're talking about. And then you just gonna use the mixture library by writing Makes her dark music don't load pretty easy because you want load the file and then we're gonna play the file and inside the sphere there's gonna write background dot which is the name off our file, as you can see on the left hand side. And then we're gonna play this sound by riding mixer. Dark music dot play Be easy on. Now, I want this file to play continuously because right now, if you don't add anything inside the start, play this file is gonna play once and then just stop. But we wanted to play in a loop because this is a game and can go on for long. We don't want to play just once. And how do you do that inside this mixer class, you just add minus one. I'm gonna play on blue, so Now let's just test it out and see whether it's working or not. As you can hear, the background music must be going on. But we haven't yet added the bullet sound of experience town, so that must not be there. So that's why we're gonna be working on adding the bullet sound now. But one thing I want you guys to notice is that currently we're using mixer dot music because we want this file to be played continuously in the bathroom. So this is kind off music. But if something is very short, for example, are bullet sound then we have to use mixer dot sound. So we're gonna come below where we have ah, bullet shooting. So how are you gonna catch the moment where our bullet is being released? So we're gonna do that inside our let's go toe above. Let's go to this. If bullets state is ready. So over here we can release the sound off our bullet going out from our spaceship because over here we're getting the X coordinate off the spaceship, and then we're shooting the bullet over here so we can somewhere over here at our bullets time And how do you do? That is also very easy. Just below this, we're gonna write mixer, not sound. So in this case, it's not mixer dark music. It's makes a dot sound on bringing a first create a reliable that's great available and called bullet underscored sound. Just to make sure that we know where sound is on makes a dot sound. And inside this, you have to give the file off the sound. So that's in our case is laser dot wave And then just like we did in the music case, we're gonna play it So we're doesn't right, But it's sound not state, but it's sound dark Play on. We don't want it toe plate inside loop. That's why we haven't added minus one. So now our bullets is making a sound. No, we just need to add on stand toe are collision Andre are catching collision. Let me just copy this first and we're gonna go below. I just want you to guess first where we are going to notice. A pretty obvious we're going toe this part where if collision we want it sound be played on that sound is off explosions. So we're just gonna copy and paste this over here because most of the things are going the same instead, off bullet, we're gonna write explosion sound, and then I'm just gonna copy and be STIs just below this play. And instead of Liza not wave, we're gonna go with explosion dot wave. So that's this is pretty much it. Let's actually play our game one more time and see if everything is working properly. So let's play this. All right, guys, everything is looking really good. So are all of the three sounds are being obviously feel free to work around on glee around at more sounds may be removed on your own son's. That's going to be fun. And the next really, we're gonna learn about how to make sure that our game gets over and our enemy hits our spaceship. So I'll see you there 17. Game over: All right, guys, welcome back. And the last week we learned how to add sounds toe our game on in this video, we are going to show the game or screen. So I removed all of these sounds for this video because it's going to be difficult to explain what's going on if I had to sum. So what we're gonna do is when men of these enemies come close to our spaceship. Maybe over here we're going to remove all of these and means. Or maybe just get them out of the screen and we're gonna show a big test, just like we are shown over here. The score zero. We're gonna show a big text off game over, over here in the middle of the screen. On when is this pixels going ahead? One of these enemies gonna come close to the spaceship. Then they're gonna hit the why Access off for 40 pixels, if you remember at adopting zero pixel at the bottom is 600 pixels on just at the starting off the spaceship. It's about 40 pixels. But just by experimenting, I found out that 4 40 is perfect, so they don't use that for 40 pixels as a limit. So winner and means come over here. We're gonna show Game over for our player on the final score is going to be shown over here . So what we're gonna do is we're gonna come to our Emmys where we are moving our enemies basically, So we're gonna come down and come to enemy movement. So any movement was over here on then. Over here, we're just gonna add a text. So let's add it takes on, just call it game or because we're going to be trying the game publico just below this on what we want is when whenever an enemy, let's any wife and whenever enemy by off I so venom of one of the enemies, they don't need to be all of the enemies when one off the enemies come toe for 40 pixels and actually, just to test it out, I don't want and needs to come to the bottom, so I'm gonna make it very, very small. Maybe 2 200 fixes on. Just when we are ending the game and you're finalizing the game, I'm gonna change it again to 4 40 pixels. So whenever one of the enemies come to 200 pixels than what we want to know. We want to move on the enemies. So we're gonna create another form for J. And and then we just got a copy. All of these because we want to move all the enemies out of the screen. That's good. Create under for loop inside this big for Luke on, then under this and it's gonna change the access off And me wife J equals to 2000. And the shirt make sure that these enemies go below the scream toe do 1000 by fixer. And then after this, I'm gonna just make sure that we display the game over text. So how do you do that? I was gonna create a function on dysfunction Will be called under school. Game over, text on. We're gonna call this function, and then we're gonna break out of this loop. So let make sure that we're not doing anything weird. The brackets and we're here. We're just gonna right brick on. This looks pretty good. So what we're doing is minimal off enemy. You don't need to be all the enemies when one of the enemy's reaches this created an doing it pixels in this case, but it's actually going to be 4 40 on then we're gonna collect all of the enemies inside this follow on. We want each off the enemies to be moved out off the screen. And we're doing that by setting the y Axis 2000. It is not going to be shown on the screen. And then we're calling this game over. Text function is going to display the team over text on the screen and then we're breaking out of this loop because we don't need this for I in range loop anymore. So now let's create this game over underscored test function. So we're gonna go where we have added art score. So let's just go over here so you can see we have added a score over here. So we're gonna do doing basically escapes same thing, and we're gonna right game over next over here. And then we're gonna call me the same thing that we have done over here on instead of for and we are gonna just straight game or may weaken right or underscore fund Onda. We want this form to be bigger. So this is the size of the foreign. We're gonna make it 64 about 64 pixels. The size is bigger, and then we're gonna create our function. So just below this show underscore function, we're gonna create our game over ex function on. We're gonna do the same thing that we did previously with our show Underscore. Function on, then over here, let's just copy and paste this line. So we're gonna copy this based over here and then instead, off score. Let's just call it over. Underscored next. And then we don't need all of this stuff. We just need to be displayed. Game on. Let's make it in capitalist. Just picture. It looks good. Game over. So this is looking good. Then we just need to bleed it on, drawn down the screen. We're gonna copy and basis over here. Let's just presento and basis over here and instead of score, we're gonna right over underscored next on. We're not because we're not going to use the X environment as we can use it, but because our game worst takes is going to be displayed at one place. So I'm gonna remove this instead of that. I'm just gonna write 200 to 50 pixels on this 200 calmer to 50 pixel is basically the middle off screen. You can try out different values and see what works for you. But basically I divided both of these values by two and made it a little bit less both the X and y axis. And that's how I got to the center, obviously you to change the values a little bit so that it looks good anyway, So this is looking pretty good right now. Let's run army, nor by file and see if it's looking. You have to remember that we have made it 200 pixels on. You can see that agreement vortex is being displayed, but it's not in the middle, and it's not big. So why is that happening? And this is because we have used the same front or here that we have created previously this point. We need to change this on because we have created a new foreign time does known as often. So we're just gonna copy this and paste this instead of foreign don't trend of you're gonna based over in the score for, because this is our new front on this point for used for a score. That's why it's so small. Let's reloaded and hopefully this time it will buck. So let's wait for it to come to 200. Why access on after that is going to show the game or scream. So now you cant hit any off the enemies. So the score is going to remain the constant. So let me just show it to you again. Let me just hit a couple of enemies on now we have bitter enemies, so let's wait for our 200 pixels to get over on Go. It's gonna happen anytime soon, all right? Issuing game over and night because you can't get any more enemies. Your score is going to remain constant. Obviously, you can add more buttons like play again on do stuff like that. But by now you already know how to do it. So I'm not going to go into it again. No final s changes. Now that we know that accord is working into the 200 less change in 24 40 pixels on. Make sure you act the sounds again and make it a complete game. So that is this is pretty much it for this video series we created on space in winter Games from scratch. If you were a big know who didn't know anything about my game are creating games Now. You have a basic understanding off how game is created. It has been wonderful hanging out with you guys. So thanks for watching and see you around.