Transcript from the "Game Start and End Actions" Lesson
>> So we want to do is try we have a game of a screen. It'd be cool to also have a game start screen or like something along the the ability to restart the game. A big piece of that is just separating out the logic for starting the game and the actual start of the program.
[00:00:19] So we can pull this off. It's actually super simple, he says have never done it like this version of this game before so say when i receive like a new message game start. Cool, and so that will go in, no, we don't want that, where did my game start go?
[00:00:43] Game, when I receive game start, we'll go ahead and have that actually do the setup motion. So now, when we hit the green flag, we'll just broadcast game start.
>> And then you can add things to it. You can add things like starting things or whatever. Like what the game's called or-
>> Yeah, you can have a start screen that they see beforehand.
>> Like how to play the game or something.
>> Exactly, you have instructions.
>> Just like what I did with one of my games except at so many broadcasts It just got stuck.
>> [LAUGH] Yeah, you have performance issues.
>> It was so complex that it had trouble on performing it, it kind of just got stuck on things
>> There are, as a side note, there's the scratch add-ons and the Chrome extension. And you could actually enable performance tools and debugging and all bunch of other stuff in here as well and like modify and get a whole bunch of other stuff.
[00:01:42] We could actually triage those things as well. So let's see. We don't actually want it to, Stop all just yet, because that will actually literally stop the script, so get rid of that. And what we can do is, we could say, when everyone gets a game over, they all hide, right?
[00:02:05] And so we've got a game start. And so now for everyone involved, Pico knows about this already. And when he gets a game over, we're going to hide him. When we get a game start, we're gonna show him. Now, we could create clones and stuff like that as well.
[00:02:30] I think this will get most of the trick done without getting too in the weeds. So game over will hide them, game start will show them. Go to the snake. Start out by hiding the snake, cause that's not playing yet either. And when the game starts, we'll show it.
[00:02:47] Actually, we can, This part doesn't really matter 'cause it's about when the game starts. So actually we'll see if I regret that. When I receive Game start, we'll show, and when I receive, Game Over, we'll hide. It might want to add a stop the script in there as well.
[00:03:14] We'll find out in a second. Let's just get all the mechanics working. So we'll show the game over. Or hide it when the game starts again. And then we can wait for like an S key or something like that to start the game over again. I can do that only one game over is currently set, or I can just let them restart whenever in case they're like I would like to start from the beginning, let's go with that.
[00:03:50] So let's see, We could do a loop in there. There's a bunch of ways I could do this. I'm going to try this out. Yeah, we could keep track of whether the game has started or stopped. I'm not going to do any of that. We'll just say, if they hit the button, it will give them the ability to start the game over again.
[00:04:14] I think I'm gonna keep it as its own thing, though. Not space bar, though. When A key is pressed, we're gonna broadcast Game Start. All right, let's try this out. I might have to debug a few seconds, but let's see. All right, and so hopefully he gets hit, game over.
[00:04:36] Everything vanishes, right? I could even change the backdrop if I wanted to, to something that makes sense. Did we end up stopping all though? Let's see. I think we gotta stop the script though. Because otherwise you see that loop is still running. So let's go ahead and stop all this, also stop this script or stop other scripts in this sprite.
[00:05:05] Let's go with that. Let's do that here as well. Let's see if that changes things for me. All right, get hit. When I hit game over, we'll show. Clear so far. I might have to debug it for a second but we'll figure out can you start with Hi game over we receive, It worked.
[00:05:46] I was just hitting essence that because I wasn't looking at my keyboard. So now we have the ability we could put a message in there as well. So we get hit a will start the game over again. So now you don't have to constantly go the flag starting stopping start to put different mechanics for levels in there.
[00:06:01] You could show different things so for instance I've got a backdrop where the ground is black. I could theoretically switch backdrops based on levels, right? You also in the dinosaur game after a certain score 500 or so like pterodactyls
>> 200, but isn't there at a certain point it changes tonight to?
>> Yeah, so there's like various different things you can trigger so you're not just bound by the green flag to start and the red stop sign to stop. You can just stop a loop. But then you can also use the messages to restart it. You can do different stages.
[00:06:34] Is and trigger stuff so you can begin to like slowly build. That's why we're kind of going for like a wide range of different techniques. And then depending on the game, you're building the mechanic you want to do, you can kind of like snap different pieces of this together in different ways.
[00:06:48] For the most part, they're like, let's talk about ways we could extend this way before like we have different costumes so every time it starts over, it's maybe of a different height. I chose the snake which is there wasn't a lot of options there, but I could choose, like, I could make a cactus sprite of different heights.
[00:07:01] You saw my little angry, angry little stone things that I was using in a previous one. You could have could rotate a random costume every time. You could have it speed up over time. A lot of the mechanics that we've done in the previous games... I could redo them here.
[00:07:16] But you can sort of put them all. You could actually maybe at some point have to show up. It's up to you, and you should play tests, and you should figure out what works best for you and should definitely explore some of that as well.