A Flash Developer Resource Site

Page 1 of 11 12345 ... LastLast
Results 1 to 20 of 211

Thread: [Resolved] PLATFORM TUTORIAL.....

  1. #1
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Ok lets get this goin Ill give you the fla at the end..

    1. This will not be a complete game rather the bare bones of a game.
    2. This tut will show the very basics of a simple platform engine.

    Scenario:
    =========
    When you press LEFT and RIGHT arrow keys the ball moves left right
    when you press SPC the ball will jump
    when you walk off platfrom ball drops
    Collectibles
    climbing ladder.

    Strategie:
    ==========

    We will script one platform, the ball, one collectible, two ladders!!
    NOTE: 2 ladders you will see why..

    Begin:
    ======
    Stage w:500,H:400 background White.
    now goto Window---Pannel--Info
    Layer 1: name platforms:
    make a blue sqr..W:500px:H 13 px,X=0,Y=315;
    layer 2: name ball
    make a ball...12px:12px, X=65.0,Y=304.1

    convert the ball to MC and give an instance name hero.
    convert the blue sqr to a MC..no instance name.

    Making the ball jump:
    =====================
    Right click--Action pannel..

    onClipEvent (load) {
    vel_y = 0; -- when jumping this will be the vellosity now its 0
    accel = 4; -- vertical acceleration
    jumping = false; --currant jump status false
    }

    onClipEvent ( enterFrame ){
    if (key.isDown(key.SPACE) && !jumping) { --if key is down and we are not currantly jumping..
    platform ="no";-- we will be off the platform
    vel_y = 20; -- we will be jumping with this vellosity
    jumping = true; } -- and we are jumping in fact...
    if (jumping == true) {-- if we are jumpin..
    if ( platform eq "on"){--- if we landed on a platform stop falling..
    vel_y = 0;
    jumping = false;
    }
    vel_y -= accel;-- change the vellosity using acceleration
    this._y -= vel_y; -- displace the ball using the vellosity...
    }
    }

    Now get the acctions of the platform:
    onClipEvent (enterFrame){
    if ( hitTest (_root.hero)){
    _root.hero._y=this._y-12;-- if the hero lands adjust it so it sits on top
    _root.hero.platform="on"; }-- thell the hero that there is platform under
    see the jump code up..

    }
    Test Movie and press SPC to jump....

    I would sugest that you get fammiliar and uderstand the above code..get calculator and try to follow computers logic..

    Update:
    =======
    to make the ball move left and right insert this right under the onClipEvent ( enterFrame)

    if (Key.isDown(Key.LEFT)){this._x -=5;}
    if (Key.isDown(Key.RIGHT)){this._x +=5;}

    i think this is self explanatory


    to be continued...


    [Edited by Mad-Sci on 04-17-2001 at 12:43 PM]

  2. #2
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Ok I hope everyone had their balls jumpin and movin left and right..

    Now copy the platform in layer one and paste on the stage..get the info pannel and enter this..

    X=136:y=280

    Now try to jump on that platform.. you can copy and paste you can resize the W: but keep the H:13 px this is important the tickness should be the same..

    as you see you cannot go off the platfrom, but otherwise our engine is 50% done

    Ok play arround a bit try to paste more platform keep all of them in layer 1 tho..

    I will continue after a while with walking off the platforms and how to handle gravity...

    mad_sci

  3. #3
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    GRAVITY:
    ========

    no just bellow the left and right key events in the hero acctions insert this line:

    if ( gravity eq "on"){this._y = this._y+10;}

    and now we need one more variable:

    if ( platform eq "on"){
    gravity="on";--- if we dont jump there will be gravity
    vel_y = 0;
    jumping = false;
    } else {gravity="off";}--if we jump no gravity..

    final code for the hero:

    Code:
    onClipEvent (load) { 
    pos_y = this._y; 
    vel_y = 0; 
    accel = 4; 
    jumping = false;} 
    onClipEvent ( enterFrame ){
    if (Key.isDown(Key.RIGHT)){this._x=this._x+5;}
    if (Key.isDown(Key.LEFT)){this._x=this._x-5;}
    if ( gravity eq "on"){this._y = this._y+10;}
    if (Key.isDown(Key.SPACE) && !jumping) { 
    platform ="no";
    vel_y = 20; 
    jumping = true; } 
    if (jumping == true) {
    if ( platform eq "on"){
    gravity="on";
    vel_y = 0; 
    jumping = false;
    } else {gravity="off";}
    vel_y -= accel;
    this._y -= vel_y; 
    pos_y += vel_y;}}
    now you can walk off the platforms and jump play arround by copy and paste platform jump on top and walk off..

    Im taking a breack at this point..if you have a qestions post here..before we debug and polish the engine..
    mad_sci

    PS not so difficult right..

  4. #4
    Senior Member
    Join Date
    Oct 2000
    Posts
    122
    Man, I just added this and mad sci did a gravity as well. Never mind
    Hey, mad sci
    This tutorial works pretty well -- i'm quite impressed. I've improved the gravity, though by adding the following actionscript into the hero movieclip;
    if (statement = true) {
    _root.hero._y -= vel_y;
    }

    Put this after the if key is down right and left stuff.
    Then, place in the following actionscript into the second edition of the platform;
    if (_root.hero._x<135.0) {
    vel_y = 20;
    statement = true;
    }

    All it does is it makes sure that you are not allowed to walk on thin air

  5. #5
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Ok Mr. that will do tho is few more lines of code..

    ok may be you noticed that if you jump from very high the hero will go tru the platform..remember I posted that the thinkness should be 13px all the time:

    else {gravity="off";}
    vel_y -= accel;
    if ( vel_y < -12 ) {vel_y=-12;}-- so it wont fall to fast..
    this._y -= vel_y;


    and now see up there:
    if ( gravity eq "on"){this._y = this._y+10;}
    change to:
    if ( gravity eq "on"){this._y = this._y+12;} so the fall will be the same no matter jumpin or not..

    Ok try and enjoy..more comments welcome..

    mad_sci

    PS O forgot if you think that its too slow change the FPS of the movie arround 25-30

    this is what I got at the end:
    Code:
    onClipEvent (load) { 
    vel_y = 0; 
    accel = 4; 
    jumping = false;} 
    onClipEvent ( enterFrame ){
    if (Key.isDown(Key.RIGHT)){this._x=this._x+5;}
    if (Key.isDown(Key.LEFT)){this._x=this._x-5;}
    if ( gravity eq "on"){this._y = this._y+12;}
    if (Key.isDown(Key.SPACE) && !jumping) { 
    platform ="no";
    vel_y = 20; 
    jumping = true; } 
    if (jumping == true) {
    if ( platform eq "on"){
    gravity="on";
    vel_y = 0; 
    jumping = false;
    } else {gravity="off";}
    vel_y -= accel;
    if ( vel_y < -12 ) {vel_y=-12;}
    this._y -= vel_y;} }
    [Edited by Mad-Sci on 04-17-2001 at 03:26 PM]

  6. #6
    Senior Member
    Join Date
    Mar 2001
    Posts
    292
    thanks for the TUT MadSci!!! its great

  7. #7
    Member
    Join Date
    Apr 2001
    Posts
    43

    Smile

    yeah this tutorial rocks. its cool. its actually working very prescise too. "make a blue square" does it have to be blue? i cant wait for the next part. if any one wants to keep up to date with my progress i will be putting it up here at http://www.myff9.f2s.com/ballgame.swf.
    now the url should work . hopefully they should all look roughly like this 1 that way i know i've done it right
    [swf width="250" height="200" background="#000000"]http://www.myff9.f2s.com/ballgame.swf[/swf]
    [Edited by SGT on 04-18-2001 at 10:29 AM]

  8. #8
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    ha ha ha ha thats funny yea it has to be blue so you can key-out latter on...you know in the movies the effects are usualy shot on a blue screen..ha ha ha..

    Ok Ill be adding the ladder in a while...

    mad_Sci

    PS link is death btw...

  9. #9
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    FINE TUNING:
    ===========
    ok did you notice the anoying jurkiness. The moment the ball touchess the platform it is displaced on top..humm this is not good..so here is what I did..

    In the hero MC right under the OnClipEvent (EnterFrame)
    insert this line:

    b_edge=this.y+ this._y/2;-- b_edge is the bottom_edge

    now in our platfrom:

    onClipEvent (enterFrame){
    my_top=this._y-this._y/2;
    if ( hitTest (_root.hero) and _root.hero.b_edge < my_top ){

    so what we did is that we not only detect a collision with the platform be we also want the hero to be on top

    copy paste platforms---Test the Movie.
    How does that look now ? better ?

    mad_sci

  10. #10
    Senior Member
    Join Date
    Mar 2001
    Posts
    184
    my person falls throu the platform


    ps. im making a fighting game how do i make it play my walking movie clip when the character moves forward thankd

  11. #11
    Senior Member
    Join Date
    Mar 2001
    Posts
    292
    i have a problem, my hero thinks that the platform is the whole x position of were the plat from is. my platforms are placed like steps.

    ------
    -----------
    ----------------
    --------------------------------
    ___________________________________O_________

    when i try to go back down, he just stays on the same x pos. like its still a platform

    _____________ O
    ___________________
    __________________________


    what should i do?

  12. #12
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Guys when you change the code in one platform this does not change the code automaticaly in all platfroms..because we script in OnClipEvent not in frames..

    this is one of the draw backs of this form of engine..

    delete all platforms except the very bottom one the one just bellow the hero..

    add the changes to that platform and copy and paste..

    mad_sci

  13. #13
    Senior Member
    Join Date
    Mar 2001
    Posts
    292
    never mind, i used some of the ine tunning up there and it works fine, except for on eminor detail. my hero starts at the correct level, but once I jump, he looks sunken into the platform.

  14. #14
    Senior Member
    Join Date
    Mar 2001
    Posts
    184
    my character is not standing on the platform he still falls through and mad sci will you tell me how to make it play the walking movie clip when i press right

  15. #15
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    JON: do you have this in your platfroms :
    _root.hero._y=this._y-12; note 12

    Kbomber..when the key right is down use

    this.gotoAndPlay ( the frame were the walking is );

    mad_Sci

  16. #16
    Senior Member
    Join Date
    Mar 2001
    Posts
    292
    yes they do have that coding. im having the same problem with another skateboard game i started, only its WAY under in the skate boarding one, and i copy cut pasted the code (except i changed the instance "hero" to "sk8er"). do you have any other ideas

  17. #17
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Ok compare your code with mine:

    http://savco.virtualave.net/plat1.swf
    http://savco.virtualave.net/plat.zip

    the swf 1kb..he hehe

    mad_sci

    PS I aded few more hacks minor once a for example changing the ver. displacement of the hero by the platform to 10px. so it overlaps slightly..also a bug came out that if you simply fall from the very top platform and still in air you can jump..this is fixed also..

    any questions ? If we are cool we can continue with ladders and collectibles...

    mad_sci

    [Edited by Mad-Sci on 04-17-2001 at 08:17 PM]

  18. #18
    Senior Member
    Join Date
    Mar 2001
    Posts
    184
    my character falls half way through the floor and gets stuck
    please help. how do i make it play a movie clip when i press forward a movie clip please give me the exact code

  19. #19
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hey Kbomber Im confused are you talking about the above tutorial because the ball moves here ok..also check the above file online..It does not seem to fall true the platform..you are doing something wrong..I put the zip online so download and take a look inside..

    mad_sci

  20. #20
    Senior Member
    Join Date
    Mar 2001
    Posts
    184
    i used the same code on a different person im making a fighting game that is why i need him to jump and play different movie clips when he walks of him walking.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center