Create a terrain like the one in Tiny Wings with Flash and Box2D – Adding a car

When I introduced the scrolling in my Tiny Wings-like terrain I told you it would have been interesting to add a car to the game.

That’s what I made in this prototype:

You can control the cart with ARROW keys this way: UP: accelerate; DOWN: brake; LEFT: balance the cart on the left side; RIGHT: balance the cart on the right side.

And there’s not that much to say, apart from the cart creation which will be covered in a standalone post, I just scroll the game field and create new hills according to cart position rather than automatically like I did in the previous example.

And this is the commented source code:

No need to download anything, just copy and paste it on the class you can find in the first post.

  • Marian

    wooohooooo, I like it :)

  • You are incredible !… I thought two days ago of trying to setup a prototype like this, but it’s useless now !

  • Ben

    Suggest adding a reset button, or the ability to pick up and move the car :)

  • santosh

    thanks a lot sir…!!!
    nice to make bike and car game in flash…

  • Rob

    Very good example, thanks for all your blogposts,
    I came across them a lot in the last few years :)
    Keep up the good work!

  • Very awesome!

    Haven’t used box2d in a few months, this will give me a brush-up plus learning the new things!

    Scrolling, dynamic curve generation, and creating and moving the “car” over the hills- lots to see!

  • Always a good read here Emanuele. Just finished reading the other parts and like the way they come together. The demo was fun to play with, until I was upside down in a valley, lol.

  • excelent work

  • Pingback: Cool Stuff with the Flash Platform - 8/11/2011 | Remote Synthesis()

  • Mark

    So Fun! Well done

  • Very nice tutorial as usual Emanuele! :)

    Could you please give us any hint on how we could add some graphics for the hills? I mean, something similar to Tiny Wings…

  • Dmitry

    Isn’t it better to handle terrain as mathematical function instead of creating it in Box2D? It would be smoother and not hard to handle, I think.

  • Emanuele Feronato

    No, it’s not, since you won’t be able to make it interact with other objects

  • carmine

    Emanuele ti prego aiutami sono totalmente ignorante
    che programma devo scaricare per creare questo tipo di “gioco” ?
    grazie mille

  • carmine

    what program do i need to do all this crap ?
    i ve got
    Adobe Flash Professional CS5.5
    will it do ?
    thx

  • carmine

    Hi , I left a comment asking what program is needed to create this kind of games
    there has been no response for over to weeks now !
    I found different solutions on different websites and kind of figured other other options by myself ! but was still wondering what is going on here ?
    is this website still looked after by someone ?

  • jdsfsdjsfsk

    all you need is adobe flash and the box2D engine which you can download for free off the internet

  • Yuvaraj

    please anybody explain about Math.cos processing….

  • Rahul

    how to create a terrain path on box2dweb html5, I did search on google but doesn’t get the proper tutorial.

  • bph007

    I have been trying to implement the same concept using HTML5 Canvas and Box2dweb, but not able to implement the part of “adjusting the stage position to keep cart in the vertical middle of the stage”. please suggest me some ways.