├── README.md ├── images ├── x.png ├── logo.png ├── xf.png ├── xx.png ├── xxf.png ├── xxx.png ├── xxxf.png ├── flash.png ├── ninja.png ├── shadow.png ├── fruit │ ├── b1.png │ ├── b2.png │ ├── b3.png │ ├── b4.png │ ├── f1.png │ ├── f2.png │ ├── f3.png │ ├── f4.png │ ├── f5.png │ ├── f6.png │ ├── s1.png │ ├── s2.png │ ├── w1.png │ ├── w2.png │ ├── w3.png │ ├── zy.png │ ├── b1-1.png │ ├── b1-2.png │ ├── b2-1.png │ ├── b2-2.png │ ├── b3-1.png │ ├── b3-2.png │ ├── b4-1.png │ ├── b4-2.png │ ├── f1-1.png │ ├── f1-2.png │ ├── f2-1.png │ ├── f2-2.png │ ├── f3-1.png │ ├── f3-2.png │ ├── f4-1.png │ ├── f4-2.png │ ├── f5-1.png │ ├── f5-2.png │ ├── f6-1.png │ ├── f6-2.png │ ├── gesar.png │ ├── w1-1.png │ ├── w1-2.png │ ├── w2-1.png │ ├── w2-2.png │ ├── w3-1.png │ ├── w3-2.png │ ├── basiclaw.png │ └── ferrari.png ├── game-over.png ├── home-mask.png ├── mistake.png ├── new-game.png └── background.jpg ├── sounds ├── bun1.mp3 ├── bun2.mp3 ├── bun3.mp3 ├── bun4.mp3 ├── bun5.mp3 ├── fault1.mp3 ├── fault2.mp3 ├── fault3.mp3 ├── fault4.mp3 ├── fault5.mp3 ├── fault6.mp3 ├── fault7.mp3 ├── fault8.mp3 ├── fault9.mp3 ├── frog1.mp3 ├── frog2.mp3 ├── frog3.mp3 ├── frog4.mp3 ├── gesar1.mp3 ├── basiclaw1.mp3 ├── basiclaw2.mp3 ├── fault10.mp3 ├── ferrari1.mp3 ├── ferrari2.mp3 ├── ferrari3.mp3 ├── ferrari4.mp3 ├── ferrari5.mp3 ├── ferrari6.mp3 ├── gameover1.mp3 ├── gameover2.mp3 ├── gameover3.mp3 ├── winnie1.mp3 ├── shakespeare1.mp3 └── shakespeare2.mp3 ├── scripts ├── require.js ├── sound.js ├── object │ ├── game-over.js │ ├── score.js │ ├── background.js │ ├── logo.js │ ├── new-game.js │ └── mistake.js ├── sound-manager.js ├── flash.js ├── rotation.js ├── layout.js ├── animation.js ├── main.js ├── tools.js ├── juice.js ├── collision.js ├── lib │ ├── tween.js │ └── raphael.js ├── knife.js ├── layer.js ├── light.js ├── drag.js ├── scene.js ├── fruit-manager.js ├── game.js ├── timeline.js └── fruit.js └── index.html /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/x.png -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/logo.png -------------------------------------------------------------------------------- /images/xf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/xf.png -------------------------------------------------------------------------------- /images/xx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/xx.png -------------------------------------------------------------------------------- /images/xxf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/xxf.png -------------------------------------------------------------------------------- /images/xxx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/xxx.png -------------------------------------------------------------------------------- /images/xxxf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/xxxf.png -------------------------------------------------------------------------------- /sounds/bun1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/bun1.mp3 -------------------------------------------------------------------------------- /sounds/bun2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/bun2.mp3 -------------------------------------------------------------------------------- /sounds/bun3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/bun3.mp3 -------------------------------------------------------------------------------- /sounds/bun4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/bun4.mp3 -------------------------------------------------------------------------------- /sounds/bun5.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/bun5.mp3 -------------------------------------------------------------------------------- /images/flash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/flash.png -------------------------------------------------------------------------------- /images/ninja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/ninja.png -------------------------------------------------------------------------------- /images/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/shadow.png -------------------------------------------------------------------------------- /sounds/fault1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault1.mp3 -------------------------------------------------------------------------------- /sounds/fault2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault2.mp3 -------------------------------------------------------------------------------- /sounds/fault3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault3.mp3 -------------------------------------------------------------------------------- /sounds/fault4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault4.mp3 -------------------------------------------------------------------------------- /sounds/fault5.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault5.mp3 -------------------------------------------------------------------------------- /sounds/fault6.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault6.mp3 -------------------------------------------------------------------------------- /sounds/fault7.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault7.mp3 -------------------------------------------------------------------------------- /sounds/fault8.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault8.mp3 -------------------------------------------------------------------------------- /sounds/fault9.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault9.mp3 -------------------------------------------------------------------------------- /sounds/frog1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/frog1.mp3 -------------------------------------------------------------------------------- /sounds/frog2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/frog2.mp3 -------------------------------------------------------------------------------- /sounds/frog3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/frog3.mp3 -------------------------------------------------------------------------------- /sounds/frog4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/frog4.mp3 -------------------------------------------------------------------------------- /sounds/gesar1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/gesar1.mp3 -------------------------------------------------------------------------------- /images/fruit/b1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b1.png -------------------------------------------------------------------------------- /images/fruit/b2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b2.png -------------------------------------------------------------------------------- /images/fruit/b3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b3.png -------------------------------------------------------------------------------- /images/fruit/b4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b4.png -------------------------------------------------------------------------------- /images/fruit/f1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f1.png -------------------------------------------------------------------------------- /images/fruit/f2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f2.png -------------------------------------------------------------------------------- /images/fruit/f3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f3.png -------------------------------------------------------------------------------- /images/fruit/f4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f4.png -------------------------------------------------------------------------------- /images/fruit/f5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f5.png -------------------------------------------------------------------------------- /images/fruit/f6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f6.png -------------------------------------------------------------------------------- /images/fruit/s1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/s1.png -------------------------------------------------------------------------------- /images/fruit/s2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/s2.png -------------------------------------------------------------------------------- /images/fruit/w1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w1.png -------------------------------------------------------------------------------- /images/fruit/w2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w2.png -------------------------------------------------------------------------------- /images/fruit/w3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w3.png -------------------------------------------------------------------------------- /images/fruit/zy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/zy.png -------------------------------------------------------------------------------- /images/game-over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/game-over.png -------------------------------------------------------------------------------- /images/home-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/home-mask.png -------------------------------------------------------------------------------- /images/mistake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/mistake.png -------------------------------------------------------------------------------- /images/new-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/new-game.png -------------------------------------------------------------------------------- /sounds/basiclaw1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/basiclaw1.mp3 -------------------------------------------------------------------------------- /sounds/basiclaw2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/basiclaw2.mp3 -------------------------------------------------------------------------------- /sounds/fault10.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/fault10.mp3 -------------------------------------------------------------------------------- /sounds/ferrari1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari1.mp3 -------------------------------------------------------------------------------- /sounds/ferrari2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari2.mp3 -------------------------------------------------------------------------------- /sounds/ferrari3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari3.mp3 -------------------------------------------------------------------------------- /sounds/ferrari4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari4.mp3 -------------------------------------------------------------------------------- /sounds/ferrari5.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari5.mp3 -------------------------------------------------------------------------------- /sounds/ferrari6.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/ferrari6.mp3 -------------------------------------------------------------------------------- /sounds/gameover1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/gameover1.mp3 -------------------------------------------------------------------------------- /sounds/gameover2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/gameover2.mp3 -------------------------------------------------------------------------------- /sounds/gameover3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/gameover3.mp3 -------------------------------------------------------------------------------- /sounds/winnie1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/winnie1.mp3 -------------------------------------------------------------------------------- /images/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/background.jpg -------------------------------------------------------------------------------- /images/fruit/b1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b1-1.png -------------------------------------------------------------------------------- /images/fruit/b1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b1-2.png -------------------------------------------------------------------------------- /images/fruit/b2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b2-1.png -------------------------------------------------------------------------------- /images/fruit/b2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b2-2.png -------------------------------------------------------------------------------- /images/fruit/b3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b3-1.png -------------------------------------------------------------------------------- /images/fruit/b3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b3-2.png -------------------------------------------------------------------------------- /images/fruit/b4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b4-1.png -------------------------------------------------------------------------------- /images/fruit/b4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/b4-2.png -------------------------------------------------------------------------------- /images/fruit/f1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f1-1.png -------------------------------------------------------------------------------- /images/fruit/f1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f1-2.png -------------------------------------------------------------------------------- /images/fruit/f2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f2-1.png -------------------------------------------------------------------------------- /images/fruit/f2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f2-2.png -------------------------------------------------------------------------------- /images/fruit/f3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f3-1.png -------------------------------------------------------------------------------- /images/fruit/f3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f3-2.png -------------------------------------------------------------------------------- /images/fruit/f4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f4-1.png -------------------------------------------------------------------------------- /images/fruit/f4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f4-2.png -------------------------------------------------------------------------------- /images/fruit/f5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f5-1.png -------------------------------------------------------------------------------- /images/fruit/f5-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f5-2.png -------------------------------------------------------------------------------- /images/fruit/f6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f6-1.png -------------------------------------------------------------------------------- /images/fruit/f6-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/f6-2.png -------------------------------------------------------------------------------- /images/fruit/gesar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/gesar.png -------------------------------------------------------------------------------- /images/fruit/w1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w1-1.png -------------------------------------------------------------------------------- /images/fruit/w1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w1-2.png -------------------------------------------------------------------------------- /images/fruit/w2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w2-1.png -------------------------------------------------------------------------------- /images/fruit/w2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w2-2.png -------------------------------------------------------------------------------- /images/fruit/w3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w3-1.png -------------------------------------------------------------------------------- /images/fruit/w3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/w3-2.png -------------------------------------------------------------------------------- /images/fruit/basiclaw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/basiclaw.png -------------------------------------------------------------------------------- /images/fruit/ferrari.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/images/fruit/ferrari.png -------------------------------------------------------------------------------- /sounds/shakespeare1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/shakespeare1.mp3 -------------------------------------------------------------------------------- /sounds/shakespeare2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hahaxixi/bao/HEAD/sounds/shakespeare2.mp3 -------------------------------------------------------------------------------- /scripts/require.js: -------------------------------------------------------------------------------- 1 | void function(global) { 2 | "use strict"; 3 | 4 | var modules = {}; 5 | 6 | var require = function(id) { 7 | if (!/\.js$/.test(id)) 8 | id += ".js"; 9 | var module = modules[id]; 10 | if (!module.exports) { 11 | module.exports = {}; 12 | module.call(this, module.exports, require, module); 13 | } 14 | return module.exports; 15 | }; 16 | 17 | global.define = function(id, func) { 18 | modules[id] = func; 19 | }; 20 | global.require = require; 21 | }(this); 22 | -------------------------------------------------------------------------------- /scripts/sound.js: -------------------------------------------------------------------------------- 1 | define("scripts/sound.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | function ClassSound(src) { 5 | this.sound = document.createElement("audio"); 6 | var source = document.createElement("source"); 7 | source.src = src; 8 | this.sound.appendChild(source); 9 | this.sound.preload = "auto"; 10 | this.sound.volume = 1; 11 | } 12 | 13 | ClassSound.prototype.play = function() { 14 | return this.sound.play(); 15 | }; 16 | 17 | exports.create = function(src, opts) { 18 | return new ClassSound(src, opts); 19 | }; 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /scripts/object/game-over.js: -------------------------------------------------------------------------------- 1 | define("scripts/object/game-over.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var layout = require("scripts/layout"); 6 | var scale = require("scripts/animation").scale; 7 | 8 | var image; 9 | 10 | exports.set = function() { 11 | image = layer.createImage("default", "images/game-over.png", 12 | layout.centerX(490), layout.centerY(85), 490, 85).hide().scale(1e-5, 1e-5); 13 | }; 14 | 15 | exports.show = function() { 16 | image.show(); 17 | scale(image, 1e-5, 1, 500); 18 | }; 19 | 20 | exports.hide = function() { 21 | scale(image, 1, 1e-5, 500, image.hide); 22 | }; 23 | 24 | exports.resize = function() { 25 | image.attr({ 26 | "x": layout.centerX(image.attrs.width), 27 | "y": layout.centerY(image.attrs.height) 28 | }); 29 | }; 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /scripts/object/score.js: -------------------------------------------------------------------------------- 1 | define("scripts/object/score.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var translateX = require("scripts/animation").translateX; 6 | 7 | var score; 8 | 9 | exports.set = function() { 10 | score = layer.createText("default", "", -59, 24, "90-#fc7f0c-#ffec53", "30px").hide(); 11 | }; 12 | 13 | exports.show = function() { 14 | score.attr("text", "+0s"); 15 | score.show(); 16 | translateX(score, -59, 7, 500); 17 | }; 18 | 19 | exports.hide = function() { 20 | translateX(score, 7, -59, 500, score.hide); 21 | }; 22 | 23 | exports.resize = function() { 24 | 25 | }; 26 | 27 | exports.number = function(number) { 28 | score.attr("text", "+" + number + "s"); 29 | score.attr("font-size", "36px"); 30 | setTimeout(function() { 31 | score.attr("font-size", "30px"); 32 | }, 30); 33 | }; 34 | 35 | }); 36 | -------------------------------------------------------------------------------- /scripts/sound-manager.js: -------------------------------------------------------------------------------- 1 | define("scripts/sound-manager.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var sound = require("scripts/sound"); 5 | var random = require("scripts/tools").randomNumber; 6 | 7 | var soundArrays = { 8 | "basiclaw": 2, 9 | "shakespeare": 2, 10 | "gesar": 1, 11 | "winnie": 1, 12 | "ferrari": 6, 13 | "fault": 10, 14 | "frog": 4, 15 | "bun": 5, 16 | "gameover": 3 17 | }; 18 | 19 | function loadArrays() { 20 | var arr, count, src; 21 | for (var name in soundArrays) { 22 | arr = []; 23 | count = soundArrays[name]; 24 | for (var i = 0; i < count; i++) { 25 | arr.push(sound.create("sounds/" + name + (i + 1) + ".mp3")); 26 | } 27 | soundArrays[name] = arr; 28 | } 29 | } 30 | 31 | exports.init = function() { 32 | loadArrays(); 33 | }; 34 | 35 | exports.play = function(name) { 36 | var arr = soundArrays[name]; 37 | var len = arr.length; 38 | return arr[len == 1 ? 0 : random(len)].play(); 39 | }; 40 | 41 | }); 42 | -------------------------------------------------------------------------------- /scripts/object/background.js: -------------------------------------------------------------------------------- 1 | define("scripts/object/background.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var layout = require("scripts/layout"); 6 | var random = require("scripts/tools").randomNumber; 7 | 8 | var image, timer; 9 | 10 | exports.set = function() { 11 | image = layer.createImage("default", "images/background.jpg", 0, 0, layout.width(), layout.height()); 12 | }; 13 | 14 | exports.resize = function() { 15 | image.attr({ 16 | width: layout.width(), 17 | height: layout.height() 18 | }); 19 | }; 20 | 21 | exports.wobble = function() { 22 | if (timer) 23 | return; 24 | timer = setInterval(wobble, 50); 25 | }; 26 | 27 | exports.stop = function() { 28 | clearInterval(timer); 29 | timer = null; 30 | image.attr({ 31 | x: 0, 32 | y: 0 33 | }); 34 | }; 35 | 36 | function wobble() { 37 | var x, y; 38 | x = random(12) - 6; 39 | y = random(12) - 6; 40 | image.attr({ 41 | x: x, 42 | y: y 43 | }); 44 | }; 45 | 46 | }); 47 | -------------------------------------------------------------------------------- /scripts/flash.js: -------------------------------------------------------------------------------- 1 | define("scripts/flash.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var timeline = require("scripts/timeline").use("flash").init(10); 6 | var tween = require("scripts/lib/tween"); 7 | 8 | var image; 9 | 10 | var anim = tween.quadratic.cio; 11 | var anims = []; 12 | var dur = 100; 13 | 14 | function createImage() { 15 | image = layer.createImage("flash", "images/flash.png", 0, 0, 358, 20).hide(); 16 | } 17 | 18 | function onTimeUpdate(time, a, b, z) { 19 | image.scale(z = anim(time, a, b - a, dur), z); 20 | } 21 | 22 | exports.showAt = function(x, y, an) { 23 | if (!image) 24 | createImage(); 25 | 26 | image.rotate(an, true).scale(1e-5, 1e-5).attr({ 27 | x: x, 28 | y: y 29 | }).show(); 30 | 31 | anims.clear && anims.clear(); 32 | 33 | timeline.createTask({ 34 | start: 0, 35 | duration: dur, 36 | data: [1e-5, 1], 37 | object: this, 38 | onTimeUpdate: onTimeUpdate, 39 | recycle: anims 40 | }); 41 | 42 | timeline.createTask({ 43 | start: dur, 44 | duration: dur, 45 | data: [1, 1e-5], 46 | object: this, 47 | onTimeUpdate: onTimeUpdate, 48 | recycle: anims 49 | }); 50 | }; 51 | 52 | }); 53 | -------------------------------------------------------------------------------- /scripts/rotation.js: -------------------------------------------------------------------------------- 1 | define("scripts/rotation.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var timeline = require("scripts/timeline"); 5 | var randomNumber = require("scripts/tools").randomNumber; 6 | var tween = require("scripts/lib/tween"); 7 | 8 | var anim = tween.exponential.co; 9 | /** 10 | * 旋转类模块模型 11 | */ 12 | 13 | exports.create = function(object) { 14 | var module = {}; 15 | var rotateDire = [12, -12][randomNumber(2)]; 16 | var defaultAngle = randomNumber(360); 17 | 18 | module.anims = []; 19 | 20 | module.show = function() { 21 | object.rotate(defaultAngle, true); 22 | object.show(); 23 | 24 | timeline.createTask({ 25 | start: 0, 26 | duration: -1, 27 | object: this, 28 | onTimeUpdate: module.onRotating, 29 | recycle: this.anims 30 | }); 31 | }; 32 | 33 | module.hide = function() { 34 | this.anims.clear(); 35 | object.hide(); 36 | }; 37 | 38 | module.onRotating = function() { 39 | var lastTime = 0, 40 | an = defaultAngle; 41 | return function(time) { 42 | an = (an + (time - lastTime) / 1e3 * rotateDire) % 360; 43 | object.rotate(an, true); 44 | lastTime = time; 45 | } 46 | }(); 47 | 48 | return module; 49 | }; 50 | 51 | }); 52 | -------------------------------------------------------------------------------- /scripts/layout.js: -------------------------------------------------------------------------------- 1 | define("scripts/layout.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var elem = document.getElementById("container"); 5 | 6 | var minWidth = 240; 7 | var minHeight = 240; 8 | 9 | exports.x = function() { 10 | return elem.offsetLeft; 11 | }; 12 | 13 | exports.y = function() { 14 | return elem.offsetTop; 15 | }; 16 | 17 | exports.width = function() { 18 | var w = elem.offsetWidth; 19 | if (w < minWidth) 20 | w = minWidth; 21 | return w; 22 | }; 23 | 24 | exports.height = function() { 25 | var h = elem.offsetHeight; 26 | if (h < minHeight) 27 | h = minHeight; 28 | return h; 29 | }; 30 | 31 | exports.left = function(n) { 32 | n = n || 0; 33 | return n; 34 | }; 35 | 36 | exports.top = function(n) { 37 | n = n || 0; 38 | return n; 39 | }; 40 | 41 | exports.right = function(n, w) { 42 | n = n || 0; 43 | w = w || 0; 44 | return exports.width() - n - w; 45 | }; 46 | 47 | exports.bottom = function(n, h) { 48 | n = n || 0; 49 | h = h || 0; 50 | return exports.height() - n - h; 51 | }; 52 | 53 | exports.centerX = function(w) { 54 | w = w || 0; 55 | return (exports.width() >> 1) - (w >> 1); 56 | }; 57 | 58 | exports.centerY = function(h) { 59 | h = h || 0; 60 | return (exports.height() >> 1) - (h >> 1); 61 | }; 62 | 63 | }); 64 | -------------------------------------------------------------------------------- /scripts/animation.js: -------------------------------------------------------------------------------- 1 | define("scripts/animation.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var timeline = require("scripts/timeline"); 6 | var tween = require("scripts/lib/tween"); 7 | 8 | var anim = tween.exponential.co; 9 | 10 | exports.translateX = function(object, from, to, duration, callback) { 11 | return timeline.createTask({ 12 | start: 0, 13 | duration: duration, 14 | object: object, 15 | 16 | onTimeUpdate: function(time) { 17 | object.attr({ 18 | x: anim(time, from, to - from, duration) 19 | }); 20 | }, 21 | 22 | onTimeEnd: callback 23 | }); 24 | }; 25 | 26 | exports.translateY = function(object, from, to, duration, callback) { 27 | return timeline.createTask({ 28 | start: 0, 29 | duration: duration, 30 | object: object, 31 | 32 | onTimeUpdate: function(time) { 33 | object.attr({ 34 | y: anim(time, from, to - from, duration) 35 | }); 36 | }, 37 | 38 | onTimeEnd: callback 39 | }); 40 | }; 41 | 42 | exports.scale = function(object, from, to, duration, callback) { 43 | return timeline.createTask({ 44 | start: 0, 45 | duration: duration, 46 | object: object, 47 | 48 | onTimeUpdate: function(time, zoom) { 49 | object.scale(zoom = anim(time, from, to - from, duration), zoom); 50 | }, 51 | 52 | onTimeEnd: callback 53 | }); 54 | }; 55 | 56 | }); 57 | -------------------------------------------------------------------------------- /scripts/object/logo.js: -------------------------------------------------------------------------------- 1 | define("scripts/object/logo.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var layout = require("scripts/layout"); 6 | var translateY = require("scripts/animation").translateY; 7 | 8 | var homeMask, logo, ninja; 9 | var width = [0, 150, 240]; 10 | var height = [183, 126, 90]; 11 | 12 | var x = [0, 0, 0]; 13 | var y = [-183, -182, -140]; 14 | var y2 = [0, 10, 20]; 15 | 16 | function getPos() { 17 | width[0] = layout.width(); 18 | x[1] = layout.centerX(width[1]) - 125; 19 | x[2] = x[1] + 160; 20 | } 21 | 22 | function createImage(imageSrc, x, y, width, height) { 23 | return layer.createImage("default", imageSrc, x, y, width, height).hide(); 24 | } 25 | 26 | exports.set = function() { 27 | getPos(); 28 | homeMask = createImage("images/home-mask.png", x[0], y[0], width[0], height[0]); 29 | logo = createImage("images/logo.png", x[1], y[1], width[1], height[1]); 30 | ninja = createImage("images/ninja.png", x[2], y[2], width[2], height[2]); 31 | }; 32 | 33 | exports.show = function() { 34 | homeMask.show(); 35 | logo.show(); 36 | ninja.show(); 37 | translateY(homeMask, y[0], y2[0], 1000); 38 | translateY(logo, y[1], y2[1], 1000); 39 | translateY(ninja, y[2], y2[2], 1000); 40 | }; 41 | 42 | exports.hide = function() { 43 | translateY(homeMask, y2[0], y[0], 1000, homeMask.hide); 44 | translateY(logo, y2[1], y[1], 1000, logo.hide); 45 | translateY(ninja, y2[2], y[2], 1000, ninja.hide); 46 | }; 47 | 48 | exports.resize = function() { 49 | getPos(); 50 | homeMask.attr({width: width[0]}); 51 | logo.attr({x: x[1]}); 52 | ninja.attr({x: x[2]}); 53 | }; 54 | }); 55 | -------------------------------------------------------------------------------- /scripts/main.js: -------------------------------------------------------------------------------- 1 | define("scripts/main.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var scene = require("scripts/scene"); 5 | var layer = require("scripts/layer"); 6 | var soundManager = require("scripts/sound-manager"); 7 | var fruitManager = require("scripts/fruit-manager"); 8 | 9 | var imageList = [ 10 | "images/flash.png", 11 | "images/game-over.png", 12 | "images/home-mask.png", 13 | "images/logo.png", 14 | "images/mistake.png", 15 | "images/new-game.png", 16 | "images/ninja.png", 17 | "images/shadow.png", 18 | "images/x.png", 19 | "images/xf.png", 20 | "images/xx.png", 21 | "images/xxf.png", 22 | "images/xxx.png", 23 | "images/xxxf.png" 24 | ]; 25 | 26 | function preloadImages(callback) { 27 | for (var i = 0; i < imageList.length; i++) { 28 | layer.preloadImage(imageList[i], callback); 29 | } 30 | return imageList.length; 31 | } 32 | 33 | function preload(text, callback) { 34 | var info = "正在加载 %d/%d"; 35 | info += "\n请打开声音..."; 36 | 37 | var num = 0, count = 0; 38 | var onload = function() { 39 | num++; 40 | text.attr("text", info.replace("%d", num).replace("%d", count)); 41 | if (num >= count) { 42 | callback(); 43 | } 44 | }; 45 | 46 | count += fruitManager.preloadImages(onload); 47 | count += preloadImages(onload); 48 | } 49 | 50 | exports.start = function() { 51 | soundManager.init(); 52 | 53 | var text = layer.createText("default", "", 16, 20); 54 | preload(text, function() { 55 | setTimeout(function() { 56 | text.remove(); 57 | scene.init(); 58 | scene.switchScene("home-menu"); 59 | }, 1000); 60 | }); 61 | }; 62 | 63 | }); 64 | -------------------------------------------------------------------------------- /scripts/object/new-game.js: -------------------------------------------------------------------------------- 1 | define("scripts/object/new-game.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var layer = require("scripts/layer"); 5 | var rotation = require("scripts/rotation"); 6 | var layout = require("scripts/layout"); 7 | var fruitManager = require("scripts/fruit-manager"); 8 | 9 | var image, component 10 | var sideLength = 195; 11 | var imageX, imageY; 12 | 13 | var icon, iconWidth, iconHeight, iconX, iconY; 14 | 15 | function getImageXY() { 16 | imageX = layout.centerX(sideLength); 17 | imageY = layout.bottom(50, sideLength); 18 | } 19 | 20 | function getIconXY() { 21 | iconX = layout.centerX(); 22 | iconY = layout.bottom(50, iconHeight); 23 | } 24 | 25 | exports.setIcon = function(groupName, w, h, callback) { 26 | if (icon) 27 | return; 28 | iconWidth = w; 29 | iconHeight = h; 30 | getIconXY(); 31 | icon = fruitManager.create(groupName, iconX, iconY, true); 32 | icon.onSlice = function(fruit, angle) { 33 | icon.break(angle); 34 | icon = null; 35 | callback(); 36 | } 37 | }; 38 | 39 | exports.set = function() { 40 | getImageXY(); 41 | image = layer.createImage("default", "images/new-game.png", imageX, imageY, sideLength, sideLength).hide(); 42 | component = rotation.create(image); 43 | }; 44 | 45 | exports.show = function() { 46 | component.show(); 47 | if (icon) { 48 | icon.show(); 49 | } 50 | }; 51 | 52 | exports.hide = function() { 53 | component.hide(); 54 | }; 55 | 56 | exports.resize = function() { 57 | getImageXY(); 58 | image.attr({ 59 | x: imageX, 60 | y: imageY 61 | }); 62 | 63 | if (icon) { 64 | getIconXY(); 65 | icon.setPos(iconX, iconY); 66 | } 67 | }; 68 | 69 | }); 70 | -------------------------------------------------------------------------------- /scripts/tools.js: -------------------------------------------------------------------------------- 1 | define("scripts/tools.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | exports.unsetObject = function(object) { 5 | for (var i in object) 6 | if (object.hasOwnProperty(i) && typeof object[i] == "function") 7 | object[i] = function() {}; 8 | }; 9 | 10 | exports.getAngleByRadian = function(radian) { 11 | return radian * 180 / Math.PI; 12 | }; 13 | 14 | exports.pointToRadian = function(origin, point) { 15 | var PI = Math.PI; 16 | 17 | if (point[0] === origin[0]) { 18 | if (point[1] > origin[1]) 19 | return PI * 0.5; 20 | return PI * 1.5 21 | } else if (point[1] === origin[1]) { 22 | if (point[0] > origin[0]) 23 | return 0; 24 | return PI; 25 | } 26 | 27 | var t = Math.atan((origin[1] - point[1]) / (origin[0] - point[0])); 28 | 29 | if (point[0] > origin[0] && point[1] < origin[1]) 30 | return t + 2 * PI; 31 | 32 | if (point[0] > origin[0] && point[1] > origin[1]) 33 | return t; 34 | 35 | return t + PI; 36 | }; 37 | 38 | exports.randomNumber = function(num) { 39 | return Math.floor(Math.random() * num); 40 | }; 41 | 42 | exports.randomArray = function(arr) { 43 | arr = arr.slice(0); 44 | var ret = [], i = arr.length; 45 | while( i -- ) 46 | ret.push( arr.splice( exports.randomNumber( i + 1 ), 1 )[0] ); 47 | return ret; 48 | }; 49 | 50 | exports.addEvent = function(target, name, fn) { 51 | var call = function() { 52 | fn.apply(target, arguments); 53 | }; 54 | if (window.attachEvent) { 55 | target.attachEvent("on" + name, call); 56 | } else if (window.addEventListener) { 57 | target.addEventListener(name, call, false); 58 | } else { 59 | target["on" + name] = call; 60 | } 61 | return call; 62 | }; 63 | 64 | exports.delEvent = function(target, name, fn) { 65 | if (window.detachEvent) { 66 | target.detachEvent("on" + name, fn); 67 | } else if (window.removeEventListener) { 68 | target.removeEventListener(name, fn, false); 69 | } else if (target["on" + name] == fn) { 70 | target["on" + name] = null; 71 | } 72 | }; 73 | 74 | }); 75 | -------------------------------------------------------------------------------- /scripts/juice.js: -------------------------------------------------------------------------------- 1 | define("scripts/juice.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | /** 5 | * 果汁 6 | */ 7 | var tools = require("scripts/tools"); 8 | var layer = require("scripts/layer").getLayer("juice"); 9 | var timeline = require("scripts/timeline").use("juice").init(10); 10 | var tween = require("scripts/lib/tween"); 11 | 12 | var random = tools.randomNumber; 13 | var dur = 1500; 14 | var anim = tween.exponential.co; 15 | var dropAnim = tween.quadratic.co; 16 | var sin = Math.sin; 17 | var cos = Math.cos; 18 | 19 | var num = 10; 20 | var radius = 10; 21 | 22 | function ClassJuice(x, y, color) { 23 | this.x = x; 24 | this.y = y; 25 | this.color = color; 26 | 27 | this.distance = random(200) + 100; 28 | this.radius = radius; 29 | this.dir = random(360) * Math.PI / 180; 30 | } 31 | 32 | ClassJuice.prototype.render = function() { 33 | this.circle = layer.circle(this.x, this.y, this.radius).attr({ 34 | fill: this.color, 35 | stroke: "none" 36 | }); 37 | }; 38 | 39 | ClassJuice.prototype.sputter = function() { 40 | timeline.createTask({ 41 | start: 0, 42 | duration: dur, 43 | object: this, 44 | onTimeUpdate: this.onTimeUpdate, 45 | onTimeEnd: this.onTimeEnd 46 | }); 47 | }; 48 | 49 | ClassJuice.prototype.onTimeUpdate = function(time) { 50 | var distance, x, y, z; 51 | 52 | distance = anim(time, 0, this.distance, dur); 53 | x = this.x + distance * cos(this.dir); 54 | y = this.y + distance * sin(this.dir) + dropAnim(time, 0, 200, dur); 55 | z = anim(time, 1, -1, dur); 56 | 57 | this.circle.attr({ 58 | cx: x, 59 | cy: y 60 | }).scale(z, z); 61 | }; 62 | 63 | ClassJuice.prototype.onTimeEnd = function() { 64 | this.circle.remove(); 65 | tools.unsetObject(this); 66 | }; 67 | 68 | exports.create = function(x, y, color) { 69 | for (var i = 0; i < num; i++) 70 | this.createOne(x, y, color); 71 | }; 72 | 73 | exports.createOne = function(x, y, color) { 74 | if (!color) 75 | return; 76 | 77 | var juice = new ClassJuice(x, y, color); 78 | juice.render(); 79 | juice.sputter(); 80 | }; 81 | 82 | }); 83 | -------------------------------------------------------------------------------- /scripts/collision.js: -------------------------------------------------------------------------------- 1 | define("scripts/collision.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | /** 5 | * 碰撞检测 6 | */ 7 | 8 | exports.check = function(knife, fruit) { 9 | return lineInEllipse( 10 | knife.slice(0, 2), 11 | knife.slice(2, 4), 12 | [fruit.x, fruit.y], 13 | fruit.radius 14 | ); 15 | }; 16 | 17 | function sqr(x) { 18 | return x * x; 19 | } 20 | 21 | function sign(n) { 22 | return n < 0 ? -1 : (n > 0 ? 1 : 0); 23 | } 24 | 25 | function equation12(a, b, c) { 26 | if (a == 0) return; 27 | 28 | var delta = b * b - 4 * a * c; 29 | if (delta == 0) 30 | return [-1 * b / (2 * a), -1 * b / (2 * a)]; 31 | else if (delta > 0) 32 | return [(-1 * b + Math.sqrt(delta)) / (2 * a), (-1 * b - Math.sqrt(delta)) / (2 * a)]; 33 | } 34 | 35 | // 返回线段和椭圆的两个交点,如果不相交,返回 null 36 | function lineXEllipse(p1, p2, c, r, e) { 37 | // 线段:p1, p2 圆心:c 半径:r 离心率:e 38 | if (r <= 0) return; 39 | e = e === undefined ? 1 : e; 40 | var t1 = r, t2 = r * e, k, a, b; 41 | 42 | a = sqr(t2) * sqr(p1[0] - p2[0]) + sqr(t1) * sqr(p1[1] - p2[1]); 43 | 44 | if (a <= 0) return; 45 | 46 | b = 2 * sqr(t2) * (p2[0] - p1[0]) * (p1[0] - c[0]) + 2 * sqr(t1) * (p2[1] - p1[1]) * (p1[1] - c[1]); 47 | c = sqr(t2) * sqr(p1[0] - c[0]) + sqr(t1) * sqr(p1[1] - c[1]) - sqr(t1) * sqr(t2); 48 | 49 | if (!(k = equation12(a, b, c, t1, t2))) return; 50 | 51 | var result = [ 52 | [p1[0] + k[0] * (p2[0] - p1[0]), p1[1] + k[0] * (p2[1] - p1[1])], 53 | [p1[0] + k[1] * (p2[0] - p1[0]), p1[1] + k[1] * (p2[1] - p1[1])] 54 | ]; 55 | 56 | if (!((sign(result[0][0] - p1[0]) * sign(result[0][0] - p2[0]) <= 0) && 57 | (sign(result[0][1] - p1[1]) * sign(result[0][1] - p2[1]) <= 0))) 58 | result[0] = null; 59 | 60 | if (!((sign(result[1][0] - p1[0]) * sign(result[1][0] - p2[0]) <= 0) && 61 | (sign(result[1][1] - p1[1]) * sign(result[1][1] - p2[1]) <= 0))) 62 | result[1] = null; 63 | 64 | return result; 65 | } 66 | 67 | // 判断计算线段和椭圆是否相交 68 | function lineInEllipse(p1, p2, c, r, e) { 69 | var t = lineXEllipse(p1, p2, c, r, e); 70 | return t && (t[0] || t[1]); 71 | }; 72 | 73 | }); 74 | -------------------------------------------------------------------------------- /scripts/lib/tween.js: -------------------------------------------------------------------------------- 1 | define("scripts/lib/tween.js", function(exports, require, module){ 2 | "use strict"; 3 | 4 | exports.exponential = function(){}; 5 | exports.exponential.co = function(index, offset, target, framesNum){ return (index == framesNum) ? offset + target : target * (-Math.pow(2, -10 * index / framesNum) + 1) + offset; }; 6 | // exports.exponential.ci = function(index, offset, target, framesNum){ return (index == 0) ? offset : target * Math.pow(2, 10 * (index / framesNum - 1)) + offset; } 7 | 8 | exports.bounce = function(){}; 9 | exports.bounce.co = function(index, offset, target, framesNum){ if((index /= framesNum) < (1 / 2.75)) return target * (7.5625 * index * index) + offset; else if(index < (2 / 2.75)) return target * (7.5625 * (index -= (1.5 / 2.75)) * index + .75) + offset; else if(index < (2.5 / 2.75)) return target * (7.5625 * (index -= (2.25 / 2.75)) * index + .9375) + offset; else return target * (7.5625 * (index -= (2.625 / 2.75)) * index + .984375) + offset; }; 10 | 11 | exports.quadratic = function(){}; 12 | exports.quadratic.ci = function(index, offset, target, framesNum){ return target * (index /= framesNum) * index + offset; }; 13 | exports.quadratic.co = function(index, offset, target, framesNum){ return - target * (index /= framesNum) * (index - 2) + offset; } 14 | exports.quadratic.cio = function(index, offset, target, framesNum){ if((index /= framesNum / 2) < 1) return target / 2 * index * index + offset; else return - target / 2 * ((-- index) * (index - 2) - 1) + offset; }; 15 | 16 | exports.circular = function(index, offset, target, framesNum){ if((index /= framesNum / 2) < 1) return - target / 2 * (Math.sqrt(1 - index * index) - 1) + offset; else return target / 2 * (Math.sqrt(1 - (index -= 2) * index) + 1) + offset; } 17 | 18 | exports.linear = function(index, offset, target, framesNum){ return target * index / framesNum + offset; }; 19 | 20 | exports.back = function(){}; 21 | exports.back.ci = function(index, offset, target, framesNum, s){ s = 1.70158; return target * (index /= framesNum) * index * ((s + 1) * index - s) + offset; }; 22 | exports.back.co = function(index, offset, target, framesNum, s){ s = 1.70158; return target * ((index = index / framesNum - 1) * index * ((s + 1) * index + s) + 1) + offset; }; 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /scripts/knife.js: -------------------------------------------------------------------------------- 1 | define("scripts/knife.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var timeline = require("scripts/timeline"); 5 | var layer = require("scripts/layer").getLayer("knife"); 6 | 7 | /** 8 | * 刀光模块 9 | */ 10 | 11 | var lastX = null, lastY = null; 12 | var abs = Math.abs; 13 | 14 | var life = 200; 15 | var stroke = 10; 16 | var color = "#cbd3db"; 17 | var anims = []; 18 | var knifes = []; 19 | 20 | function ClassKnifePart(conf) { 21 | this.sx = conf.sx; 22 | this.sy = conf.sy; 23 | this.ex = conf.ex; 24 | this.ey = conf.ey; 25 | 26 | knifes.push(this); 27 | } 28 | 29 | ClassKnifePart.prototype.set = function() { 30 | var sx, sy, ex, ey, dx, dy, ax, ay; 31 | 32 | sx = this.sx; 33 | sy = this.sy; 34 | ex = this.ex; 35 | ey = this.ey; 36 | 37 | dx = sx - ex; 38 | dy = sy - ey; 39 | ax = abs(dx); 40 | ay = abs(dy); 41 | 42 | if (ax > ay) 43 | sx += dx < 0 ? -1 : 1, 44 | sy += dy < 0 ? -(1 * ay / ax) : 1 * ay / ax; 45 | else 46 | sx += dx < 0 ? -(1 * ax / ay) : 1 * ax / ay, 47 | sy += dy < 0 ? -1 : 1; 48 | 49 | this.line = layer.path("M" + sx + "," + sy + "L" + ex + "," + ey).attr({ 50 | "stroke": color, 51 | "stroke-width": stroke + "px" 52 | }); 53 | 54 | timeline.createTask({ 55 | start: 0, 56 | duration: life, 57 | object: this, 58 | onTimeUpdate: this.update, 59 | onTimeEnd: this.end, 60 | recycle: anims 61 | }); 62 | return this; 63 | }; 64 | 65 | ClassKnifePart.prototype.update = function(time) { 66 | this.line.attr("stroke-width", stroke * (1 - time / life) + "px"); 67 | }; 68 | 69 | ClassKnifePart.prototype.end = function() { 70 | this.line.remove(); 71 | 72 | var index; 73 | if (index = knifes.indexOf(this)) 74 | knifes.splice(index, 1); 75 | }; 76 | 77 | exports.newKnife = function() { 78 | lastX = lastY = null; 79 | }; 80 | 81 | exports.through = function(x, y) { 82 | var ret = null; 83 | if (lastX !== null && (lastX != x || lastY != y)) { 84 | new ClassKnifePart({ 85 | sx: lastX, 86 | sy: lastY, 87 | ex: x, 88 | ey: y 89 | }).set(); 90 | ret = [lastX, lastY, x, y]; 91 | } 92 | 93 | lastX = x; 94 | lastY = y; 95 | return ret; 96 | }; 97 | 98 | }); 99 | -------------------------------------------------------------------------------- /scripts/layer.js: -------------------------------------------------------------------------------- 1 | define("scripts/layer.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | /** 5 | * layer manager 6 | */ 7 | 8 | var Raphael = require("scripts/lib/raphael"); 9 | var layout = require("scripts/layout"); 10 | 11 | var layers = {}; 12 | var zIndexes = { 13 | "default": zi(), 14 | "light": zi(), 15 | "knife": zi(), 16 | "fruit": zi(), 17 | "juice": zi(), 18 | "flash": zi(), 19 | "mask": zi() 20 | }; 21 | 22 | 23 | var imageCache = {}; 24 | 25 | exports.preloadImage = function(src, callback) { 26 | var img = new Image(), canvas, ctx, error; 27 | //img.crossOrigin = "anonymous"; 28 | img.src = src; 29 | img.onload = function() { 30 | canvas = document.createElement('canvas'); 31 | canvas.height = img.naturalHeight; 32 | canvas.width = img.naturalWidth; 33 | ctx = canvas.getContext('2d'); 34 | ctx.drawImage(img, 0, 0); 35 | try { 36 | imageCache[src] = canvas.toDataURL(); 37 | } catch (e) { 38 | error = e; 39 | } 40 | callback(error); 41 | }; 42 | }; 43 | 44 | exports.replaceImage = function(image, src) { 45 | src = imageCache[src] || src; 46 | image.attr("src", src); 47 | }; 48 | 49 | exports.createImage = function(layer, src, x, y, w, h) { 50 | layer = this.getLayer(layer); 51 | src = imageCache[src] || src; 52 | return layer.image(src, x, y, w, h); 53 | }; 54 | 55 | exports.createText = function(layer, text, x, y, fill, size) { 56 | layer = this.getLayer(layer); 57 | 58 | return layer.text(x, y, text).attr({ 59 | fill: fill || "#fff", 60 | "font-size": size || "14px", 61 | "text-anchor": "start" 62 | }); 63 | }; 64 | 65 | exports.getLayer = function(name) { 66 | var p, layer; 67 | name = name || "default"; 68 | 69 | if (p = layers[name]) { 70 | return p; 71 | } else { 72 | layer = document.createElement("div"); 73 | layer.className = "layer"; 74 | layer.style.cssText = "z-index: " + (zIndexes[name] || 0) + ";"; 75 | 76 | document.getElementById("extra").appendChild(layer); 77 | p = layers[name] = Raphael(layer, layout.width(), layout.height()); 78 | return p; 79 | } 80 | }; 81 | 82 | function zi() { 83 | return zi.num = ++zi.num || 2; 84 | }; 85 | 86 | exports.resize = function() { 87 | for (var name in layers) { 88 | layers[name].setSize(layout.width(), layout.height()); 89 | } 90 | }; 91 | }); 92 | -------------------------------------------------------------------------------- /scripts/light.js: -------------------------------------------------------------------------------- 1 | define("scripts/light.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | /** 5 | * 炸弹爆炸时的光线 6 | */ 7 | 8 | var layer = require("scripts/layer"); 9 | 10 | var maskLayer = layer.getLayer("mask"); 11 | layer = layer.getLayer("light"); 12 | 13 | var tools = require("scripts/tools"); 14 | var timeline = require("scripts/timeline"); 15 | var layout = require("scripts/layout"); 16 | 17 | var random = tools.randomNumber; 18 | 19 | var pi = Math.PI; 20 | var sin = Math.sin; 21 | var cos = Math.cos; 22 | 23 | var lights = []; 24 | var indexes = []; 25 | var lightsNum = 10; 26 | 27 | for (var i = 0; i < lightsNum; i++) 28 | indexes[i] = i; 29 | 30 | function removeLights() { 31 | for (var i = 0, l = lights.length; i < l; i++) 32 | lights[i].remove(); 33 | lights.length = 0; 34 | } 35 | 36 | function build(x, y, r, color) { 37 | var l = layout.width() + layout.height(); 38 | var a1, a2, x1, y1, x2, y2; 39 | 40 | a1 = r * 36 + random(10); 41 | a2 = a1 + 5; 42 | 43 | a1 = pi * a1 / 180; 44 | a2 = pi * a2 / 180; 45 | 46 | x1 = x + l * cos(a1); 47 | y1 = y + l * sin(a1); 48 | 49 | x2 = x + l * cos(a2); 50 | y2 = y + l * sin(a2); 51 | 52 | var light = layer.path(["M", x, y, "L", x1, y1, "L", x2, y2, "Z"]).attr({ 53 | stroke: "none", 54 | fill: color 55 | }); 56 | 57 | lights.push(light); 58 | } 59 | 60 | exports.start = function(fruit, callback) { 61 | var x = fruit.x, 62 | y = fruit.y, 63 | time = 0, 64 | idx = tools.randomArray(indexes); 65 | 66 | var i = lightsNum, 67 | b = function() { 68 | build(x, y, idx[this], fruit.color); 69 | }; 70 | 71 | while (i--) 72 | setTimeout(b.bind(i), time += 100); 73 | 74 | setTimeout(function() { 75 | removeLights(); 76 | callback(); 77 | }, time + 100); 78 | }; 79 | 80 | exports.showWhiteLight = function(callback) { 81 | var dur = 4e3; 82 | var mask = maskLayer.rect(0, 0, layout.width(), layout.height()).attr({ 83 | fill: "#fff", 84 | stroke: "none" 85 | }); 86 | var control = { 87 | onTimeUpdate: function(time) { 88 | mask.attr("opacity", 1 - time / dur); 89 | }, 90 | 91 | onTimeEnd: function() { 92 | mask.remove(); 93 | if (callback) 94 | callback(); 95 | } 96 | }; 97 | 98 | timeline.createTask({ 99 | start: 0, 100 | duration: dur, 101 | object: control, 102 | onTimeUpdate: control.onTimeUpdate, 103 | onTimeEnd: control.onTimeEnd 104 | }); 105 | }; 106 | 107 | }); 108 | -------------------------------------------------------------------------------- /scripts/drag.js: -------------------------------------------------------------------------------- 1 | define("scripts/drag.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var tools = require("scripts/tools"); 5 | 6 | function getCoors(e) { 7 | var coors = []; 8 | if (e.targetTouches && e.targetTouches.length) { // iPhone 9 | var thisTouch = e.targetTouches[0]; 10 | coors[0] = thisTouch.clientX; 11 | coors[1] = thisTouch.clientY; 12 | } else { // all others 13 | coors[0] = e.clientX; 14 | coors[1] = e.clientY; 15 | } 16 | return coors; 17 | } 18 | 19 | function BasicDrag() { 20 | var isTouch = this.isTouch = "ontouchstart" in window; 21 | 22 | this.TOUCH_START = isTouch ? "touchstart" : "mousedown", 23 | this.TOUCH_MOVE = isTouch ? "touchmove" : "mousemove", 24 | this.TOUCH_END = isTouch ? "touchend" : "mouseup"; 25 | } 26 | 27 | BasicDrag.prototype.init = function(el) { 28 | this.element = el; 29 | tools.addEvent(el, this.TOUCH_START, function(e) { 30 | this.startDrag(getCoors(e)); 31 | e.cancelBubble = true; 32 | e.stopPropagation && e.stopPropagation(); 33 | return e.returnValue = false; 34 | }.bind(this)); 35 | }; 36 | 37 | //private 38 | BasicDrag.prototype.startDrag = function(coors) { 39 | var element = this.element; 40 | var draging = this.draging = {}; 41 | this.isDraging = true; 42 | 43 | draging.mouseX = coors[0]; 44 | draging.mouseY = coors[1]; 45 | 46 | this.registerDocumentEvent(); 47 | }; 48 | 49 | //private 50 | BasicDrag.prototype.endDrag = function() { 51 | this.isDraging = false; 52 | this.unRegisterDocumentEvent(); 53 | }; 54 | 55 | //private 56 | BasicDrag.prototype.registerDocumentEvent = function() { 57 | var draging = this.draging; 58 | 59 | draging.documentSelectStart = 60 | tools.addEvent(document, "selectstart", function(e) { 61 | e.stopPropagation && e.stopPropagation(); 62 | e.cancelBubble = true; 63 | return e.returnValue = false; 64 | }); 65 | 66 | draging.documentMouseMove = 67 | tools.addEvent(document, this.TOUCH_MOVE, function(e) { 68 | var coors = getCoors(e); 69 | draging.newMouseX = coors[0]; 70 | draging.newMouseY = coors[1]; 71 | e.stopPropagation && e.stopPropagation(); 72 | return e.returnValue = false; 73 | }.bind(this)); 74 | 75 | draging.documentMouseUp = 76 | tools.addEvent(document, this.TOUCH_END, function() { 77 | this.endDrag(); 78 | }.bind(this)); 79 | 80 | var lx, ly; 81 | 82 | clearInterval(draging.timer); 83 | draging.timer = setInterval(function() { 84 | var dx, dy; 85 | if (draging.newMouseX != lx && draging.newMouseY != ly) { 86 | lx = draging.newMouseX; 87 | ly = draging.newMouseY; 88 | dx = draging.newMouseX - draging.mouseX; 89 | dy = draging.newMouseY - draging.mouseY; 90 | this.returnValue(dx, dy, draging.newMouseX, draging.newMouseY); 91 | } 92 | }.bind(this), 10); 93 | }; 94 | 95 | //private 96 | BasicDrag.prototype.unRegisterDocumentEvent = function() { 97 | var draging = this.draging; 98 | tools.delEvent(document, this.TOUCH_MOVE, draging.documentMouseMove); 99 | tools.delEvent(document, this.TOUCH_END, draging.documentMouseUp); 100 | tools.delEvent(document, "selectstart", draging.documentSelectStart); 101 | clearInterval(draging.timer); 102 | }; 103 | 104 | //private 105 | BasicDrag.prototype.returnValue = function(dx, dy, x, y) { 106 | //todo something 107 | }; 108 | 109 | BasicDrag.prototype.on = function(name, fn) { 110 | var method = this[name]; 111 | if (!method) 112 | return; 113 | this[name] = function() { 114 | method.apply(this, arguments); 115 | fn.apply(this, arguments); 116 | }.bind(this); 117 | }; 118 | 119 | exports.create = function() { 120 | return new BasicDrag(); 121 | }; 122 | 123 | }); 124 | -------------------------------------------------------------------------------- /scripts/scene.js: -------------------------------------------------------------------------------- 1 | define("scripts/scene.js", function(exports, require, module) { 2 | "use strict"; 3 | 4 | var soundManager = require("scripts/sound-manager"); 5 | var fruitManager = require("scripts/fruit-manager"); 6 | var drag = require("scripts/drag"); 7 | var knife = require("scripts/knife"); 8 | var layout = require("scripts/layout"); 9 | var layer = require("scripts/layer"); 10 | var tools = require("scripts/tools"); 11 | 12 | var background = require("scripts/object/background"); 13 | var logo = require("scripts/object/logo"); 14 | var newGame = require("scripts/object/new-game"); 15 | var score = require("scripts/object/score"); 16 | var mistake = require("scripts/object/mistake"); 17 | var gameOver = require("scripts/object/game-over"); 18 | 19 | var game = require("scripts/game"); 20 | 21 | var newGameIcon; 22 | var gameOverState; 23 | var curScene; 24 | 25 | var playButton; 26 | function showPlayButton(cb) { 27 | if (playButton) { 28 | setTimeout(cb, 2000); 29 | return; 30 | } 31 | playButton = document.getElementById("play-button"); 32 | playButton.style.display = "block"; 33 | tools.addEvent(playButton, "ontouchend" in window ? "touchend" : "click", function() { 34 | playButton.style.display = "none"; 35 | cb(); 36 | }); 37 | } 38 | 39 | function showNewGame() { 40 | newGame.setIcon("winnie", 96, 96, function(){ 41 | soundManager.play("winnie"); 42 | switchScene("game-body"); 43 | }); 44 | newGame.show(); 45 | } 46 | 47 | var _sceneHomeMenu = { 48 | enter: function() { 49 | logo.show(); 50 | showPlayButton(showNewGame); 51 | }, 52 | 53 | exit: function() { 54 | newGame.hide(); 55 | logo.hide(); 56 | } 57 | }; 58 | 59 | var _sceneGameBody = { 60 | enter: function() { 61 | score.show(); 62 | mistake.show(); 63 | game.start(function() { 64 | switchScene("game-over"); 65 | }); 66 | }, 67 | 68 | exit: function() {} 69 | }; 70 | 71 | var _sceneGameOver = { 72 | enter: function() { 73 | soundManager.play("gameover"); 74 | gameOver.show(); 75 | setTimeout(function() { 76 | gameOverState = true; 77 | }, 1000); 78 | }, 79 | 80 | exit: function() { 81 | gameOverState = false; 82 | score.hide(); 83 | mistake.hide(); 84 | gameOver.hide(); 85 | } 86 | }; 87 | 88 | var sceneList = { 89 | "home-menu": _sceneHomeMenu, 90 | "game-body": _sceneGameBody, 91 | "game-over": _sceneGameOver 92 | }; 93 | 94 | function switchScene(name, delay) { 95 | if (curScene === name) 96 | return; 97 | if (curScene) 98 | sceneList[curScene].exit(); 99 | curScene = name; 100 | 101 | if (delay) { 102 | setTimeout(sceneList[name].enter, delay); 103 | } else { 104 | sceneList[name].enter(); 105 | } 106 | } 107 | 108 | function bindDrag() { 109 | var dragger = drag.create(); 110 | 111 | var ret; 112 | dragger.on("returnValue", function(dx, dy, x, y) { 113 | if (ret = knife.through(x - layout.x(), y - layout.y())) 114 | fruitManager.checkCollision(ret); 115 | }); 116 | 117 | dragger.on("startDrag", function() { 118 | knife.newKnife(); 119 | }); 120 | 121 | dragger.init(document.documentElement); 122 | } 123 | 124 | var inited = false; 125 | function init() { 126 | if (inited) return; 127 | 128 | logo.set(); 129 | newGame.set(); 130 | mistake.set(); 131 | score.set(); 132 | gameOver.set(); 133 | 134 | bindDrag(); 135 | 136 | tools.addEvent(document, "ontouchend" in window ? "touchend" : "click", function() { 137 | if (gameOverState) 138 | switchScene("home-menu", 1000); 139 | }); 140 | 141 | resize(); 142 | inited = true; 143 | } 144 | 145 | function resize() { 146 | layer.resize(); 147 | background.resize(); 148 | if (inited) { 149 | logo.resize(); 150 | newGame.resize(); 151 | mistake.resize(); 152 | score.resize(); 153 | gameOver.resize(); 154 | } 155 | } 156 | 157 | background.set(); 158 | tools.addEvent(window, "resize", resize); 159 | 160 | exports.init = init; 161 | exports.switchScene = switchScene; 162 | 163 | }); 164 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |1){x=y.sqrt(x);c=x*c;d=x*d}var z=c*c,A=d*d,C=(f==g?-1:1)*y.sqrt(B((z*A-z*u*u-A*t*t)/(z*u*u+A*t*t))),E=C*c*u/d+(a+h)/2,F=C*-d*t/c+(b+i)/2,G=y.asin(((b-F)/d).toFixed(9)),H=y.asin(((i-F)/d).toFixed(9));G=a e){if(c&&!l.start){m=cq(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n);k+=["C",m.start.x,m.start.y,m.m.x,m.m.y,m.x,m.y];if(f)return k;l.start=k;k=["M",m.x,m.y+"C",m.n.x,m.n.y,m.end.x,m.end.y,i[5],i[6]][v]();n+=j;g=+i[5];h=+i[6];continue}if(!b&&!c){m=cq(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n);return{x:m.x,y:m.y,alpha:m.alpha}}}n+=j;g=+i[5];h=+i[6]}k+=i}l.end=k;m=b?n:c?l:a.findDotsAtSegment(g,h,i[1],i[2],i[3],i[4],i[5],i[6],1);m.alpha&&(m={x:m.x,y:m.y,alpha:m.alpha});return m}},cs=cr(1),ct=cr(),cu=cr(0,1);bO.getTotalLength=function(){if(this.type!="path")return;if(this.node.getTotalLength)return this.node.getTotalLength();return cs(this.attrs.path)};bO.getPointAtLength=function(a){if(this.type!="path")return;return ct(this.attrs.path,a)};bO.getSubpath=function(a,b){if(this.type!="path")return;if(B(this.getTotalLength()-b)<"1e-6")return cu(this.attrs.path,a).end;var c=cu(this.attrs.path,b,1);return a?cu(c,a).end:c};a.easing_formulas={linear:function(a){return a},"<":function(a){return C(a,3)},">":function(a){return C(a-1,3)+1},"<>":function(a){a=a*2;if(a<1)return C(a,3)/2;a-=2;return(C(a,3)+2)/2},backIn:function(a){var b=1.70158;return a*a*((b+1)*a-b)},backOut:function(a){a=a-1;var b=1.70158;return a*a*((b+1)*a+b)+1},elastic:function(a){if(a==0||a==1)return a;var b=0.3,c=b/4;return C(2,-10*a)*y.sin((a-c)*(2*D)/b)+1},bounce:function(a){var b=7.5625,c=2.75,d;if(a<1/c)d=b*a*a;else if(a<2/c){a-=1.5/c;d=b*a*a+0.75}else if(a<2.5/c){a-=2.25/c;d=b*a*a+0.9375}else{a-=2.625/c;d=b*a*a+0.984375}return d}};var cv=[],cw=function(){var b=+(new Date);for(var c=0;c