Flash game creation tutorial – part 3

March 14th update: part 5.3 released.
March 3rd update: part 5.2 released.
February 9th update: part 5.1 released.
December 31st update: 5th part released.
December 23rd update: 4th part released.

Here we go with the 3rd step.

Remember to read 1st and 2nd part if you are new to this tutorial, and let’s go.

We left our hero colleting coins, so next step will be…

The score

Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.

In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.

Hall I have to do is initializing a variable in the root with a single action

And then in the hero movieclip

Look at lines 33 and 37… as said, you get one point when you collect a coin and lose 2 points when you hit the wall.
A dynamic text in the main scene displays the score.

Sooooo easy… now let me introduce you the main event for this tutorial… the environment…

We can have different kinds of environment… let’s start with the easiest.

The killing fixed environment

The killing fixed environment is a deadly part of the stage that does not move, such as a spike.

So I created a new movieclip called environment and instanced as environment and placed in the stage.
You choose how to detect the collision, with the center of the hero or with the hero_hit shape (time to read part 2 if you do not understand what I am talking about).

Just remember you game does not have to be too easy or too hard.

Lines 34-39 do the routine that checks collision between the hero and the environment

This is useful if you want to place objects on the stage that may kill the hero.

Sometimes, the environment should move.

The killing tweened environment

I am calling “tweened environment” an object that always moves along a path… such as a sliding wall or something similar.

The actionscript, obviously, is the same as above, the only change is to the environment object, that now has a tweening motion. You’ll see it better when you will download the sources, at the end of this tutorial.

The only thing I want you to know is: for a better result, the number of pixels the environment moves at every frame should be an integer. I mean that if you want to move your environment by 150 pixels, be sure that dividing the pixels for the numbers of frames you have an integer number.
In my case, I move the environment by 150 pixels in 75 frames… 150/75 = 2 (integer) pixels/frame.
It’s not a mandatory rule, and in most cases you will experience it is impossible to achieve such integer numbers, while you can do it, well, do it.

Sometimes we want the hero to interact with environment, so I will explain howo to get…

The triggered environment

Let’s suppose to have a wall that moves very fast… making our life so hard… we should let the player decide to cross the wall, risking his life, or turn off the “engine” that moves the wall, for example pushing a button or pulling a lever.

In this new movie I created a new object named as trigger and instanced as trig, with the shape of a lever.

Then I added some actionscript to the environment, that is no longer tweened.

This is a very simple movement routine… I will explain more complex routines later in the tutorial, but at the moment I only want a wall to cross the stage up and down, and the hero to get the trigger to stop it.

The script is very simple, just take a look at the moving variable. You can see that the environment will move by 4 pixels (integer…) upwards or downwards as long as the moving variable is set to 1.

How can we stop it?

With lines 40-43 of the hero’s actionscript

If the hero hits the trigger (as explained before, you will decide the type of collision checking later when you will test the entire game), the trigger frame is moved to 2 displaying a pulled lever and the moving variable is set to 0.
In this case, the actionscript of the environment won’t enter in the if condition and the environment will stop.

Possibile applications of this routine are almost infinite: imagine buttons that stops dangerous object moving, levers that reveals hidden zones with treasures, and so on.

We will discover all those options when the game will be in progress… remember that at the moment I am just showing you the basics.

Talking about basics, let’s see a type of environment that as far as I know is not included in ball:revamped (of course we always have to try to improve existing concepts).

The undeadly environment

I want an environment that does not kill the hero, but that changes some behaviours… imagine a stage that is partially flooded.
You have water in the stage, and your hero underwater movements will be more difficult.

Line 9 has a new variable that determines if the hero is underwater or not.
Then, when it’s time to update hero’s position according to gravity, speed, and so on…
Lines 26-33 checks if the hero is underwater or not. If it’s underwater, movements are reduced by 5 vertically and by 3 horizontally.

Note: I said movements are reduced, not the speed! This means that when you will pop out of the water, you have to pay attention to your speed. I want the player to move carefully when underwater, not simply have slower (easier) movements.

Now let’s imagine to have some special object on the stage. If the hero collects such object will raise the score, but the entire environment will get harder.

The playing environment

A little game covering some of the thems we discussed until now.
You have to score as much as you can. As seen before, you get 1 point when you collect a coin, you lose 2 points when you hit the walls and 1 point when you hit the environment.
Easy? Not at all… I forgot to tell you the environment moves, and the higher your score, the faster the movement.

The actionscript on the first frame is

You may ask: can’t you put this line in the hero onCLipEvent(load)?

Yes, I could, but you will see why I put it there when we will learn how to move around levels.

Anyway, in the environment object we have the actionscript:

Do you see? the environment rotation speed increases as long as your score increases. So bad!

Finally, the hero actionscript

Nothing new, just a check to the score to prevent it to be less than zero.

If you want, drop a comment with the highest score you achieved. I bet you won’t easily score more than 15.

Remember to give me feedback and suggestions.

Download the examples source code and move to the 4th part

  • Pingback: Flash game creation tutorial - part 1 at Emanuele Feronato()

  • Hmmm… I know this is a begginer’s question to ask, and I’ll admit to being one, but how do I get two instances to group together and stay together during the “game”? I’ve tried many different ways, but they never work, I always end up leaving the square behind.

  • Random

    This is a very good tutorial. I have one comment to make however. On your last tutorial (Part 2) you told somebody it would be hard to make a bounce effect. Its actually very easy. Start by making two separate movie clips/instances for the walls, wall1 (floor and ceiling) and wall2, the right and left walls.
    if (_root.wall.hitTest(_x, _y, true)) {
    yspeed = yspeed*-1;
    }
    if (_root.wall.hitTest(_x, _y, true)) {
    xspeed = xspeed*-1;
    }

  • Random

    Umm… woops. Redo.
    if (_root.wall1.hitTest(_x, _y, true)) {
    yspeed = yspeed*-1;
    }
    if (_root.wall2.hitTest(_x, _y, true)) {
    xspeed = xspeed*-1;
    }

  • Me

    Woho!
    I scored 21 :D

  • Newbie

    i’m quite a newbie regarding flash, though i’d followed the tutorial quite easily (that’s a compliment) and managed to accomplish all the first steps but i can’t make a funcitonal score count. i’ve put the code correctly in the hero but i dont know what to do with the “score = 0;”, where to place it. (i mean, i don’t know how to initialaze a variable in the root) again, i’m new in this. sorry, hope to get ur answer

  • Newbie

    score done.
    :)

  • Newbie2

    I have the same problem Newbie had, i can’t get the score to function correctly…
    I have “score = 0;” in the main frame, a dynamic text box in the main scene, and i have “_root.score ;” in the correct spot… still not sure why it isn’t responding.

  • teh nub nub

    great tutorial
    couldnt get past 17 on that last 1

  • Tom

    WOOHOO I SCORED 800 MILLION

  • eblup

    hey can you make one with a guy gravity ground water and boxes to hop acros.

  • i best the game

    i beat ball revamped blblblblblblblblz

  • sam

    i am making lives in my game it works the same way as the score but it minus lives instead of score when it hits the walls. When the lives equals 0 i tried to make a code so that it takes it to a frame which says game over

    but this code doesn’t work:

    if (_root.lives=0) {
    gotoAndStop(2);
    }
    can anyone help me???

  • jonimator

    im having the same problem with the ‘score=0’ can anyone help me?? please where do i put it??? I cant use the scoring method! :(

  • Pingback: Flash game creation tutorial - part 4 at Emanuele Feronato()

  • in reply to sam:

    your code:
    if (_root.lives=0) {
    gotoAndStop(2);
    }

    correct code:
    if (_root.lives==0) {
    gotoAndStop(2);
    }

    you should be checking if lives is equal to zero,
    instead you had if, set lives set to zero.

    honest mistake, every time you use an if statement with variables use 2 quals signs. it means “is equal to”

    hope that cleared it up for you.

  • and as for the score newbies…
    first frame, on the frame. put score=0;
    then always refrence it with _root.score
    it will work. full proof. if you can’t get it to work with that said, then go get a new hobbie.

  • Hi , how can i put the ”The killing tweened environment” , but also the ”Water” ?

  • Andrew

    Nice tutorial :) hope there will be more of thees, how to make a “mario style” platform game maybe? ^^

  • calle

    I’m not so good at this.. i could do everything exept for makeing the score board..
    so if someone could tell me how to do(from the begining please) thanks!!
    :)
    Great tutorial!!!

  • Fiz

    woah, totally easy to learn, and you actually explain the action script, you are gifted at tutorials, and the root files for examples are a stroke of genius

  • Purple_Chikcen

    i made a dynamic text block and gave it the instance name of score and gave put score = 0; in the actions menu of the main frame. i typed zero in it and tried the game and when i collide with the coin and walls the score does not increase or decrease what am i doing wrong can anyone help me

  • Purple_Chikcen

    “gave put” is a typo woops i didnt put the word “put” in the script lol

  • Purple_Chikcen

    wow been a while since hes replied to anyone

  • Purple_Chikcen

    yus i scored 20

  • Ryan

    I got 16 on my first try!

  • where exactly do i put the score variable thing? (the first actionscript on the page)

  • Paul w

    i dont even get how to do the dynamic text box!?!? help!!!!!

  • NeedHelp

    I am having torouble with the score please help me by telling me exactly what i have to do with the score

  • trys everything

    This is to everyone who needs help with the score box.

    Click the text tool in the tool panel and create a text box. In the properties area make sure the dropdown box is set to dynamic. In that same section you will see a text area labeled “var”. in there you type “score” because that is the name of the variable you want it to show. In the first frame of a layer (preferably the layer with the text box) enter the actionscript “score = 0;”.

    If that doesn’t work, give me some slack. Post your problems and I’ll try to help. I am only 14. :-P

  • trys everything

    Oh yeah forgot.

    Awesome tutorial!

    Covers all actionscript problems.

    Only thing is, I want to keep all my actionscript in the first frame of a layer called “action”.

    How do I get the frame to recognize the onClipEvent (enterFrame) line for the hero MC?

  • Mick

    im having a pronlem with the scoreing, i can make the text box and everything, but i cant find the var box =(, can any1 help?

  • confused pinguine

    This Tutorial is really great!!
    Im 12 years old and I understand(most of) it!
    But…
    when I am Playing the game ive made, evrything goes in slomotion!!!
    WHY MAAN WHYYYY!!!

  • K

    To Mick. Mark your textbox and check the properties. Right under where you choose color and size of the letters, the “var” box is.

  • Help with inserting more “environments”
    Been following this guide for a while. Been going well so far. Execpt one thing. How do i add more environments? If i copy the first one i had, it simply goes right through it.

    ;)

  • Trys Everything

    @confused pinguine

    wat you have to do is increase the frames per second (fps) to 50

  • Mick

    yeah i checked there but on my flash theres no var box there…maybe i’ll just upgrade to flash 8 ;).

  • George

    i dont know if this was answered somewhere but alot of people were asking about the scoring. make a dynamic text box, give it a name then type this into action script.

    _root.(text box name).text = “score: ” (variable name for score);

    hope it helps

    =\

  • helper monkey

    — confused pengiun, just click on the stage, then open the properties bar at the bottom, there should be a box that says “FPS 12”, simply change the 12 to a higher number.
    im using flash mx 6.0, so sry if you’re using a different version and this doesnt work

  • im the best

    emanuele i mastered that spinning game i got 17!

  • im the best

    Lol vasheeth you spelt beginner wrong

  • im the best

    and mick flash 8, it rocks i suggest going for it

  • Pingback: Flash game creation tutorial - part 5 at Emanuele Feronato()

  • Pingback: Flash game creation tutorial - part 2 at Emanuele Feronato()

  • confused pinguine

    thx 4 ur help Helper monkey and trys everything!
    I appriciate it man…
    /\
    (or however u spell it…)

  • Anonymous

    Great tutorial, bad for beginner because you don’t explain very much.

  • Glucozade (Sonic fan #1)

    how would i put in a variable showing the number of lives left and ‘game over’ -ing the game when the lives reach zero?
    any help is appreciated

  • -none-

    23 point!!!!!!!!
    beat that!!!

  • In response to diamond drake:

    your code:
    if (_root.lives==0) {
    gotoAndStop(2);
    }

    correct code:
    if (_root.lives==0) {
    _root.gotoAndStop(2);
    }

  • Trevor

    im creating a trigger similer to the one used in the tutorial but i want to be able to stop and start the moving block the trigger affects effects I’m a complete begginner with flash but learning fast, any help you can give me is greatly apreciated.

  • Pit

    Man, i can’t figure out the score thing either…i know im doin somethin wrong. if only i knew what… I put the score code in the frame, i make a dynamic text box with variable of score, and i put in the code in the hero. NOT WORKIN! When i veiw the movie, the score box doesn’t even start out with a zero in it!

  • Pit

    oops, i meant instance! lol not variable

  • Hey i’m currently making a game (not like yours, but similar. and i was wondering, if theres a code, so that when the “hereo” touches a movie clip, it goes to the next scene?

  • Jonny

    Hi im all new to this actionscript stuff and so im confused. this is probably a really obvious answer but on the last game when i try to make the environment rotate, it doesn’t rotate from the middle, it always rotates from the left. can anyone help with this please?

  • ru8ikscu8er

    Yay, after about an hour of mindlessly playing this game like a moron, I have finally achieved the coveted rank of 30, thus becoming the world class mindless game player

    P.S. I can do the rubik’s cube in about 30 secs

  • Chaos

    So, I’ve read through the tutorials and I think they are pretty awesome. I’ve been tweaking numbers within the games, and I’ve noticed that I’m unable to make a solid object. I’ve been trying to make a solid ground or block that doesn’t kill the player, the player just can’t go through it. Mostly, I’ve been trying this with the ground. I’ve change the settings so that it doesn’t kill the player (commented out the change x and y positions) and I’ve changed the part where it changes the players speed, so rather than setting it to 0, it sets it to -(some number)*xspeed. Is there a specific number that I have to use that counters gravity and the player’s downward force? Like, for example, should I stop the players motion, than give them a gentle push upward?

  • Smokey

    im a little confused.

    The score

    Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.

    In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.

    Hall I have to do is initializing a variable in the root with a single action
    ACTIONSCRIPT:

    1.
    score = 0;

    Where do i write the “score=0;” ?

  • shadowt

    im a little confused.

    The score

    Scoring system consist in a variable set to 0 (zero) when the game starts and some events that may increase/decrease the score.

    In this case, you get 1 point when you collect a coin, and lose 2 points when you crash into a wall.

    Hall I have to do is initializing a variable in the root with a single action
    ACTIONSCRIPT:

    1.
    score = 0;

    Where do i write the “score=0;” ?

  • MasterZ87

    Score 14 xD

    I know somethinks abouts programming (Div 2 xD), but flash (and any object oriented programming) is more complicated. Thanks for the tutorial, it’s very good ^_^.

  • Aidin

    why when i generate the SWF file of these tutorials, it doesnt get keyboard input dont work but when i use flashplayer, they work and gets my keyboards?
    Emanuel, do u answer these questions?!

  • Aidin

    i realized by Clicking once on the browser, it gets my keyboard input, but why and how can i solve this bug/problem/”something that i dont want” ?

  • dffdfdfdfdf

    good tutorial for people who are intersted in making platform-type games. i dont think that this tutorial is suitable for newbs, cuz they cant learn math and variables at the beginning

  • Liz

    This tutorial is great. I am having one problem, though, that other people seem to be having but that hasn’t been answered.

    My hero cannot collect my coin. It passes right over it and the coin does not move. Does anyone know why that might be?

  • Tom

    everybody listen!!!!!

    the reason why your game is in slow motion is because your frame rate is not high enough

    all you have to do is right click the screen
    go to document properties
    find frame rate(which is usually 12 for my PC ;D)

    then change it to as fast as you want it
    :O

    i know its amazing isn’t it
    o.O

  • Temporal

    For those having Trouble with the Score:

    Make a text box on it’s own layer and resize it how you’d like. Click on the text box and look at the properties tab, make sure this is set to Dynamic, and set it’s variable to “score” (Which is NOT the box below where you select Dynamic, it’s below where you set the size of the text You might need to hit a little triangle shaped button on the bottom right of the properties box to see it).

    THEN click on the first frame of that layer (in the frames above your work area, where you make new layers, click on the first dot under “1”). Now type the actionscript into that. “score = 0;”.

    The problem you guys are probably having is the same that I did, not actually realizing what the variable box was.

  • Dragolux

    Man, I only got 14. :( Oh well. Great tutorial, EF!!

  • Azz

    BOOYAH i got 16 points XD even took a screen shot =p

  • peter

    lots of people have problem with that score thing

    i have another “problem”

    _root.coin._x = Math.random()*400+50;
    _root.coin._y = Math.random()*250+50;

    i think the numbers are so that the coin doesn’t get out of the screen, but how do u get hold of those numbers, is it trial and error?
    because in part 2 only the _x is given and i tryed the same code only _x i changed in _y and sometimes my coin got out of the screen (not much)

    anyone can explain ?
    thanks already :)

  • i tweeked it a bit and now my guy is invincible and bounces off the wall and aims for the coins, plus every coin i get is worth some candy from a strangers van….

    nah im playin, pretty good tutorial though

  • Yay! I got a 31! I spent about an hour playing though… Anyways, great tutorial! I’m learning a lot.

  • andy 60

    yer me to sorry i’m probably missing something obvious its just the score i dont quite get :(

  • Goinginsane

    OK. I have followed everyones advice, step by step. I put “score” in the variable box. And I put “score = 0;” into the frame, and I have done it about 300 times and still NOTHING!!!
    I am literaly going insane. Help

  • jitz

    hey
    the tutorial was great and i got everything working and even the score goes up when the coin it touched BUT it doesnt stay after a split second the score goes back to 0 any idea??

  • spartan 117

    your site is the best action script site i have ever seen. i have given it to all my friends, we are making an rts, like age of empires, can you help?????

  • Mr. Flashie

    Cool. I love your site.

    Could you continue with your tutorial and help us making more interactive games, something like super-mario games?

  • ive got a better idea, i can make custom lives but its more difficult that what you want…

  • confused teenager

    newb question but i cant pick up my coin and i have triple checked the code and its the same… any suggestions

  • Lemony

    I have had quite a few errors, im the same as confused teenager.

    I think you need to be more spesific on where the code in question goes. Do all the codes go in the action script for the hero? Or do you put the coin code in the action script for the coiin itself,

    CoNfUzzLeD

  • Motherload.

    Make a treasure picture(not too big) and convert it to a MC, and give it the isntance of motherload,put in the following on the place where the “trigger”AS,

    if (_root.trig.hitTest(_x, _y, true)) {
    _root.trig.gotoAndStop(2);
    _root.motherload._x = 50
    _root.motherload._y = 50
    }
    if (_root.motherload.hitTest(this.hero_hit)) {
    _root.motherload._x = -1000
    _root.motherload._y = -1000
    _root.score += 700
    _root.motherload.gotoAndStop(2);
    }

    you get a motherload of points at 50 x and 50 y when you hit the trigger.
    Made by me.

  • And inside the treasure MC, add a stop script to the first frame, make a other empty frame in it, and put in same AS.

  • GOININSANE!!!!

    be sure to have a zero put int he text of ur dynamic text box,else it doesnt work.

    Sometimes Emanuale forgot the coin scripts and more.

  • klap

    on the “water” example my charecter always seems to be “under water” or sunken, any help?

  • Umer

    THis is the best tutorial i have ever had ,I have advice instead of writting
    _y = _y + yspeed or yspeed = yspeed + gravity
    & every thing like that Can also be written as
    _y +=yspeed and yspeed+=gravity
    Need Help I am Trying to make the game like this one http://www.addictinggames.com/maxdirtbike.html
    But Problem Is this tutorial do not Explain Rotation And hittest do not work with curve objects So plsz Reply plzzzzzzzzzzzzzzzzz

  • Malik

    your tutorials are very good but i cant seem to open the FLA files, says “The file format is not not recognized”, would you please be able to send me the originals for the first interactive box on this page. The one with the counter and the coin score board
    Please Thankyou

  • bensta

    woooohoooo these tourtorials or whatever are great and so is this bong

  • Bob

    how exactly do u get the score to work because i cant get it to work.

  • romario

    I have done everything as the tutorial but i can’t set the score . Plz help me

  • Owen

    I’m making a game where you move to the next level when you get a score of 10, and you move to the game over frame when you lose all of your lives. At the moment I have this:

    if(_root.score = 10
    gotoAndStop (5);
    }

    and:

    if(_root.lives = 0
    gotoAndStop (6);
    }

    but these codes just set my score and my lives to 10 and 0 respectively. How can I fix this?

  • Temporal

    Owen: You’re setting the score to 0, you need to use == rather than =.

    == is equal to

    = equals

  • Hey,

    I’m trying to add a moving environment (precisely like the rotating line) into my game. However, the ball keeps hitting imaginary objects. All other environment objects from the last level were deleted. Instead of adding the “score” to the rotation speed, I just have:

    onClipEvent (enterFrame) {
    _rotation = _rotation+0.5;
    }

    Is there a fix for this?

  • The_erik

    scored 21 :D

  • The_erik

    hey Emanuele, great tutorial :)

    i just have one issue though. I am trying to make a game, and i’m whenever i put more than 2 different hitTest’s in the actionscript of the hero, i get a bug.
    Whenever i trigger one of the hitTest’s that i added as the last ones, my hero gets set to the point where it was supposed to, but then it dissappears right after.

    What’s going on? :<

  • The_erik

    romario, please tell me excactly what you’ve done, and then i can help you :)

  • newbie

    i dont know where to put the score = 0; in im new to this so plz explain

  • Amy

    I’ve got a problem!
    Ive made a game like this but When I have math random on my coin it goes onto one of the blocks in the enviroment making it impossible to get the coin! Please help!!!

    Instances:
    Player = “hero”
    coin = “coin”
    Blocks (all are in one movieclip) = “environment”

  • Jesse

    I have a problem. I’m making a game, and I want to have walls to make my hero retreat, not kill him. However, these “walls” could be curved, such as a river. The script doesn’t work properly:

    onClipEvent (enterFrame) {
    if (this._parent._parent.House2.hitTest(_x,_y,true)) {
    speed*=-1 }
    }

    Could any one help me please? Thank you very much!

  • Pingback: Brettcr » Blog Archive » Programming Tutorials / Game Making Check Video Description download videos off you tube()

  • Thank you so much. Very neat tutorial! Easy to understand.

  • Pingback: Elise » Programming Tutorials / Game Making Check Video Description convert youtube video to dvd()

  • hero

    I have a question about how to make it go to a diffrent frame when the coin is reached. I am making a game so that when a coin is hit another moving obstacle appears. But when i add an actionscript like
    if (_root.coin.hitTest(this.hero_hit)) {
    gotoAndPlay(55); }
    It does not collect the coin and i do not know why can some one please help me?

  • Help me

    hi
    nice tutorial.
    i need help with the score. i have done the text named it and everything i put the code in the first frame. but when i run the game it just stays at 0 and does not move. i have flash 7 do you need to do something different.

  • apocalypsefu

    Very nice tutorial. Got 14 woo hoo!

  • you need to have
    _root.gotoAndPlay (number);

    this is because it thinks the character’s frames when it just says gotoandplay.
    ifyou say root.gotoandplay
    it means the scene.,
    if you say _root.wall.gotoandplay
    it means goto the wall frame 2.

  • woot

    woot 20 but then its way too fast….

  • when the ball resets in my flash game the reset position keeps changing, for example if it touches the boundary it resets at _x 497 and _y 80 but when it collides with the wall a second time it resets further up and to the right of the original position. My version of Flash will not read the download version of the tutorials so I cannot view that and recitify the problem, can anyone help?

  • Can any one answer Amy’s and Peter’s questions?! I would like the answer too!

    Also how do you set the rotation of the environment to the middle of the object? instead of the end

  • bl00dsoul

    18 lolz :P

    nice tut :)

  • newby geek

    Hello there, great tutorials indeed.

    though I have a simple question. Because all this code is AS1.0 I m trying to write all the code in the frame 1 of the timeline instead inside my movieclip. as adobe supports it is better and I want to write AS2.0 instead. so I ve changed a bit the code (created the functions actually) like this :

    stop();
    var score:Number = 0;
    var lives:Number = 2;
    // b is the instance name of my hero.
    b.onClipEvent(load) = function {

    var power:Number = 0.3;
    var xspeed:Number = 0;
    var yspeed:Number = 0;
    var friction:Number = 0.98;
    var gravity:Number = 0.1;
    var thrust:Number = 0.75;
    var wind:Number = 0.09

    }

    b.onClipEvent(enterFrame) = function {
    if (Key.isDown(Key.LEFT)) {
    xspeed -= power;
    }
    if (Key.isDown(Key.RIGHT)) {
    xspeed += power;
    }
    if (Key.isDown(Key.UP)) {
    yspeed -= power*thrust;
    }
    if (Key.isDown(Key.DOWN)) {
    yspeed += power*thrust;
    }

    xspeed += wind;
    xspeed *= friction;
    yspeed += gravity;
    _y += yspeed;
    _x += xspeed;

    if (_root.wall.hitTest(_x, _y, true)) {
    xspeed = 0;
    yspeed = 0;
    _x = 120;
    _y = 120;
    _root.lives –;
    }

    if (_root.apple.hitTest(this.hero)){
    _root.apple._x = Math.random()*320+30;
    _root.score ++;
    }
    if (_root.lives == 0) {
    _root.gotoAndStop(2);
    }

    }

    but I get errors about line 5, 17. the erros are :

    lines 5 & 17 : Expected a field name after ‘.’ operator.

  • newby geek

    typo :

    I have:

    b.onClipEvent(enterFrame) = function() {



    b.onClipEvent(enterFrame) = function() {

  • bug

    there is a small bug in that game, if you hold down right and down, you go through the line…, not that it helps that much :p
    and i got 13

  • Jesse

    33. if (_root.score <= 0){
    34. _root.score = 0;}
    35. else{
    36. _root.score -=2;}
    37. }

    40. if(_root.score <= -1){
    41. _root.score = 0;}
    42. else{
    43. _root.score ++;}

    That will get rid of Negative scores, but very great tutorial:D, I just didn’t like the negative scores so I fixed it.

  • Jesse

    Change that first If to <= 1 because that’ll fix the wall negative error :D

  • Jesse

    ps 16 was highest score

  • tom

    i’m trying to make the movie skip to frame 2 when the player reaches the score 10.
    i’ve tried:

    if (_root.score==10) {
    _root.gotoAndStop(2);
    }

    and this is not working for me. what can i be doing wrong.

  • flash noob

    how do u do a hittest and that when u hit it, it uses gotoandStop to goto the next level?

    someone help because i’m confused

  • Zakk

    Umm, im not haveing scripting problems so mabey i have a gift for that (im 13) but how do i make an object, like water, transparent?

  • Zakk

    And i just managed to get 17 points!

  • Pingback: reducedoverlarge » Trailer for the upcoming Echo Wall climbing film()

  • Pingback: forfreebigger » Diving with Sharks at the Chumphon Pinnacles, Koh Tao Thailand()

  • score newbie

    how do you get the scoreboard thing up? this is my current code can someone please correct it?

    onClipEvent (load) {
    yspeed = 0;
    xspeed = 0;
    wind = 0.00;
    power = 0.65;
    gravity = 0.1;
    upconstant = 0.75;
    friction = 0.99;
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    xspeed = xspeed-power;
    }
    if (Key.isDown(Key.RIGHT)) {
    xspeed = xspeed+power;
    }
    if (Key.isDown(Key.UP)) {
    yspeed = yspeed-power*upconstant;
    }
    if (Key.isDown(Key.DOWN)) {
    yspeed = yspeed+power*upconstant;
    }
    xspeed = (xspeed+wind)*friction;
    yspeed = yspeed+gravity;
    _y = _y+yspeed;
    _x = _x+xspeed;
    _rotation = _rotation+xspeed;
    if (_root.wall.hitTest(_x, _y, true)) {
    xspeed = 0;
    yspeed = 0;
    _x = 120;
    _y = 120;
    _root.score -=2;
    }
    if (_root.coin.hitTest(this.hero_hit)) {
    _root.coin._x = Math.random()*400+50;
    _root.score +=1;
    }
    }

  • inotellmyname

    i know im going to look stupid for asking this because its going to be a simple answer but.
    how do i make something that is not moving move?
    i made it so your stuck and when you pull the lever i want the wall to move away then stop. and you can get thru…

  • xZeRo

    Man this tutorial is great for newbs like me. I just want to know how you made the hero blend in with the water. It almost feels as if the hero is actually in the water.

  • Pingback: discountsize » 7 Tips for a Fun Filled Family Holiday Posted By : Johnn()

  • platformergameobsessed

    Hey everyone… I kept trying to use that code on the character and put a ground so my character would be able to fly and also be able to land on the ground. The problem is that my character falls right through the floor… can anyone tell what to change in the actionscript or if there is an entirely different way to make your character fly and land?

  • xZeRo

    Another question. How do u make the trigger go back to its original situation when the hero dies?

  • Bumbanut

    I have a question:

    How do you make the coin not just appear on the same line in different places, but random places on the screen (except for the wall)?

  • xZeRo

    Bumbanut, you notice that the coin is only moving along the x – axis:
    _root.coin._x = Math.random()*400+50

    “_root.coin._x” is the code in which it tells the coin to move in the x – axis.

    The code “Math.random()*400+50” is the area in which the coin is moving randomly.

    All you have to do is make it so that it can move in a random direction along the y – axis too.

    So the code will change the y – value of the coin.

    _root.coin._y = Math.random()*250+50;

    Make sure of how many pixels are the height of ur screen. I chose 250 pixels. This can vary in your stage.

  • Okay, Im quite a newb, and Im just trying to make a test game where its birds eye view and your a dot and you have to run away from other dots, through a maze. I have your code from the end of part 1, (thanx alot!), but I want it to turn you back, kinda like a bounce when you hit a wall, but just barely.

    I have this code:

    if (_root.wall1.hitTest(_x, _y, true)) {
    yspeed = yspeed*-1;
    }
    if (_root.wall2.hitTest(_x, _y, true)) {
    xspeed = xspeed*-1;
    }

    But (and this is the newbish part)

    Where would I put that in relation to the rest of the code? Is it at the beginning or the end? Someone plz help me!!

  • rob bob bobert

    very very good tutorial well done m8 well worth the effort you put in coz this was very helpful (written well) consider ego polished

    happy new year all

  • BenneyBoy

    Thanks to
    “28. trys everything on January 28th, 2007 8:54 pm”

    For helping me with the score box.

  • austin was not on the computer

    Im designing a video game currently… You are a dragon flying threw a massive dungeon. I made it so the lava pits work, but i cant get the score board functional, also i need some script on how to creat solid flooring,i whish to make him able to walk on land..

    My current code
    }
    if (_root.gem.hitTest(this)) {
    _root.gem._x = Math.random()*400+50;
    _root.score ++;
    }
    }
    All of the other tutorial has benn really swell so far, thnx it was really helpfull…
    Wow i must sound like a winy nube, after all im only 13
    Sincerely
    Austin C.
    PS plz any one feel free to answer if possible

  • ANSWER to half your questions. i think.

    Instead of
    score = 0;
    on the frame, do,
    var score = 0;

  • IFG

    Prolly the best tutorial ive ever read, ive seen tutorials that show u what to do, but this one is so much easier

  • Lemony Emily killed a noob

    Like Austin, I need to make a solid border/surface that is not deadly, so my ninja will not fall out of the playing area.

    ATM I have removed gravity because it was making my friends go “WTF” But I need gravity for my ninja to “jump”.

    Please feel free to email me.

    Lemony Emily :)

    Oh and btw Austin im only 12 ;P

  • Pingback: Yourothermind » Blog Archive » Not a Flash game - Brent Knowles' Blog and Writing Software()

  • Bumbanut

    Yeah, hey. Thanks a lot for helping me! This game I made is really cool with your help. I added some things and removed the ones I didn’t want, added new character, a main menu, and now it’s great! Thanks!

  • NEAR

    Dear, Emanuel feronato, Italian geek and PROgrammer, or any PROgramar who sees this and can help me out

    I love your tutorial, and have been making horribly difficult levels for my friends to attempt to beat, they love it! Unfortunately, I have a problem! On one of my levels, I have three coins with instances coin, coin_2, and coin_3, all of which are programmed to teleport randomly when touched by the character and certain tweened killing environments. Unfortunately, they occasionally teleport outside the wall program, this is a huge dilemma, as it makes it nearly impossible to get any higher than 5 points!

    I have a theoretical code that I think would probably solve the problem:

    onClipEvent(enterFrame){
    if (_root.coin.hitTest(outside stage)){
    _root.coin._y = Math.random()*400+50;
    }
    but, it is full of errors, can you help me?

    Also, can you make a tut for highscores? I want my friends to be able to compare highscores, and I didn’t see a section covering it when I skimmed ahead in the tutorial.

    Thanks for reading!
    Please post back!
    -NEAR

  • NEAR

    Woopsie, me again, I found the answer to my own question, the
    _root.coin._y = Math.random()*400+50;
    is basically setting up the area where your coin can pop to, so I changed the code to
    _root.coin._y = Math.random()*280+50;
    on my coin actions and it worked like a charm.By decreasing the numbers I decreased the coin teleport area.
    Also, expirement with X and Y coordinates if you want your coin to go all over the place!

    Thanks for the free tuts emanuel

  • zard

    highest score = 1;
    i prefer to program with classes its more organized

  • DannyDaNinja

    Highest score = 13

    i plan to make a game using these tutorials! i’ll say thanks to you in the credits!

  • Helpmeplz

    I wanna make another level so when i get 20 points i ll go to the next level and i dont know qhy these actions here doesnt work

    if (score=20) {
    gotoAndStop(706);
    }

  • Helpmeplz

    PS:and where put these actions

  • Sam

    I am an absolute beginner and I’m wondering how do you even begin creating a game? Do I need any special software?

  • Pingback: Tips: Teaching yourself Game Development – Brent Knowles()

  • philzero

    For those still having trouble getting the score to work after trying everything in the comments above:
    Go to text > Font Embedding
    then add the font you are using, and click ok.

    Now it should work.

  • justin

    im new, but i made a dynamic text box and labeled it “score” for the instance name, and nothing happens..no score changes..what do u think i did wrong

  • justin

    nevermind. i fixed it..i didnt realize that i needed to var name it and put 0 in the text box itself.

  • zeeshan

    hi, great tutorials..very helpful for beginners.
    i have a Question..i mean i really wasn’t able to do that “insert ‘hero_hit’ into ‘hero’ movie clip”, i read comments,etc but didn’t find solution..i tried that in all possible ways that came to my mind but no luck..can anyone explain that how to do that part ‘from 2nd tutorial’?..I am Stuck.
    thanks. :)

  • Alright, i couldn’t get the score to work, i just don’t have the faintest idea as to how i make the text box show the score:/

  • iamanoob

    i am completely new to flash and am trying to make this game but tweak it a bit. i added lives and tried to make it so that 50 score == 1 life and such….. i couldnt get it to work…. this is the code i tried

    if (_root.score == 50) {_root.lives ++}

    btw i am only 13 so dont make me feel bad lol

  • For those having score probs,put the varible “score” is the varible textbox in the text’s settings

  • Im LEARNING!

    I have created the level “The playing environment” everything is working but how do I make it change frame, for example after collecting 10 coins

  • Carlos

    When I make the score it’s there, but when I grave a point it says 1 and then goes bak to 0, and the same when I hit a wal, it says -2 and then goes back to 0, I don’t know why is this happening, if someone knows how to fix this please tell me. Thank You in Advanced.

  • Carlos

    I already tried out everything it says in the comments, but the score keeps going back to 0…

  • Nodnarb3~~~~SCORE FIX~~~

    Ok, because this took me forever to figure out, i will help all. to FIX SCORE:

    create text box. LEAVE it Empty! <Very Important!
    make it dynamic, and set the variable to "score"
    change instance to score
    now it will work with tut's coding.

  • Hey check out the game im currently working on. I may consider creating a few video tutorials to help out you guys with score issues. As i had some issues at first i know the pain of not understanding how to fix the damn thing. Im not making any promises that i will make a video tut. but its an idea. Anywho check out my game and leave feedback thanks :) http://adf.ly/5rfWd <– link to my site with the game on it.

  • William

    The tutorial is clearly explained, thanks. i am doing a school project and this really helps.

  • superman

    I belive that this is too easy and not as complicated as it should be too achive greatness! This is Maniacs!

  • raco

    How do u achive water transparency? Anyone?

  • raco

    In answer to my own question:
    In properties find color effect and chose alpha. Then just enter a value or slide the slider to specify the alpha value you would like.

  • flashlover

    Random and Emanuele Feronato, YAY, AS2 BOX2D PHYSICS EASY EDITION, YAY!

    GREAT TUTORIALS!

    :D

    i made my own– wait, no, you both ^^;

  • flashlover

    Yeah, and i must say: I’m 7 and i understood all of this. thanks emanuele!!

    :)

  • Manoj

    Hi …are there any tutorials similar to this one in AS 3.0 ?

  • Manjub

    It gets very tricky when the coin position is equal as the axis of rotation of the environment