Create a flash game like Security – part 3

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:

Security

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:

Security

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

Security

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

Second level

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

Pink spy

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.

  • Pingback: Create a flash game like Security - part 1 at Emanuele Feronato()

  • Pingback: Create a flash game like Security - part 2 at Emanuele Feronato()

  • Really nice tutorial. You inspired me to create a multi player game like this. Again, good tutorial.

  • Maxim-O

    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;

  • Lepynet

    wow, theres gonna be another tut right? This seriosly can’t be the last.

  • abhilash

    coool!!
    but i will be waiting for line rider 5

  • abhilash

    oops…line rider part 6

  • I didin’t get the ‘how to not skip level’ thing, can you explain it better for me?

  • David

    Great tutorial, could you show us how to put in mirros and other different types of walls.

  • David

    sorry i meant mirrors not mirros, i’m bad at typing

  • the last example isnt working

  • Goldfish

    My exit isn’t working and i have no idea why? any suggestions?

  • hi

    hey gold fish
    why dont you put the instance name as exit
    the one on the work area click on it then properties > instancename

  • miguel(lito)

    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?

  • FaceBag

    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…

  • hello

    nice tut. can you tell me how to create level passwords? that would be helpful =D

  • Beans

    Oh man you gotta finish this tut! Didn’t really feel like you where finished teaching us about the cop!

  • Edd

    Love the tutorial but i can’t make my cop patrol please can you advice me on what i have to do?

  • Daniel

    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

  • Randomguy

    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

  • Randomguy

    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.

  • Randomguy

    almost forgot.
    instanced cops body as “hitter” and cops line of sight as “los”

  • Randomguy

    and their inside a movie clip instanced as “cop”

  • Joseph

    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!

  • limpeh

    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 :)

  • Lepynet

    Hey, I’m trying to make 2 exits. Anyone know how to do that?

  • kristina

    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)

  • some dude

    the same thing happened to me, its probobly that your characters size is too big, try making it smaller.

  • Custard

    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.

  • johnny

    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

  • johnny

    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

  • TimeSniper

    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/

  • Nixxus

    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 :)

  • miguel(lito), try kongregate ;)
    (http://www.kongregate.com)
    (you will ned to create an account there)

  • BO-dum

    is there any coding you can use to make the cop follow you i need help plezeeeeeeee

  • flashkid Hao

    you are really awesome. I also have a good i idea. you should make an ‘invisible’ range of hearing so if you get in it, the cop turns around and investigates where the sound is coming from. this also requires another ‘invisible’ movie like a small circle to appear at the spot where you appear in the hearing range so the cop goes to that spot.

  • Pingback: Creación de juegos en flash. | Teimagino.com()

  • Black Dragon

    is good!!

  • Okay guys, to test whether the line is hitting with the person while the alpha is 100, go to the cop movieclip (with all the code, not cop_patrol) and at the end, just before the last ‘}’ type:

    if (_root.line._alpha == 100){
    if (_root.line.hitTest(_root.hero)){
    _root.hero._x = 35;
    _root.hero._y = 40;
    }
    }

    Hope this helps! =]

  • Pingback: Como criar jogos online (em flash)?()

  • Axel

    I made a game from this tutorial, but my cop doesnt see the hero in certain parts of the level, I tried to correct the line, or addingo or subtracting in _x and _y but i doesn’t see the hero, you can pass right in front their nose and alpha is still 0.

    Does anyone has this problem, any idea how to solve it.

  • Jjjet42

    Nice tutorial.
    oh and to add 2 exits try copying the script
    for the hit test exit.
    then change exit number 2 to instance exit2.
    then paste the copied script into the heros
    script but change the hit test to exit2

  • Jjjet42

    I’m having some trouble…
    i looked at everything i did it right
    i instance it as exit.
    i put in the acton script.
    but i run it and it stays on level1.
    all of my levels are in levels movie clip.
    im using actionscript 2.0.
    they are on diffrent frames.
    the hero and the exit aren’t in level1 movieclip
    or level 2

  • Jjjet42

    still having trouble.
    compared with yours i see NO DIFFRENCE.

  • Jjjet42

    OK i figured it out!
    I just got rid of the levels movie clip
    and IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    YAY! MY first flash game!
    Thank you for this!

  • try get to the end with out geyying caught

  • pedroR

    To my exit, I put this code in the exit. I just give a name to the frame of the second level “level2” in the properties tab.

    onClipEvent (enterFrame) {
    if(this.hitTest(_root.Guy)){
    _root.gotoAndPlay(“level2”);
    }
    }

    because I use animation on the cops, it’s almost impossible to skip the frame :-)
    I give the instance name “Guy” to the main ball.
    Wonderfull tutorial!

  • Luke

    hi,
    can someone please help me? i need help on getting the end! when you go to the square that takes you to the next level? can someone tell me what the instance name needs to be? or the actionscript for the end of the level?
    thanks

  • jrnjac

    Ok look,i’m having troubles my guy can walk through walls and he can’t when i take off the whole levels thing!

  • jamie

    i am trying to load this into a parent swf with a blank_mc. No matter how I path it the hero cant find the walls. Any help would be great.

  • terrencemy

    Hi, actually I am facing some problems.
    What I am using is AS 3.0, and it totally different with AS2.0, i nvr learn 2.0 before as well…
    So it is bit difficult for me to change them into AS3.
    Especially the sightline….

  • Harry

    Hello,

    How can i make following? When cop see the hero he will follow him and when cop catch a hero game will be restarted.

  • Eric

    I’ve tried to do this myself many times, but for some reason when I put everything into the levels movie clip and I put it on stage and test the game, my hero doesn’t react to any of the walls or the exit or cops or anything. But, if I move my hero towards the bottom right corner there’s an invisible wall that I can’t go through. I did give everything an instance name and I’m not sure what’s wrong.

  • This is friggin awesome!
    hey,why don’t you make it more cool,like;
    infiltration with shadows
    kill guards
    gadgets
    cameras
    camera disabling
    interrogate guards
    scanners
    etc.
    and is it possible to make it second person mode?

  • yeah,and try to make it specialized for two or more human players

  • rodrigo

    I don’t know why but my walls aren’t working(I use cs4 is there any diference?)

  • jenny

    this it the best game ever it worked just fine for me.

  • Pingback: Como criar um jogo online()

  • shinobi

    awesome tutorial!!!
    but there needs to be more levels and more stuff in the levels.
    apart from that, GREAT TUTORIAL! helped lots. thanks.

  • Polo

    hi!! awesome tutorial but I got a little problem, the code of the hero within the moviclip “levels” is not working! when I tested it the hero was able to walk through walls! I assured to call both movieclips like this: _root.levels.wall.hitTest but is not working.
    why is that?

  • Roy

    Wich program did you use to make flash games like these? (My languange is not Englisch so maybe it’s not correct)

  • Pingback: Como criar jogos online em flash | Diretorio 10()