My First Game - DnD - Score, Lives & Effects - Space Rocks (Part 4)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to the fourth tutorial for making space rocks in drag and drop so today I'm going to be adding the score and lives and also the different rooms in the game so let's get started and the first thing I'm going to do is make a new object and I'm gonna call this obj game and this object is going to be more of a system object it's not ever going to be visible to the player but it's going to be controlling things behind the scenes so let's come up into its create event and in here we're going to set up the score and their lives and now I could do this in the player objects but since we're destroying the player object that means all of its variables will also be getting destroyed and then also resetting but if we have the game object managing everything then we're going to get those variables to persist even when the player dies so in here let's add a score okay so let's drag in score set the score and we'll keep that at zero for the start and now for lives so we want to set the lives drag that in and let's just so that's a three for now and now let's go into its drawer event so that we can actually draw these elements to the screen so again let's type in school and let's draw the instance score so drag this in and this is the caption that will appear before the score so it would say score and then a number and let's just draw that at 2020 in the room so that should be right at the top but just down 20 pixels horizontally and vertically and now for the lives let's drag that in and for its location we'll draw it at the same X but another 20 down and now we could draw just the text but with this function we can actually draw a sprite to the screen so we could draw something like Zelda's three hearts or three little ships so let's do that let's make another sprite that will be our lives and again you can draw anything you like in here I'm gonna make mine 24 by 24 and draw a ship there you go that's my lives and I've just left a bit of padding around the sprite because we're actually going to be drawing this fright right next to each other for the three lives and we want a bit of space between them and I'll leave it at the top left for the Anka just so that we're drawing it kind of like the text is anchored to the top left alright so that's it that's fright to SPL lives we do want it to stack horizontally which means it'll draw it in a horizontal line let's just put this into the game so drag it into here and this object like I said isn't going to be visible so it doesn't really matter where you place it but the convention for objects like these is to put them at zero zero at the origin all right so let's give that a run and there we go so you can see our scores coming up and we have our three lives so the moment is actually just drawing with the default font but we can make our own one so first off let's just make that font so it's coming to fonts create new I'll just call that FNT text and you can set this as whatever you like I'm gonna use Gonzales and I'll just change a few things about it to make it look a bit more retro sort of bold it turn off anti-aliasing which just means the more transparent sections of the font aren't going to be visible it'll look a bit more blocky and pixelated and now we just have to set that bond so we can do that in the create event and let's just type in font set font and we'll do that here as well so we'll set this to F and D text and from now on whatever text that we draw is going to be drawn using this font so we only have to do this once all right now for the lives in school so for adding to the school it's coming to the bullet object because that's how we had the collision with the asteroid and in here we can set our score to +10 relative to whatever it currently is but hold on a second remember that we're inside the bullet object but the score variable here says that it is an instance variable so different instances can have their own scores so we don't actually want to access the bullet score we want to access obj games score so we're going to have to apply this block so just move it here we'll have to apply this to the game right so then it will be adding ten to the obj game score and we'll have to do the same for the ship so when the ship collides with the asteroid that's when we die then we want to apply to rbj game and we want to take away one of the lives so lives - one relative to what it currently is let's shoot great - the score is going up and when we die one of the lives disappears perfect alright now let's create the other rooms for the game so at the moment we just have our game room but I also want a start room a win room and a lose screen so what I'm going to do is actually duplicate this one because I want a lot of the dimensions to be the same we'll call this RM start and now I want to drag this to the top of the list of our rooms because when you run your game game maker is going to start in the very first room in this order so we want that at the top and now we can take away all of these and I do want the game object to be created in the start room so I don't actually want it created in the game room because I just want to set the score at the start and then I want that object to persist through the different rooms because usually when you transition between the rooms all of the objects from that room is going to be deleted by the time we move to the next room so we'll have our game object persist and we'll just duplicate that again for RM game over and we'll just delete that game object and one more time for RM win alright so that is our different rooms and if you want you can add different backgrounds through them and customize them a little bit but I'm just going to leave them like that for now and I'll just be drawing text in these different rooms so let's come back to the game object and in its drawer event now I actually only want it drawing this stuff in the game room and depending on if it's in the start game over or win room I want it to be drawing different things so we want this object to be drawing different things depending on the room that we're in so we could check if the room is equal to for example the start room and then check if the room is equal to the game room if it's equal to game over if it's equal to room win but another tool we can use that we haven't used yet is called a switch and this can be just a kind of nicer way of setting things out when you have a lot of different cases so we just put switch here and then we put the value that we want to switch so that's going to be the room that we're in so that's a built-in variable that we can use and then we can just say in the case that the room is equal to and then we can just type in the name of the room sir RM game then we want to do these things and then another case so for example if room is equal to room start then we control a bunch of information for the player at the start so for the start room I want to do a few things so now we just want to draw some text to the screen so let's type in text and you can see there's a few different options here so we can draw something to the screen or we can draw it transformed and I won't actually use this one for the title because I want the title to be a lot bigger than everything else so I'm going to put space rocks and I'll draw this at 250 which is just half of 500 100 so it's kind of at the top and in the middle and now I'm going to scale it up by 3 just so that it's a lot bigger and I'll leave the rotation at 0 now for the next thing I'm going to draw score 1000 points to win all right so this is gonna be my win condition for the game and I'll draw this at 250 a little bit down but still in the middle and another one and now just tell the player the controls so remove with up left/right keys and again in the middle and a little bit down and another one press space to shoot - 50 - 60 and finally press ENTER to start and again in the middle 250 all right and you could also add another one down the very bottom which just has your name you could say by friendly cosmonaut or whoever you are all right so now if we run that we should start in the start room all right so you can see that it kind of white it's drawing all of our text in the middle but it is left justified so it's starting off the text in the middle and then it's writing it but we want to send to justify the text sir of this hole right here when we start drawing the text let's set the text alignment which is coming up right here so that's all we need drag that in and we want to set the horizontal alignment to be the center and we can leave the vertical alignment being at the top but whenever you change anything in the drawer event about the alignment just remember to change it back at the end because otherwise it might mess up alignment of other things like this for example so once this runs in the next step if the text is still Center aligned this is going to use the center aligned so we have to remember to set this back to the default at the end which is the left so if we run that again there we go now this is all in white at the moment but if you want to add some color to the text we can set the color just like this so we can drag it in right here and this is setting the draw color so this is the color that is going to be used for anything in the drawer event so if you're drawing shapes or anything so for example I could just set this to yellow and I'll set it back to white here and maybe just to highlight this one will also draw this in yellow and again I'm going to set this back to the default at the end of all of my text drawing so back to white alright so let's give that a run there we go then for the other room cases I'm actually going to be drawing pretty similar stuff so what I'm going to do is actually copy and paste this and we'll just have this as let's do arm game over but instead of space rocks I'll say you lose and then instead of yellow let's do red and I might just change the position a little bit so we're not gonna have as much on the screen I'll keep that scaled up at 3 3 and now let's tell the player what their final school was so that's typing school and we're going to draw the score again but let's say final school and we'll draw it at 250 by 250 and they'll just delete a few of these and I'll just say press ENTER to restart and we'll leave it 250 by 300 all right and we don't technically need this because it's still set to white all right and now let's duplicate this one more time so copy and paste and it's moved to the side but it doesn't actually matter it doesn't matter what order these are in it's just going to check what room is equal to so I guess up here or wherever it was pasted om win so the windscreen will make it green so all green and will say you win and will keep all those variables the same and yeah we can leave all of that the same we probably don't need to tell the player their final score because we know it's just going to be a thousand but if you were tweaking your game a little bit you might want to tell the player their score sir I'll leave it there all right and now for us to actually check if this has worked we need to get the transitions between the rooms working so we know that in our start room just as we've instructed the player we told them that if we press the enter button then we would start the room so let's create an event and we're going to use a key press Enter alright now again depending on what room were in we're going to want this enter press to do different things so for example in the game room we don't want the enterprise to do anything but in the start room we want it to go to the next room and if we're in the game over or win rooms then we want the Enter key to restart the game so we're going to use another switch statement let's type switch and again we're gonna switch the room and we'll check our cases so if the room is armed side then we want to go to the next room so let's type in room and let's have a look at these sir we want to go to a room so we can say go to room and we could type in the exact room or just go to the next room so if you have set the order of your rooms up like this you could say go to the next room which would just be the game room but just to be safe I'm just gonna specify that I want to go to our M game alright and now in the case that it is the game over room then I actually want to restart the whole game so that's restart the game and again let's copy and paste this for the RM win but now to actually get to the room win or the game over room we're gonna have to have some checks for if lives it gets to below zero or if score gets to a thousand and now we want to be checking this all the time in the game room so if if we're in the game room so we're just going to use if the room is equal to I'm game and now we want to check if the score greater than or equal to a thousand then we want to go to the win room but if the lives is equal to less than or equal to zero then we want to go to the GAMEOVER room and just the speed of our testing I'm going to set the score to 990 and lives to one so that we can just check the transition between a thousand and zero and let's shoot something so awesome we went to the wind room let's restart and to go crash into something great so now we've lost senator restart so great all of the transitions between the different rooms seem to be working all right great so that will do us for now and in the next tutorial that will be our final tutorial we're just going to add some flourishes to the game so we're going to have the game object actually spawning in more and more asteroids as we go through the game and we'll be adding some sound effects and some music so I hope you enjoyed the tutorial and I will see you in the next one
Info
Channel: GameMaker
Views: 56,004
Rating: undefined out of 5
Keywords: YoYo, Games, YoYo Games, GameMaker, Game Maker Studio, GameMaker Studio, game, maker
Id: sO06cD0YuPU
Channel Id: undefined
Length: 15min 18sec (918 seconds)
Published: Tue Oct 23 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.