Gamebuilder Development Game Application series of 70 lines of code to implement a set of rings

Source: Internet
Author: User

Online preview: http://osgames.duapp.com/apprun.html?appid=osgames1-551421721381542
Online Editor: http://osgames.duapp.com/gamebuilder.php?appid=osgames1-551421721381542
Scanning:

Run:

Set of ring is a fire dance on a very popular game, it is the Flappybird variant, is also the gravity induction game, the difference is the collision detection from the Flappybird pipe, into a rope in the middle.

This rope in Gamebuilder with Uicanvas to achieve, Uicanvas in the previous blog Gamebuilder Development Game Application series of 100 lines of code implementation do not step on the white block is introduced.

The ropes here are drawn, and therefore cannot be used to detect collisions between CANTK rigid bodies onbegincontact, but instead use the onmoved interface of the ring (rigid body) to detect collisions with the rope.

The calculation of the rope
win.onlinemoved = function() {    if(win.gamestarted = = =0) {SetTimeout (win.onlinemoved, -);return;    } win.points.shift ();    ++win.count; ++win.score;if(Win.score%Ten===0) Win.find ("Score"). SetText (Win.score *0.1);varOy = win.points[win.points.length-1];if(Win.count% -===0) {win.factor = Win.genfactor (); Win.count =0; }vary = oy + win.factor; while(Y >=290|| Y <= the) {win.factor = Win.genfactor ();        y = oy + win.factor; Win.count =0;    } win.points.push (y); SetTimeout (win.onlinemoved, -);};
The drawing of the rope
function(ctx){    var pa = win.points;    20;    ‘yellow‘;    ctx.moveTo(0, pa[0]);    for(var1; i < pa.length; i++) {        ctx.lineTo(i, pa[i]);    }    ctx.stroke();};
The composition of the ring

The ring is a combination of two rigid bodies, one in the Uicanvas (yellow one) below.

Collision detection

Implements the Onmoved event interface for the ring.

win.oncirclemoved = function(point, Element) {    vary = point.y;varx =Math. Floor (point.x + ELEMENT.W);if(Y + -> Win.points[x] + $|| Y + element.h- -< Win.points[x] + $) {win.gamestarted =0; Win.find ("Ui-box"). Setenable (false); Win.find ("Ui-box-1"). Setenable (false); Win.openwindow ("Win-result", function() {Win.replay (); Win.initgame ();},false,Math. Floor (Win.score *0.1)); }};

Gamebuilder Development Game Application series of 70 lines of code to implement a set of rings

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.