169,816

Views

Beginner

Level

94

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.

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

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

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!

94 Comments

sarendo
Im kinda stuck at challenge 3. People who posted sollution for challenge 3 is probarly right. But for ppl like me who isnt very experienced would need a very detailed solution like what block goes in what block and where you find the blocks in the palette.
0 12 years, 4 months ago
amadeus111
CHALLENGE 2: ship`s behavior>control>fire bullet> choose bullets as actor type
click limit bullets alive, set to 1 bullet/sec

0 12 years, 5 months ago
Losian
To those whom are working on the challenge:

Are you having trouble with your player ship's health not decrementing properly?

If you use the debug block 'print (anything)' and have it print your player's health(hit `~ in game to see the debug console), you can probably figure out why, or at least find where the problem is!

The collision in Stencyls is a bit weird. Even if the VERY first thing that happens on collision is to kill the actor, it will sometimes collide more than once - this can result in your player losing two or three hitpoints every time a single bullet hits.. sometimes! It's very hit or miss, and confounded me with another project.

You can keep this in mind and work with it down the line, or take the challenge a step further - can you configure a method which prevents the player from taking more than one damage from each bullet collision due to stencyl's engine weirdness?

0 12 years, 5 months ago
DaLeah
For Challenge 1: Under the Behaviors tab for Enemy Ship we did Motion and then Back and Forth Horizontally.

If you limit the left or right directions to 45 they stay on the screen.

If you check Change Direction on Collision, then they will move oppositely when being hit by bullets or each other - kinda NEAT!

1 12 years, 5 months ago
Losian
For those attempting this:

For the first challenge, you can use the built-in horizontal side to side movement, or prebuild your own using X-speed and Negate X-speed, drawing from the player's movement.

The harder part is getting the ships to collide/shift direction with one another, or to not fall off the screen. I ended up just using timed loops to have them wander back and forth in a synchronous fashion.

The second challenge I also used a time loop, essentially incrementing an attribute "CanFire" by 1 each time they fire, then decrementing it .1 second after, essentially using a sorta of time-based 'cooldown' for each shot, and restricting the shots by that merit. I tried some other methods, such as attempting to count bullet actors and such, but had little luck.

The third part was relatively simple - do exactly the same thing you did with the player firing, except make it random and not based on a button push! I made a new group/actor each, for enemybullets, and spawned them based on the enemy ship's x and y (but y plus some so it didn't spawn on top of them) and pushed in the positive Y direction. Setup the collision for the enemybullets group versus player, adjust the player to not be pushable so they don't bounce around when hit, and you've got a good start.

The tricky party was making the enemies fire at alternating or random patterns: I basically ended up making a do-every 1 second loop, within which a do after X time is nested, with the X time being a random float between 0 and 1, so each ship will continuously fire each 1 (0..1) seconds, which made them not fire in tandem. Also, I turned the enemybulltes actor after being spawned 180 to avoid it facing the wrong way. :)

Dunno if this will help anyone, but hey.

2 12 years, 5 months ago
Egg Dragon
@HaD23:
Did you find a solution to your rapid-fire problem? I was having the same trouble, but after some tinkering around I was able to solve it. As Denuo said, create a new "Ever N Seconds" event on the event tree for your enemy ship. Then insert a "Do every [] seconds" command in the event field (I used a random number between 3 and 6 for mine, rather than a fixed value). Within the "Do every [] seconds" brackets insert the "Create Actor" command followed by the "Push Actor" command, just as you did for the player's fire. That should limit the enemy ships to firing a single shot at random intervals of 3-6 seconds.

0 12 years, 6 months ago
HaD23
Hey guys...i did challenge 3 as DUENO said.but the problem is that my enemy space ships start firing like machine guns(just like these dots............................... ................)not after 1.5 seconds!!!!
0 12 years, 6 months ago
linkisnotzelda
I made it fire back and kill player and whatnot but when the player dies I get this error...

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at stencyl.api.engine.actor::Actor/get X()[/home/stencyl/stencyl.net/jenki ns/jobs/StencylWorks-Dist/workspace /plaf/flash/root/stencyl/api/engine /actor/Actor.as:1645]
at Function/<anonymous>()[C:\Use rs\Eric\AppData\Roaming\Stencyl\ste ncylworks\preview\scripts\ActorEven ts_2.as:72]
at stencyl.api.engine::TimedTask/updat e()[/home/stencyl/stencyl.net/jenki ns/jobs/StencylWorks-Dist/workspace /plaf/flash/root/stencyl/api/engine /TimedTask.as:46]
at stencyl.api.engine::GameState/inner Update()[/home/stencyl/stencyl.net/ jenkins/jobs/StencylWorks-Dist/work space/plaf/flash/root/stencyl/api/e ngine/GameState.as:1661]
at stencyl.api.engine::GameState/postU pdate()[/home/stencyl/stencyl.net/j enkins/jobs/StencylWorks-Dist/works pace/plaf/flash/root/stencyl/api/en gine/GameState.as:1511]
at stencyl.api.engine::GameState/updat e()[/home/stencyl/stencyl.net/jenki ns/jobs/StencylWorks-Dist/workspace /plaf/flash/root/stencyl/api/engine /GameState.as:1493]
at org.flixel::FlxGame/update()[/home/ stencyl/stencyl.net/jenkins/jobs/St encylWorks-Dist/workspace/plaf/flas h/flixel/org/flixel/FlxGame.as:407]

1 12 years, 6 months ago
Beaverdog
wouldnt minding know how you could add a firing sound when you fire your bullets.. hmm tried adding an event for bullets actor when created to play a sound which i imported but i get lots of errors text when i press Z to fire
1 12 years, 7 months ago
Denuo
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 12 years, 8 months ago

Sign In to Comment