Pygame Tutorial 17 Game over Space Invaders

alright guys welcome back in the last video we learned how to add sounds to our game and in this video we are going to show the game over screen so I've removed all of these sounds for this video because it's going to be difficult to explain what's going on if I add the sum so what we are going to do is when many of these enemies come close to our spaceship maybe tell over here we're going to remove all of these enemies or maybe just get them out of the screen and we are going to show a big test just like we have shown over here the score 0 we are going to show a big text of game over over here in the middle of the screen and finish this pixel is going ahead when of these enemy is gonna come close to the spaceship when they are gonna hit the y-axis of 440 pixel so if you remember at the top at 0 pixel at the bottom is 600 pixel and I just add the starting of the spaceship it's about 480 pixel but just by experimenting I have found out that 440 is perfect so we're gonna use that for 40 pixel as a limit so winner and means come till over here we are going to show game over for our player and the final score is going to be shown over here so what we are gonna do is we are going to come to our Emmys where we are moving our enemies basically so we are going to come down and come to enemy movement so any movement or was over here and then over here we are just gonna add our text so let's add a text and just call it game over because we are going to be riding the game over codes just below this and what do you want is when whenever an enemy let's enemy why and whenever enemy why of I so whenever one of the enemies it doesn't need to be all of the enemies when one of the enemies come to 440 pixels and actually just to test it out I don't want that needs to come to the bottom so I'm going to make it very very small maybe to 200 pixels and just when we are ending the game and we are finalizing the game I am going to change it okay into for 40 pixels so whenever one of the enemies come to 200 pixels then what we want to do we want to move all the enemies so we are going to create another for loop for J in and then we just gonna copy all of these because we want to move all the enemies out of the screen that's why I am going to create and the for loop inside this big follow and then under this M is going to change the access of nvy J equals to 2000 and this should make sure that these enemies go below the screen to 2,000 by pixel and then after this I'm gonna just make sure that we display the game over text so how do you do that I'm just gonna create a function and this function will be called underscore game over text and we are going to call this function and then we are going to break out of this loop so let make sure that we are not doing anything weird with the brackets and over here we are just gonna write brick and this looks pretty good so what we are doing is whenever our enemy it turns need to be all the enemies when one of the enemies reaches this greater than 200 pixels in this case but it's actually going to be 440 and then we are gonna collect all of the enemies inside this follow and we want each of the enemies to be moved out of the screen and we are doing that by setting the y-axis to 2000 this is not going to be shown on the screen and then we are calling this game over text function which is going to display the game over text on the screen and then we are 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 underscore test functions so we are going to go where we have added our to score so let's just go over here so you can see we have added our score over here so we are going to doing basically the scheme's same thing and we're gonna write game over text over here and then we are going to copy the same thing that we have done over here and instead of font we are going to just write game or maybe we can write over underscore font and we want this font to be bigger so this is the size of the font we are going to made it 64 by 64 pixels the size is bigger and then we are going to create our function so just below this show underscore function we are going to create our game over text function and we are going to do the same thing that we did previously with our show underscore function and then over here let's just copy and paste this line so we are gonna copy this paste over here and then instead of score let's just call it over underscore text and then we don't need all of this stuff we just need to be displayed game and let's make it in capitals just make sure it looks good game over is looking good then we just need to blit it on truant on the screen we're gonna copy and paste this over here let's just press ENTER and paste this over here and instead of score we are gonna write over underscore text and we are not because we are not going to use the x and y values we can use it but because our game worst takes is going to be displayed at one place so I'm gonna remove this and instead of that I am just gonna write 200 250 pixels and this 200 comma 250 pixel is basically the middle of the screen you can try out different values and see what works for you but basically I have divided both of these values by 2 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 our mean dot file and see if it's working and you have to remember that we have made it 200 pixels and you can see that our game over Tex 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 font over here that we have created previously this font we need to change this and because we have created a new font that is known as the ohon so we're just gonna copy this and paste this instead of font on Brenda we are gonna paste over underscore font because this is our new font and this point was used for score that's why it's so small now let's reload it and hopefully this time it will work so let's wait for it to come to 200 y-axis and after that it's gonna show the game over screen so now you can't hit any of 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 and now we have hit our enemies so let's wait for our 200 pixel to get over and it's gonna happen anytime soon all right so it's showing game over and no because we can't hit any more enemies your score is going to remain constant obviously you can add more buttons like play again and do stuff like that but by now you already know how to do it so I'm not going to go into it again so now finally let's change is now that we know what that our code is working instead of 200 let's change it to 440 pixels and make sure you add the sounds again and make it a complete game so guys this is pretty much it for this video series created on Space Invader games from scratch and if you were a big know who didn't know anything about my game or creating games now you have a basic understanding of how a game is created it has been wonderful hanging out with you guys so thank you for watching and I'll see you around

Loading