Cut fruit game based on HTML5 and JS

Source: Internet
Author: User

Cut fruit game used to be a popular mobile phone casual game, today to introduce is a web version of the cut Fruit game, by Javasript and HTML5 realize, although the difference between the function and the original is too big, but the basic function or have, or imitation of quite lifelike, Have a certain level of javasript friends, you can look at the source code, I believe your javasript level will be a great upgrade.

/**
* This file is compiled by Jsbuild 0.9.6
* @date Fri, 16:21:18 UTC
* @author Dron
* @site Web Links
*/
void function (Global) {
var mapping = {}, cache = {};
Global.startmodule = function (m) {
Require (m). Start ();
};
Global.define = function (ID, func) {
Mapping[id] = func;
};
Global.require = function (ID) {
if (!/\.js$/.test (ID))
id + = '. js ';
if (Cache[id])
return Cache[id];
Else
return Cache[id] = Mapping[id] ({});
};
} (this);
/**
* @source D:\hosting\demos\fruit-ninja\output\scripts\collide.js
*/
Define ("Scripts/collide.js", function (exports) {
var fruit = require ("Scripts/factory/fruit");
var Ucren = require ("Scripts/lib/ucren");
var fruits = Fruit.getfruitinview ();
/**
* Collision Detection
*/
Exports.check = function (knife) {
var ret = [], index = 0;
Fruits.foreach (function (fruit) {
var ck = Lineinellipse (
Knife.slice (0, 2),
Knife.slice (2, 4),
[Fruit.originx, Fruit.originy],
Fruit.radius
);
if (CK)
ret[Index + +] = fruit;
});
return ret;
};
function Sqr (x) {
return x * x;
}
function sign (n) {
Return N < 0? -1: (n > 0? 1:0);
}
function Equation12 (A, B, c) {
if (a = = 0) return;
var delta = b * b-4 * a * C;
if (delta = = 0)
return [-1 * b/(2 * a),-1 * b/(2 * a)];
else if (Delta > 0)
return [( -1 * b + math.sqrt (delta))/(2 * a), ( -1 * B-MATH.SQRT (Delta))/(2 * a)];
}
Returns the two intersections of a segment and ellipse, or null if disjoint
function Linexellipse (P1, P2, C, R, E) {
Segment: P1, p2 Center: C Radius: R centrifugal rate: E
if (r <= 0) return;
E = e = = = undefined? 1:e;
var T1 = r, t2 = R * E, K;
A = SQR (T2) * SQR (P1[0]-p2[0]) + SQR (t1) * SQR (P1[1]-p2[1]);
if (a <= 0) return;
b = 2 * SQR (T2) * (P2[0]-p1[0]) * (P1[0]-c[0]) + 2 * SQR (T1) * (P2[1]-p1[1]) * (P1[1]-c[1]);
c = SQR (T2) * SQR (P1[0]-c[0]) + SQR (t1) * SQR (P1[1]-c[1])-SQR (T1) * SQR (T2);
if (! (k = Equation12 (A, B, C, T1, T2)) return;
var result = [
[p1[0] + k[0] * (P2[0]-p1[0]), p1[1] + k[0] * (p2[1]-p1[1]),
[p1[0] + k[1] * (P2[0]-p1[0]), p1[1] + k[1] * (p2[1]-p1[1])
];
if (! ( (Sign (Result[0][0] – p1[0]) * SIGN (result[0][0]-p2[0]) <= 0) &&
(Sign (result[0][1] – p1[1]) * SIGN (result[0][1]-p2[1]) <= 0)) )
RESULT[0] = null;
if (! ( (Sign (Result[1][0] – p1[0]) * SIGN (result[1][0]-p2[0]) <= 0) &&
(Sign (result[1][1] – p1[1]) * SIGN (result[1][1]-p2[1]) <= 0)) )
RESULT[1] = null;
return result;
}
Determine if the segment and ellipse intersect
function Lineinellipse (P1, P2, C, R, E) {
var t = linexellipse (P1, P2, C, R, E);
return T && (T[0] | | t[1]);
};
return exports;
});

Cut fruit game based on HTML5 and JS

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.