Create a flash draw game like Line Rider or others – part 5

Finally this tut has its 5th part.

You should read steps 1 to 4 before continuing with this one, although this time it’s not so important, because before to approach the “running car” I am going to explain the “walking man” on a line.

The same kind of gamestyle you can find in draw play 1 and 2.

Believe or not, this is an important step to understand before adventuring into running cars.

Now, let’s start.

I said we are going to see a man walking on a line we created.

As usual the “line” is instanced as terrain while the code I am showing is the one in the “player” object… yes, that red box is supposed to be the player…

The player is falling

The first thing to do is determine when the player is falling and when the player isn’t falling. If you think about the real world, a man is falling when there is no ground under his feet. Or when he’s so drunk. Or both. But at the moment we are only interested about the ground.

So, let’s translate real world physics into actionscript:

Line 2: Set the gravity at 0.2

Line 3: Set the yspeed (vertical speed) to zero

Line 6: Checks if _root.go is true. This is true once the “go” button is pressed. It’s not important for the game, I put it just to make the movie wait for a user input before starting.

Line 7: Gravity calls… yspeed is increased by gravity value.

Line 8: Performing a hit test between the terrain and the _x, _y+_height/2 spot. Since the anchor point of the player is on its center, you can easily understand the spot is located in the middle on the bottom side. Basically, the player’s feet.

Line 9: raising the player of one pixel (obviously, since the player must be sunk at the moment)

Line 10: set yspeed to zero (no need to fall if we are sunk into the ground)

Line 12: add yspeed to _y position

Look at the movie:

The player is not stable to the ground. Maybe the floor is too hot, maybe the code has something to be fixed.

The problem is that once the player touches the ground, I continue adding yspeed to _y position, so the player sinks a bit into the ground. Then, the while loop raises him a bit, just to watch him sinking again. That’s why the player seems to flick.

The player is falling – part 2

I need a hack to tell the “physics engine” to stop considering yspeed if the player has its feet on the ground

Lines 12-13: The yspeed value is added to _y (old line 12) only if the player is in the air. Look at the +1 in the _y+_height/2+1. I need to “forecast” next player’s position and if I find it will be in the ground, then I stop considering the gravity. Otherwise lines 14-15 set yspeed to zero.

Now the player is falling in the right way.

Let’s make him walk now.

The player is moving

To make the player move, we need to check if some keys are pressed and manage the x speed according to the key pressed.

Line 3: Set x speed to 1

Lines 8-10: If the left key is pressed, I move the player xspeed pixels to the left

Lines 11-13: Same thing with the right arrow key

Now the player can walk!!

But… try to walk to the left margin of the stage… or to the right one… you may notice there is a hard slope, but the player walks on it as if it was a plain ground. That’s not realistic!!

The player is moving – part 2

In order to make the player stop walking when on a too hard slope, we have to define a “knee” point. If the “knee” hits the ground, it means the ground is a hard slope, or a stair, o whatever thing the player can’t climb.

Line 9: Before moving the player to the left, I assure his “knee” (located to the leftmost side of the square at a quarter height of the player) is not touching the ground.

Line 14: Same thing with the right side.

Now the player cant’ walk on slopes!! Now we want the player to jump

The player is jumping

To make the player jump, I am going to check if the SPACE key is pressed

Lines 18-20: If the SPACE key is pressed, the yspeed is set to -5 (since yspeed is affected by gravity, a negative value will make the player fly).

Line 26: In the if statement I add a check: If the yspeed is less than zero (player jumping) I add the yspeed to _y even if the player is not going to touch the ground. Without that condition, the player will never jump.

Look at our jumping player!

Again, it’s not over… as you can see, if you press SPACE while the player is in the air, the player will jump again, and again… you can make the player fly and I don’t want it.

The player is jumping – part 2

I need a variable to decide if the player can jump or not. Basically, a player can always jump execpt when he is already jumping

Line 5: initializing a variable to tell the player is not jumping

Line 19: Added the control if the player is NOT jumping when SPACE key is pressed.

Line 21: Set the jumping variable to 1. Actually, the player is jumping (so he can’t jump anymore until he touches the ground)

Lines 27 and 33: Set the jumping variable to zero. When the player is hitting the terrain, or when the player is about to hit the terrain, he is not jumping, or the jump is over.

There are some other things to fix but at the moment it’s over.

Download the full source codes and give me feedback

  • Pingback: Create a flash draw game like Line Rider or others - part 1 at Emanuele Feronato()

  • Pingback: Create a flash draw game like Line Rider or others - part 2 at Emanuele Feronato()

  • Pingback: Create a flash draw game like Line Rider or others - part 3 at Emanuele Feronato()

  • Pingback: Create a flash draw game like Line Rider or others - part 4 at Emanuele Feronato()

  • Alex

    NICE JOB
    A

  • Thank you so much!
    Your tutorials are some of the best on the net…
    This Line Rider game is something I’ve been wanting to build since I started with Flash…
    Your Actionscript explanations are thourogh and clear; and the game I made with parts one through four has been played for hours by both my sisters… I usually create an obstacle course, and let my sisters find their way around it…
    One thing I’m trying to learn to do is influence the “ball” with the arrow keys. I’ve managed to add a “reset ball” button which resets the ball and allows you to add terrain. A “line erasing” tutorial would be great also…
    Keep up the great work and simple tutorials!
    -Alec

  • Oh… Wow! I did this tutorial and input
    if (Key.isDown(Key.RIGHT)) {
    _x = xspeed;
    into the ball code; right after the collision code for the first tutorials… Now, by pressing the up key while close to the ground, the ball flies far higher than before. This is useful for annoying spots where the ball is stuck behind a wall or in a crevice…

  • mousey

    very cool.

  • george

    Thanks man. i made a sweet game because the tutoirals you have explain everything clearly.

    can you add a part 6 and make an erase button to delete some lines without eraseing them all?

    cool

    :)

  • george

    Woops. almoast forgot.

    i made a “free play” part in thr game other than the levels.

    can you tell me the code to move theexit with the arrow keys.
    i copied the code for movement from my “hero” game (one of the tut’s u poasted very cool) but it dosent work.

    HELP ME lol

    :)

    • ALEX

      I don’t quite know how you could properly make it move with the arrow keys, but if you made the exit a movieclip and then INSIDE the movieclip make it a button, and type this code into the button:
      on (press) {
      startDrag(_root.nameofyourexitmovieclipnotthebutton, true);
      }
      on (release) {
      stopDrag();
      }
      and keep the coding the same on the movieclip or whatever for the button, that should allow them to click and drag it but maybe it would interfere with the drawing? Don’t know haven’t tried it try it and tell me what happens have fun man

  • srikant

    which version of flash player is required to develop this

  • And Mar

    Awesome tute!

    In your next one I would really love to see how to make the car/ rectangle rotate so both wheels would be on line.

  • abhilash

    excellent!!
    can’t wait for next!!

  • bigbill

    Excellent however im using your coding but I’m still seeming to get the bobbing action in certain areas?

  • I have a question for anyone who reads this… Thanks in advance…
    How would I code the exit point to take the playhead to the next frame? I would really like to know this because then I can have levels. I’ve seriously tried everything, but even without the “stop code” the ball freezes on the exit point.

  • abhilash

    in reply for alec:
    its simple, copy the below code for ball
    onClipEvent(enterFrame) {
    if (_root.exit.hitTest(_x, _y, true)) {

    _root.gotoAndPlay(FRAMENUMBER)
    }
    replace FRAMENUMBER by the frame you want to go.
    I’m not sure it will work but still you can try.

  • hasna

    george: make a button in the exit mc with this action script:

    on (press) {
    drag = true;
    }
    on (release) {
    drag = false;
    }

    and on the exit mc put this code:

    onClipEvent (load) {
    drag = false;
    }
    onClipEvent (enterFrame) {
    if (drag == true) {
    this._x = _root._xmouse;
    this._y = _root._ymouse;
    }
    }

  • .Kada$h

    That’s so cooool
    You’re really good at it
    I’d like to be as fantastic as you are :D
    I also have MFP 8 I’ve just downloaded it and like now I don’t know what to do with it ^^ I’m learing how to use it :D
    I used Adobephotoshop before…
    .Cheers

  • abhalisha i enterd the action script an**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 17: ‘else’ encountered without matching ‘if’
    } else {

    **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 74: Unexpected ‘}’ encountered
    }

    **Error** Scene=Scene 1, layer=Layer 2, frame=2:Line 17: ‘else’ encountered without matching ‘if’
    } else {

    Total ActionScript Errors: 3 Reported Errors: 3
    d it didnt work it said

  • name

    i was wanting to make a game sorta diffrent to this were u can move but without gravity as if your looking for a birds eye view.

    you can move all derections but cant go through lines. sort of like whats happening here but i dont know how to do it could you help me?

    it a bit hard to explain lol soz if this makes no sense :S

  • eblup

    hey iam kinda mad at you because you kinda coppyed my code but o well. my code:

    onClipEvent (load) {
    j = 0;
    c = 1;
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
    if (c > 0) {
    j = -6;
    this._y -= 6;
    c = 0;
    }
    }
    }

    onClipEvent (enterFrame) {
    if (j > 3) {
    j = 3;
    }
    }

    onClipEvent (enterFrame) {
    if(_root.ground.hitTest(_x (_width/2),_y,true)){
    _root.ground._x = 10;
    }
    if(_root.ground.hitTest(_x-(_width/2),_y,true)){
    _root.ground._x -= 10;
    }
    if(_root.ground.hitTest(_x,_y (_height/2),true)){
    _y -= 3;
    j = 0;
    c = 1;
    }else{
    j = 1;
    this._y = j;
    }
    if(_root.ground.hitTest(_x,_y-(_height/2),true)){
    j = 3;
    }
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)) {
    _root.ground._x -= 6;
    _xscale = 100;
    _root.guy.gotoAndStop(2);
    }else if (Key.isDown(Key.LEFT)) {
    _root.ground._x = 6;
    _xscale = -100;
    _root.guy.gotoAndStop(2);
    }else{
    _root.guy.gotoAndStop(1);
    }
    }

    can you try to make it so when he goes up a hill he tilts like in fancy pants advinture

    plz reply

  • eblup

    i used youre code with my code to make

    onClipEvent (load) {
    j = 0;
    c = 1;
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
    if (c > 0) {
    j = -6;
    this._y -= 6;
    c = 0;
    }
    }
    }

    onClipEvent (enterFrame) {
    if (j > 3) {
    j = 3;
    }
    }

    onClipEvent (enterFrame) {
    if(_root.ground.hitTest(_x (_width/2),_y,true)){
    _root.ground._x = 5;
    }
    if(_root.ground.hitTest(_x-(_width/2),_y,true)){
    _root.ground._x -= 5;
    }
    while(_root.ground.hitTest(_x,_y (_height/2),true)){
    _y–;
    j = 0;
    c = 1;
    }
    if(!_root.ground.hitTest(_x,_y (_height/2),true)){
    j = 1;
    _y = j;
    }
    if(_root.ground.hitTest(_x,_y-(_height/2),true)){
    j = 3;
    }
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)) {
    _root.ground._x -= 5;
    _xscale = 100;
    _root.guy.gotoAndStop(2);
    }else if (Key.isDown(Key.LEFT)) {
    _root.ground._x = 5;
    _xscale = -100;
    _root.guy.gotoAndStop(2);
    }else{
    _root.guy.gotoAndStop(1);
    }
    }

  • sirus

    are u making a next part or is this the last?

  • Emanuele Feronato

    It’s not the last… a lot more will come.

  • madpassion

    help meee..lol…i got lost on the very first step :( .Im not that experienced.

  • Jesuson

    THANK YOU !!!!
    I want to tell u how useful are your tutorials.
    I start to learn actionscript with them and I have beem trying to complete the develop of a game like line rider since some weeks ago.
    After try to write the script for collisions using the hitTest in all the ways I have found a better method in a flash called attractors.
    I´m next to coplete the game. Here I write the links for “attractos” and for my “line cross rider” preview.

    http://www.thecleverest.com/content/attractors.swf

    http://denvish.net/ulf/180407/4978_Line_Cross _Rider_beta4.php

  • Blarg

    Hey, Love your tutorials. But i was wondering, are you going to do a tutorial on how to make a game like the one on this page? http://www.playgamesclub.com/online-games/puzzles–brain-online-games/free-rider.html

    Thanks for your work so far and I’ll be waiting for a reply.

  • Emanuele Feronato

    I think it’s simpler than LR.

    A good idea for an intermediate step, I’ll try to do something like this.

  • Blarg

    Ok, thanks very much. BTW, is there any way to use the script you have provided, along with the drawing script, to make a basic game like the draw play? because i’ve been trying and it’s not really working… I’m really not the best at Actionscript.

  • Blarg

    And, if you dont mind me asking, when do you think you’ll have your next tutorial out?

  • Hi, I’m new to actionscript, and I was wondering if you could publish a script to tell me how, that if you press space when you’re already in the air, it makes no difference, you start descending after hitting the space bar once.

  • oops, sorry, you already do it

    could you do something for a scrolling screen please?

  • Please can you make a tutorial on how to make a game like adventure quest

  • Grifo

    Hi Emanuele.
    You’re great at Code(and you’ve got the biggest patience I’ve ever seen too).
    I was wondering, how do you estabilish the player’s position
    over the platforms, after he jumps from beneath one of them?
    I saw lots of people doing this, and lots of mistakes as a result. Do you simply estabilish a fixed position one some part of the square

  • Grifo

    Hi Emanuele.
    You’re great at Code(and you’ve got the biggest patience I’ve ever seen too).
    I was wondering, how do you estabilish the player’s position
    over the platforms, after he jumps from beneath one of them?
    I saw lots of people doing this, and lots of mistakes as a result. Do you simply estabilish a fixed position one some part of the square

  • Pingback: Create a flash artillery game - step 2 at Emanuele Feronato()

  • Tim

    Um…when can we expect part 6? i’ve been waiting for quite a long time and would love to know how to continue making the game.

  • That would be nice. If he does make another, my guess would be it would be near the end of june.

  • Yah, will there be a part six? Are you making one? Please post a reply for us.

  • Emanuele Feronato

    Sure, I am working on it

  • Art

    Emanuele your the best, now I can program really well because
    of your tutorials. I’m kinda knew to actionscript.

    What dose this operator do?” while () {} “

  • hi, ur great.

    i wondered if in the next part you will be including screen follow.

    please do.

    cud someone show me how to go back to the start point on collision with, for example, spikes? creatin a platform game

  • Art

    Hi

    crawfy, you wanted to know how to restart a players position, here:

    _root.spike.hitTest(_x, _y, true){
    _x = 5
    _y = 5
    }

    or for the hitTest you can use this:

    _root.spike.hitTest(this){}

  • Art

    Very cool tutorial,
    what dose this code mean though? :

    while () {}

    thanks in advance :)

  • How do you make the square adjacent to the line? the bottom of the square says flash and does not go flat with the line? can you tell me?

  • tim

    how could i remove the line after i drew it?

  • person

    your tutorials are the best, I come to this site all the time to see when part 6 is done.

  • Adventure quest can’t be made purely with flash doom boy, you need to set up and server and create a few php scripts and some databases. which take lots of money.

  • crawfy

    thanks art

  • line rider 1.

  • Chad Horton

    I am trying to reach you about business opportunities

  • badri

    iam seen your tutorials it is very nice but now iam in learning stage. Will you please give me some simple and best examples which I can understand easily thankyou

  • Marius

    Hi

    Just found your tutorial and it’s awsome, thank you! When does tutorial number 6 come? I’d love to see another part of this great tutorial…

  • Redoox

    Good and clear tut.

    But it made me wonder how far that “nice red block” actually can jump!!

    you can try it out yourself: :P
    http://redox.awardspace.com/sports/pituushyppy.html
    Same keys as in this tutorial..just jump on to red line..and..oh well,that was it.

    (yep,I was bored…)

  • Emanuele Feronato

    10.323

  • SHIV

    hi
    very nic tut man
    can u explain how to make guns and all
    like a movieclip gun which has a bullet movieclip or something. PLS.
    with limited ammunation and special effects while shooting like black smoke or sparks or somethin like that.

  • SHIV

    hi emanuele,
    pls explain how to create a game like mortal kombat in which 2 guys fight (player 1 and player 2) using diff powers. And some powers can only b used when there is a graph full or something.
    ALSO
    explain how to make a graph which indicates score or life instead of dynamic textboxes.

  • don

    i dont get it at all

  • John

    Hi! I am making a game for commercial purposes, and I was wondering if these action scripts for the flash draw game are copyrighted, or are they free to use for my game. If I could use them, I would be happy to site this website in the game, if you want. thanks!

  • Emanuele Feronato

    Feel free to use the script as you want, thank you for giving me a credit, once completed send me the game and I’ll publish on my site.

  • dfahasdfh

    i’ve been waiting for part 6 for almost half a year, do you know when it will be done? thanks

  • Maggot

    Thank’s
    I’m just starting with flash and i really have to admit that you’re tutorials are the clearest and most explained i could find on the net.

  • Jeffrey

    I DOWNLOADED YOUR “FULL SOURCE CODES” AND THEY CRASHED FLASH!!!!!

  • olli

    ok….why the hell when i click download all sources i get all the pictures ive ever seen on the internet,all my friends bebo/myspace pics,i have got MILLIONS i want a fucking good explanation cuz i am pissed off.i want to know how u got all of my m8s pics aswell onto my laptop.REPLY.

  • Emanuele Feronato

    I think it’s something on your computer.

  • I’ve been making a platformer where I can just draw a terrain with the paintbrush tool and my character (currently a square) will be able to walk and climb around on it. Hopeuffly, these tutorials might help me program working slopes. Right now they work… sort of. I’ll try to get some better guidance from your codes. Which are totally awesome, by the way.

  • Cory

    Very nice man. Except one thing….. if you don’t jump but instead WALK off the platform, you can still jump… midair. Very well explained… thx.

  • Riccardo

    hey cory, that’s not hard to solve.
    in my game i’ve added a “collision” boolean.
    whenever gravity is applied, collision goes false, when it’s not it goes true.

    so if you go off a platform, the boolean will go false, and you won’t be able to jump, since in my game the jumping code is like this:

    if (Key.isDown(Key.SPACE)&& collision==true)

  • Cory

    I was just saying… besides, there’s a FAR easier way.

    onClipEvent(enterFrame){
    if(yspeed>0.1 or yspeed<-0.1){
    jumping2=1;
    }else{
    jumping2=0;
    }
    if(Key.isDown(Key.SPACE) and jumping2==0){
    yspeed=-4;
    }
    }

    Emanuele, you should add that to the tutorial. Also, you should change the gravity to make it larger and the jump speed to make it like -6, so that it remains the same jump height, but it makes it so that the player gets less jump time, making it look more realistic.

  • Cory

    Art Said: Very cool tutorial,
    what dose this code mean though? :

    while () {}

    thanks in advance :)

    that command is like the *for* instance, but instead of manipulating a variable, it just does it until the condition isn’t correct anymore.

    For example, in this it says:

    while (_root.terrain.hitTest(_x, _y+_height/2, true)) {
    _y–;
    yspeed = 0;
    }

    think of it like this. UNTIL that condition ISN’T right, do the action. Hope that helps.

  • Stu

    could you make it so if the man is on the slope, he then is leaning as if he was on the slope.

    if that makes sence…

  • David

    Hey! I really like you’r tutorials, but I tried to add

    this.gotoAndStop(2);

    as in

    if(Key.isDown(Key.RIGHT)){
    this.gotoAndStop(2);

    But that didn’t really work… Could you help me a bit? I want a animation that is on frame 2 of the “guy” movieclip to start when you hit the key right. Also you should make a key setup “tutorial” so that you can use w a s d etc.

  • ises

    great tutorial !!! thank u so much, it’s really help me.

  • EagleVision

    When are you going to make more tutes?

    Are you going to continue this? Reply please! :D

  • quick

    I want to see that too.

  • Grayson

    make it a button then put for the script
    on(rollover){gotoAndPlay(*)}

    * = the number of the frame you want to goto
    but you will have to edit this so that when the block rolls over it goes to the next frame
    cause the script there will make it so when the mouse rolls over it goes to the next frame adn we dont want that sry if this didnt help much cause i am still editing the code so that the blob is what needs to go ovewr it

  • I deleted the CreateEmptyMovieclip and made a movieclip with the terrain name & stuff, but when I draw, it draws really far away to the bottom right of the mouse. HELP PLZ???!!?!?!!!!!?!?!?!?!

  • AirData

    Like a few others here, I’d like to know how to make the “hero” rotate naturally as it moves up hills and down hills. Like if the box was a car the “hero” would rotate.

  • Hi, first of all, thanks for this amazing tutorial :D

    But I have one question,
    I made a terrain which is bigger than the window, and I want prevent the character walks out of the window. I want the terrain also to move when the character is almost out of the window.

    I dont know if my question is clear because my English is pretty bad :s
    But maybe an example will help, everyone knows the supermario game I suppose…
    Well, in supermario the terrain also moves, supermario is always centerred in the window.

    I hope someone can help me :)
    –bram–

  • Bram,
    All you need to do is

    onClipEvent (enterFrame) {
    if (_root.go) {
    if (Key.isDown(Key.LEFT)) {
    if (!_root.terrain.hitTest(_x-_width/2, _y+_height/4, true)) {
    _x -= xspeed;
    //this is where you change
    _root._x += xspeed;
    }
    }

    when will the next tut be out?!

  • Ryan

    Great tutorial – my only problem is that the ball won’t stop bouncing. Does anyone have the code to stop the ball from bouncing like in real life? Many thanks if anyone is talented enough to help. :)

  • is there any way top print all tutorials form 1 to 5 because its hard to read all of them and do some reasearch along like if i want know what are parameters of sin in flash i am not opening flash again agian Right plus if i have papers i will be able to read anywhere and anyway so plsz reply also reply on email
    My Web fire08.110mb.com

  • sem

    i hope this works

  • hi,my name is rick roberts & i am intersested in learing how to create my own video game one day & i would like to say that this is the best tutorial i have seen in a long time & i have seen alot of them i am a rookie when it comes to creating but i do understand what to do.i would like to ask if you can, can you please try to explain to me more of how to work this because i understood alot of whet you put on the tutrial but some it it just didnt make sense or it cold be because i have only been doing this stuff for like two months lol.well anyway if you can please try to help me out i would apprciate it alot thank you rick!!!

  • Nice I This Part Was Easy IF Compare To previous parts hey explain previous parts more

  • beau

    hey do you hav a code to change the lines color?i cant find 1….

  • Alec

    im a different alec

    how do you make the exit goto the next frame?

  • is there any chances to do this tutorial for a “online players” like.. http://www.ff0000.com/ ?

  • Hi.

    I’d like to say that I really like this tutorial and that it would help me make my own side scrolling computer game in flash.

    Unlike most platformer tutorials that only handle flat platforms, this one can be made to handle not just slopes but also oddly shaped platforms.

    I used to use “if” statements for hittests but now I know “while” statements work better.

    Thanks.

  • paul

    Hi,
    I love this tutorial and its a great tool to know how to “draw” on the screen.

    My question is, how do you save it now?
    you mentioned in part 1 that you would tell us in part 2 how to save, but I never saw it.

    Can anyone tell me how to save the drawing?
    i am familiar with php/xml and the likes, but code and function wise i wouldnt know where to start

    thx in advance

  • al

    ummm… what are we posting these actionscript codes on.

  • erick

    no entendi ,si se hablar ingles, very well i need to say but, no se que es eso de actionscript el codigo donde lo pego o que hago con ese codigo lo pego en los fremas de macromedia flash o que? que hago!

  • Xodus

    erick’s translation (with Google Translator)

    not understanding, if we speak English, very well but i need to say, not what do you mean, actionscript code where you hit or what I do with this code hit in the Fremen of Macromedia’s Flash or what? I do!

  • i wil like to make a game please

  • I made a game with this code, it works fine. However, I want to add a zoom, a scroll, and a change line color function (I could probably figure that one out). To give whoever responds to this an idea, I have no preset lines. I have a draggable exit, a car for the player (who can’t move himself) and a large blank background.

  • chase

    wow you dont have a clue how much you have helped me! thanks so much. ur the man!!!!!!!

  • Little Boy In The Puff Ball Hat

    Wow, im making an all in one that ive just started and will be soon publishing it so until then thanks for the tutorials, they helped alot!

  • bitCulture

    Hi! This tutorial has been very helpful… You may not check the posts here this long after the original but if you do can you help me understand something? I coded everything once through, exactly the way you did it, and it works perfectly, of course. But I wanted to try and create a persistent universe and move the terrain rather than the player. I tried doing everything, but reversing the values and applying them to the map instead and my first few attempts were totally unsuccessful. I’ve decided to make it simple and just try doing it again, piece by piece using the inverted values and player/terrain x/y values but I can’t even get the gravity function to work right.

    while (_root.map.hitTest(player._x, player._y + player._height / 2, true))
    {
    map._y++;
    yspeed = 0;
    }

    when this executes, the map just jumps way below the playerMC. Any idea why this code would behave differently just because the map is being moved in the while loop rather than the player?

    Again, this tutorial is awesome and thanks even if you can’t or don’t help. :D

  • bitCulture

    Okay, so a sudden flash (no pun intended) of inspiration hit me. This code, for some reason, will reset the map based on it’s bounding box and not the player’s shape flag test.

    Looks like I’ll have to fish around some more.

    Thanks anyway!

  • ShroomedOut

    Thank you very much!
    I’ve been looking for a tutorial for making “solid objects” for a long time.

  • Black Dragon

    very nicee
    my shot yeeahhh!!

  • nacho

    excellent tutorials emanuele!
    may I ask what the “!” symbol in lines 19 and 29 of the last actionscript mean?
    couldn’t figure that out…

  • Nice tutorial BTW, although I dont believe this is a line rider game more of a line bounce game, but it does set the foundations for experimenting

    @nacho
    The explanation mark ” ! ” reverses the if statement, so…

    if(variable == true) // if variable equals true

    if(variable != true) // if it doesn’t equal true

    In the code it is placed before a function and is checking to see if there isn’t a hittest and will run the first part when the ball is not touching the terrain.

    Kirupa have lots of helpful information on ‘if statements’…
    http://www.kirupa.com/developer/actionscript/ifelse.htm

  • Stu

    Part 6?

    i’d love to know how to get the sliding down the slopes like line rider working, i’ve been working on my own engine for a while now. but i’m not sure how to get the sliding down the slope working nicely enough

    part 6 would be greatly appreciated

  • Clic

    GREAT tutorial ;D
    But,I have a question though,

    In my game, there is a “bar” on the bottom of the screen that works as a menu.
    It works fine, but, the “terrain” (the line you draw) goes over the menu. I mean, you can draw on it.

    And I don’t want that.
    Can you/someone help me?

  • Thanks for this tutorial game scripts. Cool one, I’ll try to read on and study your work.

  • Jaren Jackson

    I’m no good at physics can someone send me a script to make him “RIDE” the line or somethin like that

  • MegaSonicX

    How do I turn this into a file that can be played using Macromedia Flash Player

  • ankitesh jha

    sir,
    your tutorial was very helpful.

    but sir i am a bit confused how to create a terrain which consists of scrolling buildings with some gap between them??

    thanking you
    ankitesh jha

  • Randomman159

    As you said at the top of the tutorial, a “rider” will follow…

    And how long is it until this “rider” will be shown to the public?

  • Dave Oliver

    Hi I was planning on using this code to develop for a game for hospitialised children to play, do you think this would be ok?

    • Emanuele Feronato

      Sure! use it as you want

  • Silent Shadow

    I had fused the first one and the 5th one together by taking the terrain off of this one and put the source code in the movie of this on and changed the character that moves to a stickman so now i made the terrain thing be drawn but i’ve been trying to look for something that can clear the screen and reset the main part can you help

  • CheeseToasty

    Thank you so much for making your tutorials, you realy saved my butt, I had to program a couple of flash games for an assignment and i couldnt work anything out. This has realy helped.

    Also, i found another quiwk in your unlimited jump step of the tutorial, if you jump off screen, when you fall you fall throught the ground. Why?

    Thanks,

  • First of all I apologize for my poor English. Thanks for your tutorial. I found your site yesterday and i read lot of articles in your site. you are explain well. I like your car racing tutorial. Because i try to make game like that. But i couldn’t make it good. In your tutorial you explain well how to do it. Good luck..

    Please any one help me about this trouble. How to coding a player that moving smoothly in slope. Not up/Down movement.