Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
This game is coming along nicely, but what it's really missing is it's missing scoring and various levels. So if I click Play, as I destroy these UFOs, the score, nor the level will add up. There will be nothing in here. So my goal is to go ahead and populate those two text fields. So let's take a look at them. I am going to turn off these three layers: the introScreen, options menu, and the endScreen.
There is right in here for this text layer, if I just select the Zoom tool, I am just going to zoom in on that text here, just use my Selection tool to select these text fields. Let's take a look at them. If I select this score text field, I'll go to the Properties panel. Now notice that this text field, its instance name is score_txt. It's set to Classic Text and it is a Dynamic Text field. So I want to dynamically update the score as I sort of destroy those various enemies.
Also notice that the Font Family is just _sans. So it's going to use the default sans serif fonts regardless of the device. Not only that, the size is about 24 point, which seems large normally, but it's going to look great on the phone. Same thing for my Level text field. If I select it, its instance name is level_txt, it's a Classic Text field set to Dynamic Text, and has the same Character properties as well. So I am going to start basically with the score right here.
So I am going select it. The score_txt is what I am going to keep in mind, and I am going to select that first frame in the Actions layer and open up the Actions panel. So at the top what I have is I have this variable called level currently, and it is a number, because I am already actually using that and I'll show where that is. But what I want to do is I want to add another variable called score, and it's also going to be a number, just like that. All right, let's see where level is being used.
So I'll just scroll down, because when the game gets initialized, the level starts out equal to 1. Well, what I want to do with that variable is I want to put that number actually in the text field. So level_txt, its Text Property is going to be equal to the level number. I wrapped that in String because what it does is it takes this, which is normally known as a number, and it converts it to a string, so it just treats it as text, since it's going in a text field.
Again, I want to work on the scoring, so score is going to be equal to 0. So start out at zero, and then for the Score text field, its instance name is score_txt. Its text property, same thing. All right, so they both start out when it initializes, Level is going to be 1, the Score is going to be 0. And for the score, each time the laser hits one of the enemies, I want to add to the score. So let's go ahead and take a look at that. As I scroll down, for moveEnemies, I can see them move test for collisions. Right down in here for test for collisions I have is this.
So when the laser hits the enemy, not only does it make an explosion, does the enemy get removed, the laser gets removed, but right in here, add to the score. That's what I want to do. And I do that just by typing in score++, and what that means is is it takes whatever the score is and it just adds one to it. So that's just adding one to the score. The next thing I need to do is for the score_txt, for that text field, go ahead and update it with that score variable.
So it adds to the score and then it gets put in the appropriate place. So the score is all squared away. What about the levels? Where is that being used? Well, let's take a look. Let's scroll up, because when the enemies are created, this is where the level is being used. So remember, this is initially set to 1, and I will just undo that. But know that each time basically the enemies are being made, there is a chance that maybe, what, two enemies will be made, each time this function is called, so that's how that works, and that's just for the first level, there's maybe only two enemies that are going to come down.
But as the levels go on, I actually want more enemies to be created, and that's why if I undo that, it's going to add say level at--let's say it's going to had 2 to it level two, so there is a chance that three enemies will come down as well. So that's the number of enemies as the game progresses, as you advance in levels. Well, how do you advance the levels? So I will just undo that because what I want to do is I want to go ahead and right down here in the check for end, testForEnd, right here in line 276, testForEnd, right in here, this is what I want to do is want to go ahead and advance the level if they reach a certain score.
So right in here, I am going to go ahead and type in if the score, if it's greater than 10 for instance, then I can go ahead and advance the level. So if the score is greater than 10, advance the level. So that will be equal to 2 the first go round, and then also update the text field whichever level you are at. Okay, so that's if the score is greater than 10, then advance the level. But I always want this to be greater and greater as well.
So the first go around for level one, you only have to kill 10 guys. For level two, you have to kill 20 guys. So what I need to do right in here is just--I'm going to type in level*10. Multiply it by 10. Okay, so this makes each level a little bit harder, and it's going to be 10 the first level, 20 the second level, 30 the third level, and also more of the enemies come down as well, and of course that's updated in the text field. So that's how we deal with multiple levels.
It gets a little bit more advanced because more of the enemies are generated, and also I'm also adding to the score. So let's go ahead and test this. I'll click Play, and let's watch the score and the levels.
So I've just right-clicked on this SWF file, just to pause it. So you can see, I have a score of 23. I am now actually up to level 3, which is great. That's exactly what I want. So the thing I need to do next is I actually need to give my guy a number of lives, and they get subtracted as these UFOs reach at the bottom, because as it stands right now, I can just play all day racking up my score with no consequences.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97212 Viewers
61 Video lessons · 84503 Viewers
71 Video lessons · 68706 Viewers
56 Video lessons · 101188 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.