Commit f008892f by 李楚霏

1121代码整理

parent e5b3decd
/**
/**
* Copyright (c) 2019 AnyGame. All rights reserved.
*/
let panelManager = null;
const panel = require('panel');
const panelLogic = require('crazyHitLogic');
const banner = require('banner');
const manager = require('manager');
cc.Class({
extends: panel,
properties: {
win: {
type: cc.Node,
default: null,
tooltip: '胜利提示',
},
final: {
type: cc.Node,
default: null,
tooltip: '最终结果',
},
title: {
type: cc.Node,
default: null,
tooltip: '正常提示',
},
meatPrefab: {
default: null,
type: cc.Prefab,
tooltip: '肉节点',
},
crazyBar: cc.ProgressBar, // 进度条
crazyBtn: cc.Node, // 疯狂点击按钮
ndCrazy: cc.Node, // 管理疯狂点击的节点
ndBtnGet: cc.Node, // 普通领取按钮
dinosaurNode: { //恐龙
default: null,
type: cc.Node,
tooltip: "恐龙"
},
levelPreb: cc.Prefab, //经验值动画
},
onLoad() {
panelManager = require('panelManager');
this.dinosaur = this.dinosaurNode.getComponent('dinosaurCrazy');
this.dinosaur.init();
this.posArray = []; /* 记录元素位置坐标 */
this.meats = [];
var x = 0;
var y = 10;
for (let index = 0; index < 4; index++) {
var meat = cc.instantiate(this.meatPrefab);
this.meats.push(meat);
meat.setPosition(cc.v2(x, y));
x = this.meats[index].x + 100;
var pos = meat.position;
this.posArray.push(pos);
cc.log("init:" + this.meats[index].position);
this.node.addChild(meat);
}
},
onEnable() {
// this.watch 接口 调用
},
/**
* 界面显示时相关逻辑接口
*/
show(params) {
this.unscheduleAllCallbacks();
require('manager').sendEvent('界面曝光-大按钮狂点');
if (params) {
this.callback = params.callback;
}
this.meatNum = 0; /* 吃肉的个数 */
this.crazyBar.progress = 0;
this.win.active = false;
this.final.active = false;
this.title.active = true;
this.ndBtnGet.active = false;
this.ndCrazy.active = true;
//this.countdown.node.active = true;
this.startCutProgress = false;
},
cutProgress() {
this.unschedule(this.cutProgress);
return;
},
over(quick) {
require('manager').sendEvent('界面曝光-大按钮狂点-结束');
if (this.crazyBar.progress < 0.7) {
this.title.active = false;
this.final.active = true;
this.win.active = false;
} else {
this.title.active = false;
this.final.active = false;
this.win.active = true;
}
this.ndBtnGet.active = true;
this.ndCrazy.active = false;
this.mistake(quick);
/**
*最终显示吃肉个数
*/
this.win.getComponent('cc.Label').string = '我吃了' + this.meatNum + '个肉';
},
onCrazyBtnClick() {
if (!this.startCutProgress) {
this.startCutProgress = true;
this.unschedule(this.cutProgress);
this.schedule(this.cutProgress, 1);
}
if (this.eating) {
return;
}
this.eating = true;
let meat = this.meats[0];
let targetPos = cc.v2(meat.x - 100, meat.y);
const moveToAction = cc.moveTo(0.1, targetPos);
let finish = cc.callFunc(() => {
this.eating = false;
meat.position = this.posArray[this.posArray.length - 1];
for (let i = 0; i < this.meats.length; i++) {
if (i === this.meats.length - 1) {
this.meats[i] = meat;
} else {
this.meats[i] = this.meats[i + 1];
}
}
}, this);
var seq = cc.sequence(moveToAction, finish);
meat.runAction(seq);
for (let i = 1; i < this.meats.length; ++i) {
if (!this.meats[i]) {
continue;
}
let targetPos = cc.v2(this.meats[i].x - 100, this.meats[i].y);
const moveToAction = cc.moveTo(0.1, targetPos);
this.meats[i].runAction(moveToAction);
}
const levelNode = cc.instantiate(this.levelPreb);
levelNode.parent = this.dinosaur.node.parent;
let rndPosX = dataFunc.randomNum(-75, 75);
let rndPosY = dataFunc.randomNum(100, 150);
levelNode.position = cc.v2(this.dinosaur.node.x + rndPosX, this.dinosaur.node.y + rndPosY);
const levelPrebMoveToAction = cc.moveBy(1, cc.v2(0, 200));
const levelPrebFadeInAction = cc.fadeOut(1.0);
const levelPrebActionTo = cc.scaleTo(1, 0.5);
let finish2 = cc.callFunc(() => {
levelNode.destroy();
}, this);
var action = cc.spawn(levelPrebMoveToAction, levelPrebFadeInAction, levelPrebActionTo);
var seq = cc.sequence(action, finish2);
levelNode.runAction(seq);
this.dinosaur.updateSelf();
this.meatNum++;
this.crazyBar.progress += this.crazyBar.progress >= 0.7 ? 0.1 : 0.1;
if (this.crazyBar.progress < 0.2) {
levelNode.getComponent(cc.Label).string = '+1';
PlayerManager.player.addFan(1);
} else if (this.crazyBar.progress < 0.5) {
levelNode.getComponent(cc.Label).string = '+2';
PlayerManager.player.addFan(2);
levelNode.scale = 2;
} else {
levelNode.getComponent(cc.Label).string = '+3';
levelNode.scale = 3;
PlayerManager.player.addFan(3);
if (this.crazyBar.progress > 0.8) {
this.unscheduleAllCallbacks();
this.over(true);
}
}
},
onBtnGetClick() {
require('manager').sendEvent('按钮点击-大按钮狂点-继续游戏');
panelManager.hidePanel('crazyHitPanel');
window.manager.hideAdBanner('gameOverPanel');
if (this.callback && typeof this.callback === 'function') {
this.callback();
this.callback = null;
}
},
mistake(quick) {
if (window.manager.isAreaShield() || quick) {
window.manager.showAdBanner('大按钮狂点');
} else { // 误触
const p = banner.getBannerHeightCenter();
this.scheduleOnce(() => {
window.manager.showAdBanner('大按钮狂点-结算');
}, manager.setting.crazyClickDelay || 1);
}
},
update(dt) {
this.crazyBar.progress -= 0.3 * dt;
if (this.crazyBar.progress < 0) {
this.crazyBar.progress = 0;
}
},
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment