Create a flash game like Security – part 1

April 29th update: part 2 released
July 27th update: part 3 released

Some days ago a reader told me about Security 2 game. It’s a simple game: navigate through a level by using the arrow keys avoiding security traps and guards.

Security 2

I found the game so easy do develop but so interesting about artificial intelligence that I decided to start a tutorial about it.

In this part we’ll see how to create and manage the player and the guard/cop.

The player

Creating the player is very easy, especially if you read the first part of Flash game creation tutorial – part 1.

All you have to do is to create an movieclip where you draw a ball, drag the movieclip on the stage and assign it this actionscript

I won’t comment this actionscript because you can find all explainations in Flash game creation tutorial – part 1.

The walls

To create the walls, I created another movieclip and filled it with some squares, the “walls”. Then I moved to the stage and instanced it as “wall”.

The player actionscript changed this way:

As you can see in lines 6, 11, 16 and 21, I check the hit test between the center of the player and the wall before moving him. If I “foresee” the player’s center will hit the wall, I don’t move him.

Now the player can move through the scene, but I don’t like the player can partially disappear behind a wall. That’s due to the way I made the hit test. Testing with the center of the player, that’s what I got.

Time to change a bit the actionscript

The walls – part 2

In this second attempt, I introduced the concept of radius.
Knowing the radius of the player allowed me to determine the hit test not relatively to the player’s center but on the player’s edges.

Line 3: Determining the radius of the player

Then on lines 7, 12, 17 and 22 I performed the same hit test as before but not relatively to the center.
If, for example, the player is going left, the hit is performed on the player _x position (the center) minus the power minus the radius.

This allowed me to get a more accurate movement, but with some glitches (the same affecting the original Security 2 game).
In some cases you may notice the player stops some pixel before touching a wall, and in some other cases the player can walk through a wall if the wall it’s not in the direction the player is walking (this one don’t affect Security 2).

The first glitch appens because I move the player of 3 pixels/frame.

Imagine that the player has a radius of 6 pixels and is 8 pixels far from the wall. The test is performed on the pixel that is 9 pixels from the center (6+3) and it is a successful test, so I do not move the player. The player just stops 2 pixels away from the wall. How bad!

The second glitch happens because every time I go in a direction, I perform the hit test only in that direction, so if the player is very close to a wall corner, he can walk through a wall. Look at the picture to understand both glitches:

Glitches

So I needed to try another way

The walls – part 3

This is the new idea: I do not care about hit test when I move the player, but when I am about to display the frame

Look:

As you can see, in lines 6-17 I move the player without caring about hit tests, then at lines 18-29 I perform the test and move back the player of one pixel in a direction every time the hit test is detected in that direction. Since player’s speed is 3, the while loop won’t be executed more than 3 times, that is not CPU expensive.

The only thing I can say about this script is that the player can walk a bit through a corner, but it is not affecting the gameplay if the player has small size.

Now it’s time to design better levels

Designing a level

To design a level, I suggest you not to draw some boxes around the screen. Draw instead a big square covering all the stage then remove the parts you want to be walkable. Refer about designing levels for the game Tunnelball in this tutorial for more information about this way of drawing levels (or become a regular reader of this blog…)

Here it is a level designed in the new way

Now it’s time to add the guard/cop

The cop

The “line of sight” of Security 2 cops may seem awesome, but there is not artificial intelligence in it: I can do the same in a single movieclip.

As you may see, I simply designed the cop with his line of sight and managed it as a simple movieclip

Line 32 performs the test in the four sensible spots of the player and, if checked, moves the player to his initial position (defined at lines 4 – 5 and 33 – 34)

Try to go through the “line of sight” and you’ll see by yourself.

Now all you have to do is move the cop along a defined path and you’re done.

During next tutorials I will explain how to make a real line of sight, how to add more stuff (patrolling cameras, traps, terminals etc).

Download all examples (I included a in-progress example too, not mentioned in this tutorial), give me feedback and enjoy, then proceed to part 2.

  • Ciao

    sounds really cool. Did you try to make it for mobile phones using Flash Lite 2?

    Alessandro

  • Sirus

    I made an alteration to the first code on the page to make him run.

    onClipEvent (load) {
    power = 1.5;
    }

    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;
    }
    if (Key.isDown(Key.SHIFT)) {
    power = 3;
    }
    if (Key.isToggled(Key.SHIFT)) {
    power = 1;
    }
    }

    Notice how i add:

    if (Key.isDown(Key.SHIFT)) {
    power = 3;
    }
    if (Key.isToggled(Key.SHIFT)) {
    power = 1;
    }

    this makes him run when you press shift and walk when you press it again.

    What do you think?

  • Emanuele Feronato

    Great!

    I could make the player to be more “visible” when running to add a bit of a “stealth” to the action.

  • CHAOS

    Great! i’ll wait for the rest!

  • CHAOS

    my guy “pops” thogh a wall. help me.

  • Sirus

    one question. do u use slash MX
    or flash profesional 8?

  • Sirus

    i mean Flash not slash.

    woops =o

  • Niall

    Thanks for the first part of the tutorial!

    Cant wait for the next bit!

  • abhilash

    cool!
    i wanted a tut like this

  • mousey

    Wow great tut, i also made some cctv camers (just duplicated the cop and changed the graphics and gradient color) And simple added ‘cop’ as an instance name also what im trying to do is make an exit (ive been reading the other tutorial linerider taking idea from that action script) But could anyone help !!!!

    also im going to give a link to what ive done so far soon !

  • mousey

    oh and i forgot to mention i added a motion tween to the cop so he moved !

  • hasna

    nice tut

    but i didnt learn anything come with some new things instead

  • abhilash

    I used some codes of other tuts for cop to follow the hero this is the code
    “onClipEvent(enterFrame){
    tx = this._x;
    mx = _root.man._x;
    rx = tx – mx;
    if(this.hitTest(_root.man)){
    this.gotoAndStop(2);
    }else{
    if(rx >= 1 && rx-300){
    this._x = 1;
    }
    this.gotoAndStop(1);
    }
    ty = this._y;
    my = _root.man._y;
    ry = ty – my;
    if(this.hitTest(_root.man)){
    this.gotoAndStop(2);
    }else{
    if(ry >= 1 && ry-300){
    this._y = 1;
    }
    this.gotoAndStop(1);
    }
    }”
    now the cop is moving but through the walls!!
    can you help me?

  • Niall

    I just added a motion path to the cop so it moved.

  • Apache

    Hi,

    I have alittle problem with the wall. I would like lines to make wall from, but the guy simply walk through the line. (I tried it with squares, and he walks through it too. ). I copied and pasted the codes you wrote, but it doesnt work for me. I use flash 8 prof. Any ideas how can i fix it? Or does it work with lines at all?

    Looking forward for your answer.

  • zak

    i luv it!!!

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

  • flashcrazy

    hey i did this tutorial but when i added the code for the walls my guy still walks through them to the other side!! WHY?

  • flashcrazy

    YOU **** ****!!!!! REPLY NOW!!!!!!
    (edited by Emanuele Feronato)

    flashcrazy: 1st and last warning. Don’t ask 4 explainations in this way. Respect other readers

  • cooooooooooooooool

  • abhilash

    to all who are having problem:please check that you have given the instance of”wall” to the wall

  • Wow, thats wierd, we were just starting to make a game just like this for our website, we have one that we coded ourselves but yours seems to be very good. The only difference is we have added the ability to disarm the guards, who will find their flashlights in a designated amount of time, by using a weapon. (Note: anybody who tries this themselves, we suggest don’t use the pen to draw walls, use only 90 degree angles, if you create the ability to disarm there can be MANY glitches, i hope the authoer adds a possibility of disarming guards in the future.

  • I tried to make my own a while ago but only just found this!

    My attempt is here: My Attempt

    What do ya think?

    Thanks

  • Emanuele Feronato

    Matt: did u mean “cross that border”?

    I like it, what about sharing your source code with a line or two (or fifty) of explaination?

  • EBLUP

    hey long time no talk.

    i think thesis people want more than just that and they don’t want to wait so if you want ill send you flash games and you can make tutoreals for them. OK?

  • pls help I can,t understand

  • alexdarkred

    on the last piece about the cop when i treid playing it it said there was an error saying “**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 36: Unexpected ‘}’ encountered”
    what should i do

  • conor

    also i made the ball bouce off the walls just to add excitment

  • conor

    … sorry that part was wrong tut but i need help on this 1 i done every thing tothe word but the guy walks thru the walls and yse i have instaced them as wall

  • wer dup

    I dont know how old this is but if you still check it I was
    wondering how to add more levels.

  • mik

    how the heck do you change the instance??

  • Ronak

    Dont understand anything

  • quadrapod

    if ((_y radius)>400) {
    _y -= 3;
    }
    if ((_y-radius)400) {
    _x -= 3;
    }
    if ((_x-radius)

  • i just can’t do it

    like, the cops move with the player
    and they start at the same position(almost)

    my player walks trough walls

    and i can’t do the level…
    can anyone help me?

  • Bob Thor

    Can you help me please? I have Adobe flash CS3. Whenever I try to put the first Actionscript in and run it, it comes up with: Clip events are only permitted for MovieClip Instances for lines 1 5. I made sure I had it under symbol description too. Thank you!

  • Bob Thor

    P.S.—I just downloaded your examples. Mine is exactly the same except for the fact that when I open up the script editor, your circle seems to be recognized as a movie clip, while mine does not. Thanks again!

  • David

    i need some help im making a game like this, but i need to make an exit to move to the nest level but i donr know how to do that. i think that your suppose to make it with a hit test but i dont know how to, i tryed to but it didnt work.

    if you know how to do that please e mail me.

    David_sheets4@hotmail.com

    or post how to here lol

  • Art

    This is a nice tutorial.
    but for the hit test you wrote:

    if ((_root.cop.hitTest(_x, _y radius, true)) or (_root.cop.hitTest(_x, _y-radius, true)) or (_root.cop.hitTest(_x radius, _y, true)) or (_root.cop.hitTest(_x-radius, _y, true)))

    cant you just write this:

    if ((_root.cop.hitTest(this))

    it will be a lot simpler.

  • Emanuele Feronato

    Art: no, it’s not simpler, it’s wrong because of the bounding box.

  • gary

    i need to make a finish so if it hits is it will go to
    another frame heres what ive tryed

    if(this.hitTest(_root.finish)){
    this.gotoAndStop(‘2’);

    post a message if you now how to solve this Thx

  • suman

    very good

  • Izz

    hey emanuele, another arsome tut. have u ever played Dead Marshes? (type it into Google) I was trying yesterday to create a really simple version like it, just with the scrolling walls and the boat but I failed miserably — I couldn’t get 2 different hitpoints rotating, ect, ect.
    So anytime you feel like mking a tutorial for Dead marshes that would be nice…
    It was worth a try.

  • mike

    I was trying to add on a few levels and as a kind of cheat i wanted to make a pass word that got you to the next level i used…

    on (press) {
    if (_root.cheat.text == bankpro) {
    gotoAndStop(‘lvl2’);
    }
    }

    with this code it will accept any password

    please help!!

  • Lepynet

    Emanuele, in the next tut, can you make a finish? everyones complaining, and in your other tuts, they don’t work with this code. Oh, and thanks. i’ve been trying to make a game forever, and they were always filled with glitches. now, there not.

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

  • conn

    What program do you need for this?

  • Chris

    Hey Guys!

    I have got a problem creating the walls. As you described it it does not work. I do not know y.

    Maybe there is somebody who can help me

  • ???

    what the?
    well whoever did this tutuorial did go and all it’s just that hey should of made it a little more advanced like if you get caught 4 times you go to a gameover screen and make the security guard move.
    that would be worth while…

  • N/A

    there is some flaus in your action script.

  • Pingback: Create a survival horror game in Flash tutorial - part 1 : Emanuele Feronato - blog of an italian geek()

  • Xavi

    can you make a rock paper scissors game tutorial. I made one so that you choose rock, paper, or scissors and it shows it in a box. then when you press ready, the comp randomly chooses a hand. i am stuck on how to make the comp recognize if you have won or lost.
    i tried to something like
    var cpu:Number = random(3)
    if(cpu == 1){
    tellTarget(“cpuChoice”){
    gotoAndStop(2)
    }
    }
    etc
    if(cpu == 1 && playerChoice._currentFrame ==3){
    gotoAndStop(‘win’)
    }
    i would be REALLY grateful if you did a tut or sent me the way that you would do it…(whole thing)
    thnx =)

  • Derek

    Hello, trying to use this tut to get it to work, but apparently javasccript hates me more than most…The cop moves with the player and both move through the walls, need some help if you could give it, please.

  • Gonzalo

    I have a question:

    This is the first time I have ever tried to create a game using flash, so all of this is new to me….
    When I try to insert the code into the first frame, i get an error that says that clipevents are only permitted for movie clip instances… and i really don’t understand what that is supposed to mean….
    Can anyone please reply with some kind of solution or just tell me what i’m doing wrong.
    Thanx.

  • Ranyo

    i understood, and did this tutorial, but im trying to make a simple game from this, and i suck at any scripting, but how do i make it to where the character can run into two(or more) “different” wall objects

  • Ranyo

    nvm i found out how to.

  • jason

    i am having a problem with making the cameras when the player moves through the camera the player is not rest how can i fix this problem

  • Pingback: A Gem of Flash Game Tutorials | Newbie Game Programmers()

  • Joseph

    Mike, change the ‘lvl2’ in the brackets to just ‘2’. that should change it to that frame.

  • Hey nice tutorial i was having trouble my walls would follow with my hero, i found out that i typed in the script to the wall >.< so wall would follow, thank god you have downloads!, well i get it nice tut m8!! 5/5

  • After making the movie clip i added the script to the hero there was an error:
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler

    There are a lot of others having the same problem, so could you please tell all of us what program you are using and what might cause these problems?

  • Pingback: Jail Break: Flash game based on Security tutorials : Emanuele Feronato - italian geek and PROgrammer()

  • im using adobe flash and my guy wont go through the left wall but goes right through the right.

    p.s. i made it so that he could only go left or right for this game

  • KJBang

    Hey i wanted to know how to make the cop move or keep him from pretty much ?doing me?….. well n-e-wayz how else do I make The cop do what he’s supposed to do?

  • johnny

    ive made many flash games buti cant get the walls to work(on any game ive made). do i have to put any action script for the wal or just leave it blank and idk this is what ive got my man programmed as right now:

    onClipEvent(load){
    fight = false;
    }
    onClipEvent(enterFrame) {
    if (fight == false) {
    if (Key.isDown(Key.LEFT) && fight != true) {
    _rotation = 270;
    this._x -= 5
    }
    else if (Key.isDown(Key.RIGHT) && fight != true) {
    _rotation = 90;
    this._x += 5
    }
    if (Key.isDown(Key.UP) && fight != true) {
    _rotation = 0;
    this._y -= 5
    }
    else if (Key.isDown(Key.DOWN) && fight != true) {
    _rotation = 180;
    this._y +=5
    }
    }
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
    _rotation = 225;
    }
    if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
    _rotation = 45;
    }
    if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
    _rotation = 135;
    }
    if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
    _rotation = 315;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y -=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y +=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._x +=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y -=5;
    }
    }

    sorry its long cud u maybe email me a more correct 1 all the humbo jumbo is my best attempt at a rotating character so i can make a real man not a circle and it will make him look the way hes moving..from ariel view

    also if the wall soes need actonscripting plz email that to me too- johnnyracket@yahoo.com

  • johnny

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y -=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y +=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._x +=5;
    }
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.hero)) {
    _root.hero._y -=5;
    }
    }

    ^^^^^^^^^^^^
    thats the prob with man i think idk its not stopping him from walking thru walls!?

  • johnny

    sprry guys i fixed it i just looke dover my script its to messy i perfected this will allow a much better man that can walk thru walls and emanuele if u cud maybe perfect my hit test id liek i thanks

  • johnny

    onClipEvent (load) {
    power = 3;
    radius = 16;
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    _rotation = 270;
    _x -= power;
    }
    if (Key.isDown(Key.RIGHT)) {
    _rotation = 90;
    _x += power;
    }
    if (Key.isDown(Key.UP)) {
    _rotation = 0;
    _y -= power;
    }
    if (Key.isDown(Key.DOWN)) {
    _rotation = 180;
    _y += power;
    }
    while (_root.wall.hitTest(_x, _y+radius, true)) {
    _y–;
    }
    while (_root.wall.hitTest(_x, _y-radius, true)) {
    _y++;
    }
    while (_root.wall.hitTest(_x-radius, _y, true)) {
    _x++;
    }
    while (_root.wall.hitTest(_x+radius, _y, true)) {
    _x–;
    }

    if (Key.isDown(Key.SHIFT))
    power = 1.5

    if (Key.isToggled(Key.SHIFT))
    power = 3
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
    _rotation = 225;
    }
    if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
    _rotation = 45;
    }
    if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
    _rotation = 135;
    }
    if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
    _rotation = 315;
    }
    }

    ^^^^^^^
    there ya go guys have fun playing with my killer nub scripting =)

  • Erik

    hey, u didnt explain how to make the cop go on a defined path, i tryed to do it myself and i have no errors but he wont move… this is my code (keep in mind, im only trying to go up and down)

    onClipEvent (load) {
    ystart = _y;
    speed = 6;
    radius = 8;
    gameend = false;
    topwall = 60;
    up = true;
    down = false;
    }
    onClipEvent(enterFrame){
    while (gameend=false) {
    while ((_yystart)&&(up=false)){
    _y -= speed;
    }
    up = true;
    }
    }

    if you can, email any responses to bballman4l15@optonline.net. thanks!!!

  • Erik

    … i dont know why this didnt get copied but this is in there too.

    while ((_y<topwall) && (up=true)) {
    _y += speed;
    }
    up = false;

  • lpb50

    it dosnt work i put the scripts in and what hapens when i move the man the wall moves!!!
    can any one help me?
    :(

  • Traeby

    Hi,
    this website has opened my eyes and taught me better than my tutor; I’ve based my project on the illustration here, however, the movements are very tricky;it’s going through walls in some cases(lol); How can I solve this problem??
    Any AS3 GURU please help me ASAP!!

  • Hi can u make a whole deatailed tutorial on this http://www.mofunzone.com/online_games/magic_pen.shtml plsz explain physics i will wait for reply Your tutorial line rider dosen’t have these physics as this game have so plsz make one point is simulating physics actually i am making motorbike game so i need to understand

  • matt

    my guy just goes through the walls how do i i fix this?

  • Vince

    I love the fact that you’re trying to help us make this game, but it doesn’t work for me. even after I put in all of the codes, my character still goes through the walls, and the security guard is attached to the character.

  • Gurg

    I need some help, my dude walks fine and can exit a level but i cant make the cops detect him, he can just pass trough them.

    Heres my code:

    onClipEvent (load) {
    power = 2;
    radius = 6;
    _x = 32;
    _y = 34;
    }
    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);
    }
    if ((_root.cop.hitTest(_x, _y+radius, true)) or (_root.cop.hitTest(_x, _y-radius, true)) or (_root.cop.hitTest(_x+radius, _y, true)) or (_root.cop.hitTest(_x-radius, _y, true))) {
    _x = 32;
    _y = 34;
    }
    }

  • isaac

    all those codes are wrong they contain errors cmon please put the good one..

  • my hero dont get followed by the cop
    no idea how to do it

  • flashuser

    i try the walls thing and my player just walks through the walls! help!

  • plz ansewr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • me

    um it works and all, but when i test the movie,the guy starts like off the little viewing screen, but once i manage to get him in, he gets caught and goes back to that unknown place.

    ??????????

    PLZ HELP ME!!!!!

  • josh

    love it, i made a game called “pickel’s adventure” out of this =]

  • hi when ever my guy walks he just alks under the wakks could someone help me?? email me if you can stickdude45@hotmail.com

  • josh

    i am trying to get the character to go into “stealth” mode:

    onClipEvent (load) {
    power = 3;
    radius = 10;
    _x = 35;
    _y = 40;
    }
    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.wall.hitTest(_x, _y+radius, true)) {
    _y–;
    }
    while (_root.wall.hitTest(_x, _y-radius, true)) {
    _y++;
    }
    while (_root.wall.hitTest(_x-radius, _y, true)) {
    _x++;
    }
    while (_root.wall.hitTest(_x+radius, _y, true)) {
    _x–;
    }
    if (Key.isDown(Key.SHIFT)) {
    this._root.energy -=1;
    this.gotoAndPlay(“stealth”);
    if(_root.energy < 0){
    _root.energy = 0;
    _root.gotoAndStop(3);
    }
    }
    }

    it all works perfectly, except either the enemy “sees” the character, both stealth mode and normal, or he doesn’t. here is the code for the cop;

    onClipEvent(enterFrame){
    if (_root.char.hitTest)
    _root.energy -=150;
    }
    what the shift button does, it moves to a frame inside the mc “char” that is visible the opacity 25% and the instance name is changed to “char-stealth” so the cop doesn’t interact.
    could you help me in any way?
    i could send you the source file if you would like ;)

  • Gelo (PX173)

    I think I found a correction. I checked for errors, and it said something about the _x and _y parts. They’re actually inverted, meaning that _y is left and right, and _x is up and down.

  • Gelo (PX173)

    Oh wait, I was wrong.

  • arafitos

    How did you make the walls work like that. When I make my walls, the whole bounding box triggers the hit.test and the character can’t move.

  • Pingback: Flash Game Making Tutorial - Part 5 | ninjadoodle.com()

  • Greg

    I used the example where you used the while loops to detect collision and modified it a little bit so the code is in the frame and not the player. The problem is the player stops short on a few collisions and goes into the wall a little bit on some other testtests. I made sure I have the right radius but it problematic.

    This is where it gets weird, so then I copied exactly emanuele’s code and put it in the player and made sure all the conditions are the same as his example, but i still have the same collision problems.

    I would be very grateful if anyone has any ideas.

  • nathan

    I can’t get any more than one cop to work on each lvl i know my codes are right cuz i used the same instance as my first cop for my other but still my first cop is the only one that can catch me.

  • It doesn’t work in Flash MX… Do you know the code for that? Please reply, as I’m no good at ActionScript- for this, I has to copy and paste what you’d done (the guy moves but that’s all it does…)

  • Oh, I just noticed that I forgot to name the instances :S It works now :)

  • mikajendo

    Great tutorial, the only problem I have is when I put the “hero” movie clip inside the “levels” movie clip it just goes straight through the walls, but when its on the main time line it works fine. All the instances are correct and I compared my code to yours and there was nothing wrong with it. Does anyone know what is wrong?

  • Hello, great tutorial; I found it very easy to follow up until the part where you created the cop. I’ve created the ‘cop’ as a single movieclip (as an assumption) and entered in the actionscript you’ve given, but it doesn’t work properly, and I’m not getting the same effect as you do.
    Instead of what yours appears to do, my cop starts outside of the maze itself, and when I move my main player, the cop follows the same instructions.

    Any help would be greatly appreciated.

  • jonathan b

    Even with the last code, my movement seems to work as if the wall is more down and right, i tried having the character on all kinds of sizes but it doesnt work, any ideas?

  • Darko

    After “The walls – part 2” My character doesn’t work right.

    As in, the collision detection works perfectly to the right, and downward. But when I go up or left, I end up having a huge gap sort of like this.

    Left right
    | |
    | |
    | O O|
    | |
    | | it creates a space
    when I go left.
    It won’t let me go any farther towards the wall. Same thing happens when I go up. And the code was copied and pasted to see if I did anything wrong, but it still doesn’t work. :/

  • Darko

    The spaces didn’t work right, but it looks like this. Sorreh.

    Left
    |
    |
    | O
    |
    |

    Creates a space.

  • 921w

    yo, can some one plz help. just like every one else, my guy keeps going through the wall. if any one can help, mail me at w-92125@hotmail.com

  • hossein

    how to scroll map?

  • mas como eu quero fazer um jogo rsrsrsrs

  • evalducas

    is this aS 3.0 ??? mail me plz

  • Reuben

    i put in the radius=6 part in the actionscript and it says: “There is no property with the name “radius”.
    What do i do?

    Besides that great tutorial :)

  • Derrek Buerger

    I can’t get another cop on. i do everything again to make another cop but the hit detection doesn’t work…

  • Reuben

    Hey this is all great, and it taught me loads, but when i do the part that makes me start over when i hit the cop, it only works when i hit the cop when im pressing down. my code is exactly the same as yours. its just that my guy doesnt go to the beginning when he hits the cop from left right or below. only if he goes down on him. please help!

  • Dylan

    Emanuel, please help me!

    Is it possible to make the cpu (the cop) move? I’ve read your part 2 but the actionscript for the moving cop includes the line of sight and other stuff. Could you please send me a typed out actionscript that would make the cop move around (patrol) and send you to another screen (that says “you lose” or something like that)if you touch the cop or his vision?

    Thanks

  • Dylan

    ANYONE PLEASE HELP ME!!!

    You know in some flash games after intros or after levels it says, “Press Space to Continue” and when you press space, you go to the next part of the game?

    How do you do it? What’s the actionscript you have to type in?

    Thanks.

  • Derrek Buerger

    Apperantly, when i use the very good wall code with the “while” loops, and i submit the game to a site with that code, apperantly, that’s a bad code. got anything else?

  • hey Mr.emanueleferonato ive a little problem now i followed your every instruction and when i test movie and move my character against the wall i disappear for no reason so if you can give me your email i can show you screenshots of my test movie okay thank you for reading this and good day

  • Chris F

    First,

    Let me tell you your tutorial sucks. You do not explain how you did the walls, you just re-direct us to another tutorial where you partly show in a group of small images how to make a level for another game, which does not work here using flash 8.

    Please, re-do or do not make any more tutorials, this really wasnt helpfull at ALL.

  • Seto Wolf

    I put in the code, did the instance names, change the errors and now it’s coming up and saying “Constructor functions must be instance methods.” I have no clue what it means, plz help!!

  • The New Guy

    For running instead of having a toggle as suggested earlier you could use and else statement so if shift is pressed you run if it isn’t you walk here is the code i used

    onClipEvent (load) {
    speed = 3;
    }

    onClipEvent (enterFrame) {
    if(Key.isDown(Key.LEFT)) {
    _x -= speed;
    }
    if(Key.isDown(Key.RIGHT)) {
    _x += speed;
    }
    if(Key.isDown(Key.UP)) {
    _y -= speed;
    }
    if(Key.isDown(Key.DOWN)) {
    _y += speed;
    }
    if(Key.isDown(Key.SHIFT)) {
    speed = 5
    } else {
    speed = 2
    }
    }

  • ANNOYED

    THIS IS BLOODY STUPID! I CAN MAKE THE GODDAMN BALL MOVE- BUT WHEN I COPY THE ACTIONSCRIPT IN IT STILLS GOES THROUGH THE BLOODY WALL I’VE BEEN TRYING FOR SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO LONG NOW WHY ISN’T IT WORKING!? THEN I COPY THE COPS ACTIONSCRIPT IN AND IT JUST FOLLOWS ABOUT MY BALL WTH?? ARGH PLEASE HELP ME.

  • wow great job i like this site so much!!

  • Hi

    When i put the code in the character it still walks like under the walls but i dont know what i did wrong plz help

  • i have an error, i followed the coding, i get an error in as 3 and it says there is no actionscript coding in as3, i am making the first code, to make ‘player’ move

  • i want to move movie clip in variables, plz anyone for help

    regards,
    maria

  • anon

    this is the god dam worst tutorial i have every come across, none of the codes work had to edit every single one. FU

  • ubeach

    YOUR CODING IS UNBELIEVABLY CRAP.

  • Sam

    I have copied the coding and made minimal changes but my character has no radius. Well its hard to explain,my character doesnt hit the top and right parts of the wall but half passes through the left and bottom. Can I get help?