When we come into the game, we're asking the player to press the start to begin and there's a nice
big green start button which isn't doing a whole lot yet, and that's what we're going to take care
of in this lesson.
We're going to add an event listener to that button.
So adding an event listener, we already have the button object as a BTM are variable BTM.
So we're listening for a click on the button and when the button is clicked, then we can launch our
start game function and now we can create start games.
So start game function.
We're not passing in any parameters.
And the next step that we want to do is we actually want to hide this start button and we also want
to hide the message because we don't want we don't need to have any of that information being sent to
the player.
So take that message object.
Apply a style property to it in the style property is display setting display to none and then also
taking button applying style display and equaling that to none as well.
So let's try that.
And remember, this is the player coming in.
We've got some instructions for them.
Press start to begin and a start button.
So we make that button and when they click the button, we've started the game.
So we basically need to hide that option to start the game again.
So this is where we set up some of the player values and we're going to create a global object.
Just call it player and we can leave that blank for now.
So this gives us the ability to add content in there.
And also, if you want, you can set up some values within there so we can have score and set score
to zero.
We can have the total that guys set that to zero as well, just comma separated because it's an object.
Another important variable that I usually use within games is in play.
So this is our controller to start and stop the gameplay.
So we're going to set that to not zero, but we can set it to false.
And then when the game is in play, then we're true and we can constantly check that.
And the more variables you make, the more adjustments and tweaking you can do in the more interesting
you can make your game.
So try to make it as dynamic as possible.
So loading in things like speed is really helpful.
If you want to adjust the speed, then you know you've got that one variable and everything's contained
within the player object and you can update that as needed.
So we can also make sure that the player score is zero.
And this is also going to give us replay ability so we can restart, restart the game if necessary.
And we also want to update that score value within the player's visible area.
So we're going to set up a function so we can just call that score update.
And what this will do is this function will take the score, the element with the class of score and
update its text content and equal that to whatever the value of player scores.
So that's all that one is going to do.
And we can add in additional functionality if needed.
And I would suggest to call this every time you make an adjustment to the score.
So just make that request to that function.
And we also want to update the number of bad guys that are left.
So that was the other value that we had here and updating it.
So we've got our player and we can we've got one called Total Bad and we can set that to whatever number
we want.
So this can be the starting number for the number of bad guys.
And you can also have both of these updates at the same time.
So this is something that we can do, and it probably makes more sense that we have both of them within
that same function so we can have a score update.
And this will also update the number of bad guys.
So instead of selecting the object score, we're going to select the element that is referenced with
bad left and update the text content with whatever the value of total that is.
And this should actually be score output.
That's the name of the object.
So make sure that we get that correct so I can try that out.
And when we press start, we see we've got enemy left ten and our score is updated to zero.
So ready to start the game.
So what else do we need to do in order to build the gameplay?
We need to create the bad guys, so create the bad guys.
And we also have to launch animation.
So within the animation, this is where all the action is going to take place.
And then one last thing.
We're going to take player inplay and we're going to set it to true.
So that will start the gameplay.
So launching the animation setting player in play to true.
And we can actually move this one up as well to here as we're updating the player object.
So ready to move on to the next step where we're going to create the bad guys and we're also going to
launch the animation and we need to add a few other things before we continue.
And that's adding in event listeners for the.
So that's still all to come in the upcoming lesson.