123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- function Game(heartUrl, callback) {
- this.fCode = ['anbaodi', 'huazhuang', 'xiaoheiz'];
- this.callback = callback || '';
- this.renderType = 'canvas';
- this.heartUrl = heartUrl;
- this.gameContainer = document.getElementById('gameContainer');
- this.text = document.getElementById('text');
- this.minutes = document.getElementById('minutes');
- this.seconds = document.getElementById('seconds');
- this.finalBonus = document.getElementById('finalBonus');
- this.select = document.getElementById('select');
- this.countText = document.getElementById('countText');
- this.money = document.getElementById('money');
- this.finalCount = document.getElementById('finalCount');
- this.finalMoney = document.getElementById('finalMoney');
- this.moneyText = 20;
- this.w = 750;
- this.h = 1217;
- this.averageN = Math.floor(this.w / 94) - 2;
- this.averageW = this.w / this.averageN;
- this.stage = null;
- this.ticker = null;
- this.Tween = null;
- this.Ease = null;
- this.count = 0;
- this.times = 20;
- this.fcode_base_url = "https://passport.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=";
- this.type_sn = '';
- this.fcode_url = this.fcode_base_url + this.type_sn;
- this.gameContainer.style.height = this.h + 'px';
- this.draw = new Draw();
- this.init();
- this.start();
- this.draw.setValue(0);
- }
- Game.prototype = {
- init: function () {
- var _this = this;
- this.stage = new Hilo.Stage({
- renderType: this.renderType,
- container: this.gameContainer,
- width: this.w,
- height: this.h
- });
- this.stage.enableDOMEvent(Hilo.event.POINTER_START, true);
- this.ticker = new Hilo.Ticker(60);
- this.Tween = Hilo.Tween;
- this.Ease = Hilo.Ease;
- this.ticker.addTick(this.stage);
- this.ticker.addTick(this.Tween);
- this.ticker.interval(function () {
- _this.times--;
- _this.countTimesText();
- if (_this.times <= 0) {
- this.gameContainer.innerHTML = '';
- _this.finalResult();
- $('#speaker_handle').fadeOut('fast');
- $('#Jaudio').attr('src', '');
- _this.stage.removeAllChildren();
- _this.ticker.stop();
- }
- }, 1000);
- this.ticker.start();
- },
- start: function () {
- var _this = this;
- for (var i = 0; i < this.averageN; i++) {
- var minP = this.averageW * i + 47;
- var maxP = this.averageW * (i + 1) - 47;
- var x = Math.round(Math.random() * (maxP - minP) + minP);
- (function (j, x) {
- setTimeout(function () {
- _this.create(x);
- }, j * 80);
- })(i, x);
- }
- },
- create: function (x) {
- var _this = this;
- var heartSpeed = (Math.random() * 5 + 8).toFixed(2);
- var left = x || Math.round(Math.random() * (this.w - 94) + 47);
- var heart0 = new Hilo.Bitmap({
- image: _this.heartUrl,
- rect: [0, 0, 94, 80],
- x: left,
- y: _this.h,
- scaleX: 1,
- scaleY: 1,
- pivotX: 47,
- pivotY: 40,
- onUpdate: function () {
- this.y -= this.speed;
- if (this.y < 0) {
- this.removeFromParent();
- setTimeout(function () {
- _this.create();
- }, 100);
- }
- },
- }).addTo(_this.stage);
- heart0.on(Hilo.event.POINTER_START, function (e) {
- var self = this;
- _this.Tween.to(this, {
- scaleX: 1.4,
- scaleY: 1.4,
- alpha: .7
- }, {
- duration: 300,
- ease: _this.Ease.Bounce.EaseIn,
- onComplete: function () {
- self.removeFromParent();
- _this.count++;
- _this.calcScore();
- setTimeout(function () {
- _this.create();
- }, 100)
- }
- });
- }, false);
- heart0.speed = heartSpeed;
- },
- countTimesText: function() {
- var times = this.times >= 10 ? this.times.toString() : '0' + this.times;
- var arr = times.split('');
- this.minutes.innerHTML = arr[0];
- this.seconds.innerHTML = arr[1];
- },
- calcScore: function() {
- var score = 0;
- // 微信分享后玩第二次, app点击后可以玩第二次
- if(from_app) {
- if(appClick == 1) {
- score = this.count * 2 > 70 ? 70 : this.count * 2;
-
- }
- else {
- score = this.count * 2 > 100 ? 100 : this.count * 2;
- }
- }
- else {
- if(!isShare) {
- score = this.count * 2 > 70 ? 70 : this.count * 2;
- }
- else {
- score = this.count * 2 > 100 ? 100 : this.count * 2;
- }
- }
- // if(!score)return;
- if(score < 21) {
- this.moneyText = 20;
- this.type_sn = '75871534212363894680';
- }
- else if(score < 41) {
- this.moneyText = 40;
- this.type_sn = '90771534212382068658';
- }
- else if(score < 61) {
- this.moneyText = 60;
- this.type_sn = '36011534212399441256';
- }
- else if(score < 81) {
- this.moneyText = 80;
- this.type_sn = '81851534212419720914'
- }
- else if(score < 100) {
- this.moneyText = 99;
- this.type_sn = '42891534212437309614'
- }
- else {
- this.moneyText = 100;
- this.type_sn = '46851534212455402795'
- }
- this.draw.setValue(score);
- },
- caclBonus: function() {
- this.countText.innerHTML = this.finalCount.innerHTML = this.count;
- this.money.innerHTML = this.finalMoney.innerHTML = this.moneyText;
- var fcode_url = this.fcode_base_url + this.type_sn;
- $('.receive_bonus, .final_bonus_link').attr('src', fcode_url);
- },
- restart: function() {
- this.gameContainer.innerHTML = '';
- this.times = 20;
- this.countTimesText();
- this.init();
- this.start();
- },
- finalResult: function() {
- this.caclBonus();
- if(from_app) {
- if(appClick == 1) {
- this.select.style.display = 'block';
- return;
- }
- }
- else {
- if(!isShare) {
- this.select.style.display = 'block';
- return;
- }
- }
- if(this.count < 100) {
- this.finalBonus.style.display = 'block'
- }
- else {
- this.callback && this.callback();
- }
-
- }
- }
|