The 70-line code implementation ring for GameBuilder game application series and the 70-line gamebuilder70

Source: Internet
Author: User

The 70-line code implementation ring for GameBuilder game application series and the 70-line gamebuilder70

Online Preview: http://osgames.duapp.com/apprun.html? Appid = osgames1-551421721381542
Online Editing: http://osgames.duapp.com/gamebuilder.php? Appid = osgames1-551421721381542
SCAN:

Run:

The ring is a very popular game on the fire dance. It is a variant of FlappyBird and also a gravity sensing game. The difference is that the collision detection is from the FlappyBird steel pipe, it turns into a middle rope.

This rope is implemented using UICanvas in GameBuilder. In the previous blog GameBuilder, UICanvas developed the 100-line code implementation of the game application series. Do not step on the white block.

Because the rope is drawn, the onBeginContact interface of the Cantk rigid body cannot be used to detect the collision. Instead, the onMoved interface of the ring (rigid body) is used to detect the collision with the rope.

Rope Calculation
win.onLineMoved = function() {    if(win.gameStarted === 0) {        setTimeout(win.onLineMoved, 20);        return;    }    win.points.shift();    ++win.count;    ++win.score;     if(win.score % 10 === 0)    win.find("score").setText(win.score * 0.1);    var oy = win.points[win.points.length - 1];    if(win.count % 400 === 0) {        win.factor = win.genFactor();        win.count = 0;    }    var y = oy + win.factor;    while(y >= 290 || y <= 110) {        win.factor = win.genFactor();        y = oy + win.factor;        win.count = 0;    }    win.points.push(y);    setTimeout(win.onLineMoved, 20);};
Draw a rope
win.drawCirclePath = function(ctx){    var pa = win.points;    ctx.lineWidth = 20;    ctx.strokeStyle = 'yellow';    ctx.moveTo(0, pa[0]);    for(var i = 1; i < pa.length; i++) {        ctx.lineTo(i, pa[i]);    }    ctx.stroke();};
Ring Composition

A ring is composed of two rigid bodies, one in UICanvas (the yellow one.

Collision Detection

Implement the onMoved event interface of the ring.

win.onCircleMoved = function(point, element) {    var y = point.y;    var x = Math.floor(point.x + element.w);    if(y + 55 > win.points[x] + 200 || y + element.h - 50 < win.points[x] + 200) {        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));    }};

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.