159,609
Views
Beginner
Level
60
Comments
Crash Course 2: Invaders - Part 14
by Hectate (Updated on 2015-05-02)
Part 14: Winning the Game
We now need to create an Event for our Scene that will let the player win. It will check how many Enemy Ships are left, and if the player destroys all of them, the Event will show a message on screen.
Step 95: To start, select our Level One Scene from the Dashboard, click the Events button, and Add Event for when Member of Group Is Created or Dies.
Step 96: Select the Enemies Group from one dropdown and the killed option from the other, as shown below.
Step 97: Next, create a Number type Attribute called Victory Counter.
Step 98: In the Event block, add an increment block, and set it to increase the Victory Counter Attribute by 1.
Step 99: Next, create a When Updated Event (which, as usual, creates an Always block). In it, add a boolean block (the "if" found under Flow > Conditions) that checks whether our Victory Counter Attribute is equal to the number of Enemies in our Scene.
Step 100: Now we need to create another Attribute that we will use to “switch on” the text that will display when the player kills all the Enemy Ships.
- Create an Attribute of type Boolean called Win?
- Select the Setter block for this Attribute (under Attributes -> Setters)
- Put a true block inside it
Step 101: Lastly, we need to add a When Drawing Event (under Basics). This will let us actually draw the text onto the screen.
- Add the When Drawing Event
- In the Drawing category, grab the set current font to [ ] block under the Styles subcategory and place it inside the When Drawing block.
- Drag over an if block, and place the Win? Attribute block in it.
- Lastly, drag over a draw text [ ] at x [ ], y [ ] block and place it inside the if block. For the text to show, simply type in "You Win!"
- Set the coordinates for X and Y to 300 and 240 for now.
Notice that you can move your mouse cursor around in the Scene to find the best coordinates to choose - you can see the coordinates in the lower right of the Scene Editor (as shown below). Keep in mind that text positioning is determined by the left-side of the text so we are beginning our text at the center of the screen, not centering the middle of the text.
Save and test your game. You should end up with the following once you destroy your enemies.
Keep in mind that we're setting exact coordinates for where the text should appear. If you change the game window's (viewport's) size to something other than a Width of 640 and a Height of 480, you'll have to adjust the X and Y values shown so the text is located where desired. Also, there are better ways of aligning text so that it is automatically centered, but that is beyond the scope of this article.
60 Comments
I can't see how I can make the increment block to Victory Counter since it only shows numbers... Help plz.
1
It is saying taht we have encountered errors when we try to test it. Is there anything that we can do to fix it? Thanks!
1
the winning notification doesnt appear, I already read the instruction over and over again but still i dont know whats wrong, help mee
0
Yay finally course finished took me a lot of time ( 2 hours )
I wonder if i can make games like cave story now?
lol still dreaming
1
I solved a different issue with the display message. It turned out my 'Enemy Ship' was never set to the 'Enemies' group.
It's still possible to increment by the 'Enemy Ship', it just needs to be incremented under 'Actor of Type' not 'Member of Group'. Works here, but would not make sense for any game involving more than one type of enemy.
I only figured this out by doing a quick debug to display the 'Victory Count' as on screen text - the counter wasn't increasing whenever I killed an enemy ship. Worth giving a shot if you've already changed the font.
2
It seems that the alien doesn't always each hit as a hit. Sometimes pressing fire too quickly seems to make the enemy ignore a hit. Shooting more slowly seems to work. I wonder what the update cycle is? Is there a way to adjust the tick or does the problem lie elsewhere?
0