Create a flash game like Security - part 3
Filed Under Flash •
Time to do what you asked for a while: the 3rd part of the Security Flash game creation, covering the exit and some more features.
First of all you should read parts 1 and 2, then follow me and learn to create some interesting things.
Exits
Most of you asked for exits, and here they are. First of all, it's very important to consider one thing: when you design a game with more than one level, it's very important you do not allow the player to skip levels with the "Forward" or "Step forward one frame" or whatever you call the Flash function to advance frames.
You can't place levels on every frame or you are making levels that will give no fun because they may be skipped by the player.
There are several ways to do this, I'll start with the easiest to code. Let's proceed step by step
The first thing you need to do is designing the levels, with all the objects in them: hero, cops, exit, walls, and so on.
I am designing very simple levels because level design is not the aim of this tutorial.
These are the movieclips I have on my library:

A brief explication:
Cop: the cop... actually unused in this tutorial but you will need it to design your own levels
Exit: the exit, the item that will bring you onto the next level
Hero: it's you! it's you!
Level 1: The WALLS of the first level. Read carefully: WALLS and nothing more.
Level 2: The WALLS of the second level. I flipped the first level because I am lazy. You should design your own.
Levels: This is the core of the game. It's a movieclip where I put the levels themselves. I could have placed them on the main scene, but in that case the player would skip using the forward function I mentioned above. It's very important that all your game is on one single frame. So I put all levels in the levels movieclip, then I dragged the levels movieclip in the stage.
Here it what I did:

This is the timeline of levels movieclip. Every frame has just a "Stop()" on it.

And this is the content of the 2nd fame in the levels movieclip. As you may notice, I dragged the level2 walls, the hero and the exit. It's very important that you instance all the objects on the stage as I did, for example, for the walls (see the red circle).
Now that I have all (two) levels, it's time to write down some actionscript.
The following actionscript are to be attached to the two heros... the one on the first frame and the one on the second frame
First level
-
onClipEvent (load) {
-
power = 2;
-
radius = 6;
-
}
-
onClipEvent (enterFrame) {
-
if (Key.isDown(Key.LEFT)) {
-
_x -= power;
-
}
-
if (Key.isDown(Key.RIGHT)) {
-
_x += power;
-
}
-
if (Key.isDown(Key.UP)) {
-
_y -= power;
-
}
-
if (Key.isDown(Key.DOWN)) {
-
_y += power;
-
}
-
while (_root.levels.wall.hitTest(_x, _y+radius, true)) {
-
_y--;
-
}
-
while (_root.levels.wall.hitTest(_x, _y-radius, true)) {
-
_y++;
-
}
-
while (_root.levels.wall.hitTest(_x-radius, _y, true)) {
-
_x++;
-
}
-
while (_root.levels.wall.hitTest(_x+radius, _y, true)) {
-
_x--;
-
}
-
if (_root.levels.exit.hitTest(_x, _y, true)) {
-
_root.levels.gotoAndStop(2);
-
}
-
}
Second level
-
onClipEvent (load) {
-
power = 2;
-
radius = 6;
-
}
-
onClipEvent (enterFrame) {
-
if (Key.isDown(Key.LEFT)) {
-
_x -= power;
-
}
-
if (Key.isDown(Key.RIGHT)) {
-
_x += power;
-
}
-
if (Key.isDown(Key.UP)) {
-
_y -= power;
-
}
-
if (Key.isDown(Key.DOWN)) {
-
_y += power;
-
}
-
while (_root.levels.wall.hitTest(_x, _y+radius, true)) {
-
_y--;
-
}
-
while (_root.levels.wall.hitTest(_x, _y-radius, true)) {
-
_y++;
-
}
-
while (_root.levels.wall.hitTest(_x-radius, _y, true)) {
-
_x++;
-
}
-
while (_root.levels.wall.hitTest(_x+radius, _y, true)) {
-
_x--;
-
}
-
if (_root.levels.exit.hitTest(_x, _y, true)) {
-
_root.levels.gotoAndStop(1);
-
}
-
}
As you may notice, these scripts are the same of the ones you saw in previous tutorials, with the only exception at lines 30-32 where I check for a collision between the player and the exit to make the level advance.
Here it is the game, and you can't skip levels!
2nd angent
As a bonus, I will introduce a new feature: the female agent! In every spy story there is a woman, and here it is... look how does her affect gameplay
The aim of the new game is simple: you control two spies, you will move the red one pressing Ctrl + arrow keys, and the pink one pressing Shift + arrow keys. If you press Ctrl + Shift + arrow keys, nothing will happen!
You pass the level when both spies reach the exit
Here it is the actionscript for the first level, for red and pink spies
Red spy
-
onClipEvent (load) {
-
power = 2;
-
radius = 6;
-
can_exit = false;
-
}
-
onClipEvent (enterFrame) {
-
if (Key.isDown(17) and !Key.isDown(16)) {
-
if (Key.isDown(Key.LEFT)) {
-
_x -= power;
-
}
-
if (Key.isDown(Key.RIGHT)) {
-
_x += power;
-
}
-
if (Key.isDown(Key.UP)) {
-
_y -= power;
-
}
-
if (Key.isDown(Key.DOWN)) {
-
_y += power;
-
}
-
}
-
while (_root.levels.wall.hitTest(_x, _y+radius, true)) {
-
_y--;
-
}
-
while (_root.levels.wall.hitTest(_x, _y-radius, true)) {
-
_y++;
-
}
-
while (_root.levels.wall.hitTest(_x-radius, _y, true)) {
-
_x++;
-
}
-
while (_root.levels.wall.hitTest(_x+radius, _y, true)) {
-
_x--;
-
}
-
if (_root.levels.exit.hitTest(_x, _y, true)) {
-
can_exit = true;
-
if (_root.levels.spy_woman.can_exit) {
-
_root.levels.gotoAndStop(1);
-
}
-
}
-
}
Pink spy
-
onClipEvent (load) {
-
power = 1.5;
-
radius = 6;
-
can_exit = false;
-
}
-
onClipEvent (enterFrame) {
-
if (Key.isDown(16) and !Key.isDown(17)) {
-
if (Key.isDown(Key.LEFT)) {
-
_x -= power;
-
}
-
if (Key.isDown(Key.RIGHT)) {
-
_x += power;
-
}
-
if (Key.isDown(Key.UP)) {
-
_y -= power;
-
}
-
if (Key.isDown(Key.DOWN)) {
-
_y += power;
-
}
-
}
-
while (_root.levels.wall.hitTest(_x, _y+radius, true)) {
-
_y--;
-
}
-
while (_root.levels.wall.hitTest(_x, _y-radius, true)) {
-
_y++;
-
}
-
while (_root.levels.wall.hitTest(_x-radius, _y, true)) {
-
_x++;
-
}
-
while (_root.levels.wall.hitTest(_x+radius, _y, true)) {
-
_x--;
-
}
-
if (_root.levels.exit.hitTest(_x, _y, true)) {
-
can_exit = true;
-
if (_root.levels.spy.can_exit) {
-
_root.levels.gotoAndStop(1);
-
}
-
}
-
}
Lines 2 (of both scripts): Notice how the pink speed is slower than the red one. Women always slow down men!
Lines 4 (of...): A boolean can_exit variable is set to false. It means the spy cannot leave the level
Lines 7 ...: In order to move a spy, check if the Ctrl key is pressed and the Shift key is released or the Ctrl key is released and the Shift is pressed
Lines 33-38: When a spy reaches the exit, his can_exit flag is set to true, and I check if the other spy can exit. If both spies can exit, then advance the level.
Here it is. Play and have fun. Lots of features and code optimization will wait us, but at the moment I hope I gave you a good idea for a future game.
Download the source codes and have fun.
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
33 Responses to “Create a flash game like Security - part 3”
Leave a Reply

[...] April 29th update: part 2 released July 27th update: part 3 released [...]
[...] July 27th update: part 3 released [...]
Really nice tutorial. You inspired me to create a multi player game like this. Again, good tutorial.
But if the girl hits the exit and then leaves and than the boy hits the exit they don’t both hit the exit and still go to the next level, so I think you should make a else statement that says: can_exit = false;
wow, theres gonna be another tut right? This seriosly can’t be the last.
coool!!
but i will be waiting for line rider 5
oops…line rider part 6
I didin’t get the ‘how to not skip level’ thing, can you explain it better for me?
Great tutorial, could you show us how to put in mirros and other different types of walls.
sorry i meant mirrors not mirros, i’m bad at typing
the last example isnt working
My exit isn’t working and i have no idea why? any suggestions?
hey gold fish
why dont you put the instance name as exit
the one on the work area click on it then properties > instancename
I finised making my game
and emanuele,
my dad wants to thank you for teaching me all this
why?
cuz i Am still 10 years old and i know how to make a game
again thank you
and i have finised making my game
where can i host it?
How do I make it so when the cop sees the hero (meaning when the line is hitting the hero), how do I make it so that he resets..even better how can I make it so that once the cop sees him, if he sees him for like 2 seconds it resets…
nice tut. can you tell me how to create level passwords? that would be helpful =D
Oh man you gotta finish this tut! Didn’t really feel like you where finished teaching us about the cop!
Love the tutorial but i can’t make my cop patrol please can you advice me on what i have to do?
Hy thanx.
Im still in college and for my final assignment im required to do a flash game, i had no idea where to start.
your tutorial realy helped me alot
Can you show me how to make the character have stealth? Im trying to make a level where if you press the CTRL key then the character partially disapears, but when i let go he doesn’t return to normal.
thanks
I need Help!
I have fixed up the glitch that you couldn’t return to normal but when I hit the cops nothing happens.
can u tell me how to make it so if i hit the cops line of sight in stealth the stealth starts to disappear and if i hit the cop in stealth it restarts and if i hit the line of sight without stealth it restarts in the next tutorial?
Thanks.
almost forgot.
instanced cops body as “hitter” and cops line of sight as “los”
and their inside a movie clip instanced as “cop”
Miguel, two good places to host your games are newgrounds and kongregate. You’re gonna need an account on one of them, but i personally prefer newgrounds because the rating/voting system is more organised. good luck!
Good tutorials, but I hope there will be another ‘Part 4′ for it that covers about the CCTV, switches, and some other features in security.
Anyways, thanks for the tutorials :)
Hey, I’m trying to make 2 exits. Anyone know how to do that?
hi… i am doing your cool tutorial, but when i did it in the levels movieclip, the hero can walk throug the walls and i cant undestand why, becaurse i did everything as you wrote in the toturial…I have remembered to name all the instances i hope you will help me:-)
(sorry for the bad english :-S)
the same thing happened to me, its probobly that your characters size is too big, try making it smaller.
Hey. The “making it so you can’t skip though” thing didn’t work, so I decided not to use it, as it’s only for a school thing. However, I would like to know how to make it so that when he touches Exit, it takes him to the next level, as your code depends on the “making it so you can’t skip though” thing working, and mine is different. Please help.
hello i commented on part 1 i have a chracter that is slightly more sophisticated i need help creating shooting bulets in all 8 (or atleast 4) directions. also i need u to explain how o put a cop on a line route idk how to do that.
but shooting i cant make him shoot i have a bullet but all the actionscripts ive tryed when i hit fire my bullet sits in the middle of my character and doesnt go forward!!! i really needyou help and i wud greatly appreciate it if u cud reply by turs..2 day from now as i am on spring break and trying to make headway on my game. thank you sincerly johnny
johnnyracket@yahoo.com
hey anybody no how to make a character shoot bullets in 1 dif directions? if so plz paste action scripts or email me them i need for my game. thank you johnny
johnnyracket@yahoo.com
p.s. sorry for posting so much emanuele and others but i really ned help ive hit a major stal and it stinks
Hi Emanuele!
I’ve recently made a flash game with help from you tutorials forthe security game.
I hope you like it!
The link below leads to the game itself.
http://www.ebaumsworld.com/games/play/601156/
Hey, nice game TimeSniper:) It was kinda addictive so i had to play it through. What about the highscore in the end? Is it some kind of high score module or is it in your game?
Nice tutorials too, maybe i will make a security game some day :)