As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

159,870

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.

http://static.stencyl.com/help/images/cc2_add_actor_dies_event.png

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.

NOTE: If you have fewer (or more) than 5 Enemies in the scene, be sure to set the number to that value, not 5!

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.

  1. Create an Attribute of type Boolean called Win?
  2. Select the Setter block for this Attribute (under Attributes -> Setters)
  3. 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.

  1. Add the When Drawing Event
  2. In the Drawing category, grab the set current font to [ ] block under the Styles subcategory and place it inside the When Drawing block.
  3. Drag over an if block, and place the Win? Attribute block in it.
  4. 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!"
  5. 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.

http://static.stencyl.com/help/images/cc2_you_win_message.png

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.

Let's move on to Part 15.

Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

60 Comments

Allerises
The first 4 enemies that I take down take damage at every bullet hit, however, the 5 onwards, they seem to not take damage every time I hit them with a bullet
1 9 years, 11 months ago
Slader
FOR ALL OF YOU THAT ARE HAVING TROUBLES WITH THE VICTORY MESSAGE:
I had a similar problem, but I figured it out. No, it's not that you need to have exactly 5 enemies (but if you have a different number make sure the Win? block is true when the Victory Counter is the number of enemies your games have). Go back to your Default Font tab. There should be a sub-section in that tab that allows you to choose the color. Make sure the color is a visible one! Mine defaulted to black, which made it nearly invisible. I'm guessing this will fix the majority of the problems.

6 10 years, 4 weeks ago
Flonaldinho
The whole Tutorial worked fine for me until i came to this chapter. At the end when i tried to test i also got an error with my "win?" block. I read the given instructions again twice and didn't noticed something that might cause this error.
(Because the following is only in the picture but not written down in the text):
When i was looking exactly to the picture i noticed a small difference between my 'when drawing' block and the one shown here.
When you drag over the "set current font to [Font]" Block you have to change [Font] to your created "Default Font".
This fixed the error for me.
Maybe thats how to fix the error you get DanoStarkG.
At least it worked for me.

1 10 years, 1 month ago
DanoStarkG
Help!
When i try to test it it says that an error occurred and it's with the block of [Win?] anyone knows whats wrong?

0 10 years, 1 month ago
alexmitchell1
You need to have at least one tenth of a second delay between you hitting them and the enemy dying otherwise the bullets stay in the air
0 10 years, 2 months ago
tenderlions2011
I fail this course, at the end i couldn't figure out how to make the victory text pop out so i give up!
2 10 years, 5 months ago
abdullahbhatti
When I hit enemies on right the are killed easily but on left side with too many bullets and for destroying bullets add event to enemies kill self and change to kill last collided actor
0 10 years, 6 months ago
r4nsack
when my enemies are killed they disappear but the bullets stay on the screen. However, the bullets do disappear when hitting the enemy the first and second time... help... please.....
0 10 years, 11 months ago
eoghandunne
I couldn't get the You Win! to come up because i only had 4 enemies on screen. So make sure you have 5 enemies to reach victory attribute and it works then.
0 10 years, 11 months ago
darrellsims99
Wow now I feel all stupid lol i figured it out haha. for futer people who can't figure that one out you go to the Add Event button on the left, then scroll down to actors, then on the very top column of the actors part click the members of group and that orange clip thing should pop up.

0 11 years, 4 months ago

Sign In to Comment