173,773
Views
Beginner
Level
95
Comments
Crash Course 2: Invaders - Part 15
by Hectate (Updated on 2015-05-02)
Part 15: Final Touches
Step 102: Now that you’ve tested your game and everything works, it’s time to export it to your desktop as a SWF file. That way, you can open the file in any browser to play the game! Open the Publish menu, select Web, Flash.

Step 103: Stencyl will create a SWF file and ask you to choose where to save the file and what to name it.
Congratulations! Now that you have your Crash Course game, you can take on the Challenges that follow, and modify the Crash Course game further, or you can start on your own game! The choice is yours.
Here are a few challenges you could take on if you want to take this project further. We won't provide you with any solutions, it's up to you to figure out how to add these features.
Challenges
Challenge 1: Find a way to make the Enemy Ships move back and forth on screen.
Challenge 2: Restrict how frequently the player can fire the cannon, either by setting a maximum for the number of bullets on screen or by limiting how quickly the player’s Ship can fire bullets.
Challenge 3: Make the Enemy Ships fire back at the Player.
Where do I go from here?
There's a whole lot more to Stencyl, and we encourage you to experiment on your own and read through the rest of Stencylpedia to find out how to import your own resources, create your own Behaviors, and enable Stencyl to help you create the games of your dreams.
Continue to Chapter 2
95 Comments
Challenge spoilers. If you don't want to be told how to finish the challenges, stop reading now.
Challenge 1: Behaviors -> Back and Forth Horizontally
Go to Enemy Ship Actor, click on the Behaviors tab and then add the Back and Forth Horizontally behavior. All the default settings are fine if you're okay with the ships being off the screen every now and then.
Challenge 2: Boolean (read isk8bits comment below)
That allows you to alter how often a player can shoot, but you can do it another way...
Challenge 2: Counting (read gpyles comment below)
This lets you decide how many bullets the player can have currently fired on screen. You can change the numeric value in the If Bullet Counter statement to however many bullets you want to have on screen at once.
Challenge 3:
Firstly, I created a new Actor type and named it Enemy Bullets. I created a new collision group for it and made it collide with both the Players group and the Bullets group. I used the same image file for the animation, but altered the colors so it's obvious the player should avoid them. All you have to do is click on the Actor Type (Enemy Bullets) -> Appearance tab. Then select the first frame, click on Edit Frame (External) on the bottom left and use the paint bucket or pencil tool to change out the colors after the file loads up. Save (CTRL-S) and then x out and do the same for the next two frames.
Now that you have the Enemy Bullets all menacing and evil-colored you can start throwing in some events. I added three events to the Enemy Bullet Actor. Two of which are collision events that make the bullets kill themselves after they hit either the player's Ship Actor or the player's Bullet Actor. The third is to destroy the bullet when it leaves the screen. (Most of the code is recyclable and you can right-click on the blocks to copy and paste, just make sure you alter the necessary bits.)
Now that the Enemy Bullet Actor is fully loaded, we can move on to the Enemy Ship Actor.
In order to make the Enemy Ships fire I added just a single event. I made it a "do every [] seconds" event and set the time to 1.5. Directly under that I added an if statement that checked to see if the Enemy Ship was dead or not and then I used the same block of code from the player's Ship for firing bullets, but changed yDir to 1 instead of -1 (this makes the bullets fire down instead of up) and changed create Bullet to "create Enemy Bullet" (the Actor we just made a minute ago).
The last step is to make adjustment to the player's Ship. Firstly, you'll want to go into the Ship Actor type and click on the Physics tab. Here, you want to select "Cannot be pushed" under "What kind of Actor Type?". This is so the Enemy Bullets don't push the player's Ship off the screen.
Now, we need to add the three events that were added to the Enemy Ship in the tutorial, but slightly modified for the player's Ship so it interacts with Enemy Bullets.
That should do it. Good luck everyone.
-Denuo
2
for the second challenge try creating a bullet boolean that sets to false .1 seconds after the bullet key is pressed.
Then below the last do after put in a do after .5 seconds that sets bullet boolean to false.
finally put all your coding inside an if statement with Bullet oolean = false
should look like this
when action1 is pressed
if Bullet Boolean = false
create bullet at x: ....
push last created actor sharply....
do after .01 seconds
set Bullet Boolean to true
do after .5 seconds
set Bullet Boolean to false
You can change the times depending on how you want it to play out
0
I was able to get the enemy ships moving using the 'Back and Forth Horizontally' behavior so that was pretty easy!
To limit the number of bullets I created an attribute [Bullet Counter] on the player 'Ship' and then incremented by one when the bullet is created [Events - Actor Created] and decremented by one when the bullet is killed.
Then just added an [If Bullet Counter <= 1 ] around the Keyboard event block to limit the number of bullets on the screen to two.
It did take a little while to realize where I needed to add the attribute for the bullet counter. I had originally tried doing most of this on the Bullet actor but when I realized I needed to add the condition block to the code that accepted the keyboard action I moved everything to the ship actor.
Really liking Stencyl so far.
Now on to getting the enemy to fire...
1
So I got the ships to move back and forth, and down, but any movement causes the game to crash after about 10 shots or so... Ideas?
0
Also, I like these challenges at the end.. but without showing us a solution for them (even as a link to another page) ends up being kinda frustrated as I can't figure out what I've done wrong. Gunna skip ahead instead of banging my head on some of these..
0
Thanks for this entire tutorial. A couple parts could... really use some revision. A lot of very vague text and typos. Thankfully the comments section never failed me once. :)
0
How fun! My 5 year old son and I did this together and had a great time. Now we are going to try to build the dragon shooting at letters game that my son thought up.
1
Hey, why is my ship is on the top left side, and disappear when i go left, and cant go to right? :(
0





