Gamebuilder Development Game Application series of 60 lines of code implementation Flappybird

Source: Internet
Author: User

Online Demo: http://osgames.duapp.com/apprun.html?appid=osgames1-911422256817006
Online Editor: http://osgames.duapp.com/gamebuilder.php?appid=osgames1-911422256817006
Scanning:
Run:

Flappybird is a 2014 explosion of a game, belongs to the classic gravity induction game, play very simple at the same time and very abusive heart, it is this feature let Flappybird in the social network virus-like spread.

Gamebuilder integrates the box2d physics engine and develops this type of gravity-sensing game that belongs to his housekeeping skills.

A total of only 60 lines of flppybird are required for the Gamebuilder implementation, which basically realizes the random distribution of the pipe in the vertical direction (the horizontal position is fixed), and of course you can set the pipe yourself, so that if 10 lines of code will be done.

The game consists of two main aspects:

Horizontal Cloth Tube

The virtual width of the screen is set to 100000 pixels, placing only the top and bottom four pipes, such as:

The bird crosses the tube (to the left of the screen) back into the front of the bird (right side of the screen).

    • Location Generation function
function() {    var x, y;    for(var04; i++) {        var position = {x:0, y:0};        480 + i*320;        y = win.randomY();        position.x = x;        position.y = y;        win.pList.push(position);    }};
    • Update Location List
Win.updateplist = function() {    varWin = This. GetWindow ();varBird = Win.find ("Bird");//Bird over tube, play sound, add points    if(Bird.x > Win.nextscorex) {Win.nextscorex + = the; Win.find ("Effects"). Play ("Disappear.mp3"); Win.score + =1; Win.find ("Score"). SetText (Win.score); }//The leftmost tube moves out of the screen, move it to the right    if(win.plist[0].x- This. Xoffset <- the) {varp = Win.pList.shift (); p.x = win.plist[2].x + the;        P.Y = Win.randomy ();    Win.pList.push (P); }};
    • Periodically update the pipe position based on the location list
function() {    win.updatePList();    for(var04; i++) {        win.find("boxup" + i).setPosition(win.pList[i].x, win.pList[i].y);        win.find("boxdown"850);    }    50);};
Collision detection

In the game, the bird as a rigid body, in the game has been required to remain vacant, once the collision is considered to end the game, so long as the implementation of the bird Onbegincontact event interface can be.

Event code:

varthis.getWindow();if(!win.gameOver) {    true;     win.find("bird").setV(015);    win.openWindow("win-result"function(ret) {false, win.score);}

Gamebuilder Development Game Application series of 60 lines of code implementation Flappybird

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.