Compare commits

..

No commits in common. "b617219f5bdb8d4ce334dc6c55d20be758d11e5e" and "de5ff73df7ca7deb829905f00f3c127b28f33545" have entirely different histories.

9 changed files with 2530 additions and 2896 deletions

File diff suppressed because it is too large Load Diff

View File

@ -537,7 +537,7 @@ export default class Block extends cc.Component {
this.block_Info.node = null; this.block_Info.node = null;
} }
else if(this.type == BlockType.){ else if(this.type == BlockType.){
this.node.getChildByName("boom").getComponent("Boom").destroyBoom(false); this.node.getChildByName("boom").getComponent("Boom").destroyBoom();
} }
@ -589,7 +589,7 @@ export default class Block extends cc.Component {
} }
} }
MapConroler._instance.judgeWin(0); MapConroler._instance.judgeWin();
setTimeout(() => { setTimeout(() => {
let tempColor = this.color; let tempColor = this.color;
@ -763,7 +763,7 @@ export default class Block extends cc.Component {
var self = this; var self = this;
this.removeMapBlock(); this.removeMapBlock();
MapConroler._instance.judgeWin(1); MapConroler._instance.judgeWin();
setTimeout(() => { setTimeout(() => {
let pos = this.node.getPosition(); let pos = this.node.getPosition();
if(self.type == BlockType.){ if(self.type == BlockType.){
@ -779,7 +779,7 @@ export default class Block extends cc.Component {
self.block_Info.node.getComponent("Block").posY,false); self.block_Info.node.getComponent("Block").posY,false);
} }
else if(self.type == BlockType.){ else if(self.type == BlockType.){
this.node.getChildByName("boom").getComponent("Boom").destroyBoom(false); this.node.getChildByName("boom").getComponent("Boom").destroyBoom();
} }
MapConroler._instance.nextLevel(); MapConroler._instance.nextLevel();
@ -1319,12 +1319,14 @@ export default class Block extends cc.Component {
this.touchDelta = cc.v2(0, 0); this.touchDelta = cc.v2(0, 0);
} }
if(this.type == BlockType.){ if(this.type == BlockType. && this.moveStack == true){
if(this.block_Info.node!= null){ if((this.stacking.x != 0 || this.stacking.y!= 0) && this.block_Info.node!= null){
if(this.block_Info.node.getComponent("Block").moveStack == true){ this.isTouch = false;
this.block_Info.node.x = this.node.x + this.block_Info.node.getComponent("Block").stacking.x; // this.node.x = this.block_Info.node.x + this.stacking.x;
this.block_Info.node.y = this.node.y + this.block_Info.node.getComponent("Block").stacking.y; // this.node.y = this.block_Info.node.y + this.stacking.y;
} this.node.x = Math.round(this.block_Info.node.x + this.stacking.x);
this.node.y = Math.round(this.block_Info.node.y + this.stacking.y);
console.log("跟随移动",dt);
} }
} }
if(this.block_Info){ if(this.block_Info){

View File

@ -212,8 +212,8 @@ export default class GameManager extends cc.Component {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx !== 'undefined' && wx !== null) {
MiniGameSdk.API.shushu_Init(); MiniGameSdk.API.shushu_Init();
Utils.getUserInfo((data) => { Utils.getUserInfo((data)=>{
console.log("登陆成功", data); console.log("登陆成功",data);
}); });
let levelInfo = cc.fx.StorageMessage.getStorage("level"); let levelInfo = cc.fx.StorageMessage.getStorage("level");
//旧的读取数据设置数据方法,以强联网为主 //旧的读取数据设置数据方法,以强联网为主
@ -259,7 +259,7 @@ export default class GameManager extends cc.Component {
//新用户,有本地缓存读取配置 //新用户,有本地缓存读取配置
newReadData() { newReadData() {
console.log("读取新信息2"); console.log("读取新信息");
let openid = cc.fx.StorageMessage.getStorage("openid"); let openid = cc.fx.StorageMessage.getStorage("openid");
if (openid == null || openid == "" || openid == undefined) { if (openid == null || openid == "" || openid == undefined) {
console.log("没有openid"); console.log("没有openid");
@ -270,7 +270,7 @@ export default class GameManager extends cc.Component {
action: 'read' action: 'read'
}, },
success: res => { success: res => {
console.log('读取用户数据成功_____________________', res.result) console.log('读取用户数据成功', res.result)
if (res.result.code == 404 && res.result.message == "未找到用户数据") { if (res.result.code == 404 && res.result.message == "未找到用户数据") {
} }
else if (res.result.code == 200) { else if (res.result.code == 200) {
@ -479,7 +479,7 @@ export default class GameManager extends cc.Component {
console.log(res.result.openid); console.log(res.result.openid);
cc.fx.GameConfig.GM_INFO.openid = res.result.openid cc.fx.GameConfig.GM_INFO.openid = res.result.openid
} }
else { else{
console.log("用户此一次进入游戏为正确获取openid"); console.log("用户此一次进入游戏为正确获取openid");
} }
cc.fx.GameConfig.GM_INFO.first = true; cc.fx.GameConfig.GM_INFO.first = true;
@ -687,7 +687,7 @@ export default class GameManager extends cc.Component {
MiniGameSdk.API.shushu_Login(); MiniGameSdk.API.shushu_Login();
MiniGameSdk.API.yinli_Init(); MiniGameSdk.API.yinli_Init();
MiniGameSdk.API.yinli_Login(); MiniGameSdk.API.yinli_Login();
const group = cc.fx.GameTool.setWechatGameGroup(2); cc.fx.GameTool.setWechatGameGroup(2);
this.startGame(); this.startGame();
} }
} }

View File

@ -127,7 +127,6 @@ export default class MapConroler extends cc.Component {
onLoad() { onLoad() {
cc.fx.GameConfig.GM_INFO.review = 0; cc.fx.GameConfig.GM_INFO.review = 0;
cc.fx.GameConfig.GM_INFO.reviewBoom = 0;
cc.fx.GameConfig.GM_INFO.gameState = true; cc.fx.GameConfig.GM_INFO.gameState = true;
this.mask.opacity = 0; this.mask.opacity = 0;
this.node.getChildByName("Adhesive").zIndex = 500; this.node.getChildByName("Adhesive").zIndex = 500;
@ -187,7 +186,7 @@ export default class MapConroler extends cc.Component {
setPropNum() { setPropNum() {
//如果道具数量大于0显示 cc.fx.GameConfig.GM_INFO.freezeAmount如果为零显示'mul10' //如果道具数量大于0显示 cc.fx.GameConfig.GM_INFO.freezeAmount如果为零显示'mul10'
if (cc.fx.GameConfig.GM_INFO.freezeAmount > 0) { if(cc.fx.GameConfig.GM_INFO.freezeAmount > 0) {
this.iceNode.children[0].active = false; this.iceNode.children[0].active = false;
this.iceNode.children[1].active = true; this.iceNode.children[1].active = true;
this.iceNode.children[2].active = true; this.iceNode.children[2].active = true;
@ -197,7 +196,7 @@ export default class MapConroler extends cc.Component {
this.iceNode.children[1].active = false; this.iceNode.children[1].active = false;
this.iceNode.children[2].active = false; this.iceNode.children[2].active = false;
} }
if (cc.fx.GameConfig.GM_INFO.hammerAmount > 0) { if(cc.fx.GameConfig.GM_INFO.hammerAmount > 0) {
this.hammerNode.children[1].active = true; this.hammerNode.children[1].active = true;
this.hammerNode.children[0].active = false; this.hammerNode.children[0].active = false;
this.hammerNode.children[2].active = true; this.hammerNode.children[2].active = true;
@ -207,7 +206,7 @@ export default class MapConroler extends cc.Component {
this.hammerNode.children[1].active = false; this.hammerNode.children[1].active = false;
this.hammerNode.children[2].active = false; this.hammerNode.children[2].active = false;
} }
if (cc.fx.GameConfig.GM_INFO.magicAmount > 0) { if(cc.fx.GameConfig.GM_INFO.magicAmount > 0) {
this.magicNode.children[1].active = true; this.magicNode.children[1].active = true;
this.magicNode.children[0].active = false; this.magicNode.children[0].active = false;
this.magicNode.children[2].active = true; this.magicNode.children[2].active = true;
@ -226,7 +225,7 @@ export default class MapConroler extends cc.Component {
this.count_Time = Date.now(); this.count_Time = Date.now();
//发送数数事件——进入关卡 //发送数数事件——进入关卡
console.log("准备进入下一关,发送下一关进入"); console.log("准备进入下一关,发送下一关进入");
if ((cc.fx.GameConfig.GM_INFO.level + 1) == 1) { if((cc.fx.GameConfig.GM_INFO.level + 1) == 1) {
this.guideNode.getComponent(Animation).stop(); this.guideNode.getComponent(Animation).stop();
this.guideNode.active = false; this.guideNode.active = false;
} }
@ -325,7 +324,7 @@ export default class MapConroler extends cc.Component {
this.wallInit(); this.wallInit();
this.blockInit(); this.blockInit();
if ((cc.fx.GameConfig.GM_INFO.level + 1) == 1) { if((cc.fx.GameConfig.GM_INFO.level + 1) == 1) {
// 如果是第一关,显示引导 // 如果是第一关,显示引导
this.guideNode.active = true; this.guideNode.active = true;
this.guideNode.zIndex = 1000; this.guideNode.zIndex = 1000;
@ -1334,22 +1333,13 @@ export default class MapConroler extends cc.Component {
} }
judgeWin(number) { judgeWin(){
this.blockNum = this.blocks.length; this.blockNum = this.blocks.length;
if (number == 1) { if((this.blockNum == 0 || this.blockNum == 1) &&!this.gameWin &&!this.gameOver){
if ((this.blockNum == 0 || this.blockNum == 1) && !this.gameWin && !this.gameOver) {
this.stopTimeCutDown(); this.stopTimeCutDown();
this.stopBoom(); this.stopBoom();
} }
} }
else if (number == 0) {
if (this.blockNum == 0 && !this.gameWin && !this.gameOver) {
this.stopTimeCutDown();
this.stopBoom();
}
}
}
//判断游戏成功下一关 //判断游戏成功下一关
nextLevel() { nextLevel() {
@ -1362,7 +1352,7 @@ export default class MapConroler extends cc.Component {
// alert("游戏成功"); // alert("游戏成功");
MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level); MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level);
this.gameWin = true; this.gameWin = true;
console.log("恢复一点体力", cc.fx.GameConfig.GM_INFO.level); console.log("恢复一点体力",cc.fx.GameConfig.GM_INFO.level);
cc.fx.GameTool.setUserHealth(1, (data) => { cc.fx.GameTool.setUserHealth(1, (data) => {
}) })
this.stopTimeCutDown(); this.stopTimeCutDown();
@ -1391,7 +1381,7 @@ export default class MapConroler extends cc.Component {
} }
else { else {
if (this.gameOver == true) { if (this.gameOver == true) {
this.failLevel("time"); this.failLevel(null);
} }
} }
} }
@ -1406,14 +1396,14 @@ export default class MapConroler extends cc.Component {
winLevel() { winLevel() {
MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level); MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level);
if (this.node.parent.parent.getChildByName("Win"). if(this.node.parent.parent.getChildByName("Win").
getChildByName("nextBtn").getComponent("btnControl")._touch == false) { getChildByName("nextBtn").getComponent("btnControl")._touch == false){
return; return;
} }
this.node.parent.parent.getChildByName("Win"). this.node.parent.parent.getChildByName("Win").
getChildByName("nextBtn").getComponent("btnControl").setTouch(false); getChildByName("nextBtn").getComponent("btnControl").setTouch(false);
cc.fx.AudioManager._instance.playEffect("anniu_Big", null); cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
console.log("下一关", cc.fx.GameConfig.GM_INFO.level); console.log("下一关",cc.fx.GameConfig.GM_INFO.level);
if (cc.fx.GameConfig.GM_INFO.level > 249) { if (cc.fx.GameConfig.GM_INFO.level > 249) {
cc.fx.GameConfig.GM_INFO.level = 249; cc.fx.GameConfig.GM_INFO.level = 249;
MiniGameSdk.API.showToast("每周更新,敬请期待!"); MiniGameSdk.API.showToast("每周更新,敬请期待!");
@ -1466,28 +1456,15 @@ export default class MapConroler extends cc.Component {
// this.node.parent.parent.parent.destroy(); // this.node.parent.parent.parent.destroy();
} }
//时间到了复活 reviewLevel() {
reviewLevel(event, type) { if(this.reviewState == true){
if (this.reviewState == true) {
return; return;
} }
this.reviewState = true; this.reviewState = true;
cc.fx.AudioManager._instance.playEffect("anniu_Big", null); cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
let coin = 900; let coin = 900;
let data = {
type: type,
coin: -coin
}
if (type == "time") {
if (cc.fx.GameConfig.GM_INFO.review == 1) coin = 1900; if (cc.fx.GameConfig.GM_INFO.review == 1) coin = 1900;
else if (cc.fx.GameConfig.GM_INFO.review == 2) coin = 2500; else if (cc.fx.GameConfig.GM_INFO.review == 2) coin = 2500;
}
else if (type == "boom") {
if (cc.fx.GameConfig.GM_INFO.reviewBoom == 1) coin = 1900;
else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 2) coin = 2500;
}
data.coin = -coin;
// console.log("自身金币:",cc.fx.GameConfig.GM_INFO.coin,"消耗金币:",coin); // console.log("自身金币:",cc.fx.GameConfig.GM_INFO.coin,"消耗金币:",coin);
if (cc.fx.GameConfig.GM_INFO.coin < Math.abs(coin)) { if (cc.fx.GameConfig.GM_INFO.coin < Math.abs(coin)) {
MiniGameSdk.API.showToast("金币不足,无法加时间"); MiniGameSdk.API.showToast("金币不足,无法加时间");
@ -1499,36 +1476,26 @@ export default class MapConroler extends cc.Component {
return; return;
} }
else { else {
this.runRewive(data); this.runRewive(-coin);
} }
} }
//执行复活函数
runRewive(data) { runRewive(data) {
console.log("复活回调函数内", data); console.log("复活回调函数内", data);
cc.fx.GameTool.changeCoin(data.coin); cc.fx.GameTool.changeCoin(data);
MiniGameSdk.API.showToast("继续游戏"); MiniGameSdk.API.showToast("继续游戏");
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
if (data.type == "time") {
if (cc.fx.GameConfig.GM_INFO.review < 2) if (cc.fx.GameConfig.GM_INFO.review < 2)
cc.fx.GameConfig.GM_INFO.review += 1; cc.fx.GameConfig.GM_INFO.review += 1;
}
else if (data.type == "boom") {
if (cc.fx.GameConfig.GM_INFO.reviewBoom < 2)
cc.fx.GameConfig.GM_INFO.reviewBoom += 1;
}
this.gameOver = false; this.gameOver = false;
this.gameWin = false; this.gameWin = false;
this.pause = false;
if (data.type == "time") {
this.timeNumber = 21; this.timeNumber = 21;
this.add_Time += 20; this.add_Time += 20;
} this.pause = false;
this.blockNum = this.blocks.length; this.blockNum = this.blocks.length;
if (this.blockNum == 0) this.nextLevel(); if (this.blockNum == 0 )this.nextLevel();
this.node.parent.parent.getChildByName("Lose").active = false; this.node.parent.parent.getChildByName("Lose").active = false;
setTimeout(() => { setTimeout(() => {
@ -1609,22 +1576,15 @@ export default class MapConroler extends cc.Component {
this.node.parent.parent.getChildByName("Lose").active = true; this.node.parent.parent.getChildByName("Lose").active = true;
this.node.parent.parent.getChildByName("Lose").getChildByName("Time").active = true; this.node.parent.parent.getChildByName("Lose").getChildByName("Time").active = true;
this.node.parent.parent.getChildByName("Lose").getChildByName("Boom").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("Boom").active = false;
if (type) {
if (type == "time") {
let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("Time").getChildByName("buyBtn"); let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("Time").getChildByName("buyBtn");
buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false; buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false;
if (cc.fx.GameConfig.GM_INFO.review == 0) buyBtn.getChildByName("coin1").active = true; if (cc.fx.GameConfig.GM_INFO.review == 0) buyBtn.getChildByName("coin1").active = true;
else if (cc.fx.GameConfig.GM_INFO.review == 1) buyBtn.getChildByName("coin2").active = true; else if (cc.fx.GameConfig.GM_INFO.review == 1) buyBtn.getChildByName("coin2").active = true;
else if (cc.fx.GameConfig.GM_INFO.review == 2) buyBtn.getChildByName("coin3").active = true; else if (cc.fx.GameConfig.GM_INFO.review == 2) buyBtn.getChildByName("coin3").active = true;
} if (type) {
if (type == "boom") { if (type == "boom") {
this.node.parent.parent.getChildByName("Lose").getChildByName("Time").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("Time").active = false;
this.node.parent.parent.getChildByName("Lose").getChildByName("Boom").active = true; this.node.parent.parent.getChildByName("Lose").getChildByName("Boom").active = true;
let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("Boom").getChildByName("buyBtn");
buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false;
if (cc.fx.GameConfig.GM_INFO.reviewBoom == 0) buyBtn.getChildByName("coin1").active = true;
else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 1) buyBtn.getChildByName("coin2").active = true;
else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 2) buyBtn.getChildByName("coin3").active = true;
} }
} }
}, time); }, time);
@ -1800,7 +1760,7 @@ export default class MapConroler extends cc.Component {
this.setPropNum(); this.setPropNum();
// this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString(); // this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString();
MiniGameSdk.API.showToast("购买冻结时间成功"); MiniGameSdk.API.showToast("购买冻结时间成功");
}, 200); }, 2000);
} }
@ -1815,7 +1775,7 @@ export default class MapConroler extends cc.Component {
MiniGameSdk.API.showToast("购买魔法棒成功"); MiniGameSdk.API.showToast("购买魔法棒成功");
this.setPropNum(); this.setPropNum();
// this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString(); // this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString();
}, 200); }, 2000);
} }
else if (data == "hammerAmount") { else if (data == "hammerAmount") {
@ -1829,7 +1789,7 @@ export default class MapConroler extends cc.Component {
this.setPropNum(); this.setPropNum();
// this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString(); // this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString();
MiniGameSdk.API.showToast("购买锤子成功"); MiniGameSdk.API.showToast("购买锤子成功");
}, 200); }, 2000);
} }
@ -1847,6 +1807,15 @@ export default class MapConroler extends cc.Component {
if (hammerBtn.getComponent("btnControl")._touch) { if (hammerBtn.getComponent("btnControl")._touch) {
hammerBtn.getComponent("btnControl").setTouch(false); hammerBtn.getComponent("btnControl").setTouch(false);
if (cc.fx.GameConfig.GM_INFO.hammerAmount < 1) { if (cc.fx.GameConfig.GM_INFO.hammerAmount < 1) {
// if (cc.fx.GameConfig.GM_INFO.coin < 1500) {
// MiniGameSdk.API.showToast("金币不足,无法购买道具");
// setTimeout(() => {
// this.openShop();
// hammerBtn.getComponent("btnControl").setTouch(true);
// }, 500);
// return;
// }
this.node.parent.parent.getChildByName("propWindow").active = true; this.node.parent.parent.getChildByName("propWindow").active = true;
this.node.parent.parent.parent.getComponent("SceneManager").openPropBuy("hammer"); this.node.parent.parent.parent.getComponent("SceneManager").openPropBuy("hammer");
} }
@ -1915,7 +1884,7 @@ export default class MapConroler extends cc.Component {
cc.fx.GameTool.buyProp(2001, this.handleBuySuccess.bind(this, "freezeAmount")); cc.fx.GameTool.buyProp(2001, this.handleBuySuccess.bind(this, "freezeAmount"));
} }
openShop() { openShop(){
const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点 const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点
if (winCOIN) { if (winCOIN) {
const wincoin = winCOIN.getComponent(SceneManager); const wincoin = winCOIN.getComponent(SceneManager);
@ -1976,7 +1945,7 @@ export default class MapConroler extends cc.Component {
this.setPropNum(); this.setPropNum();
// this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString(); // this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString();
let propInfo = cc.fx.StorageMessage.getStorage("prop"); let propInfo = cc.fx.StorageMessage.getStorage("prop");
if (propInfo) { if(propInfo){
propInfo.magicAmount = cc.fx.GameConfig.GM_INFO.magicAmount; propInfo.magicAmount = cc.fx.GameConfig.GM_INFO.magicAmount;
propInfo.timestamp = timestamp; propInfo.timestamp = timestamp;
cc.fx.StorageMessage.setStorage("prop", propInfo); cc.fx.StorageMessage.setStorage("prop", propInfo);
@ -2202,7 +2171,7 @@ export default class MapConroler extends cc.Component {
} }
} }
startBoom() { startBoom(){
for (let i = 0; i < this.blocks.length; i++) { for (let i = 0; i < this.blocks.length; i++) {
if (this.blocks[i].getComponent("Block").type == 6) { if (this.blocks[i].getComponent("Block").type == 6) {
this.blocks[i].getChildByName("boom").getComponent("Boom").startBoom(); this.blocks[i].getChildByName("boom").getComponent("Boom").startBoom();

View File

@ -1127,7 +1127,7 @@ export namespace MiniGameSdk {
}, },
// 根据环境变量设置 debug 模式 // 根据环境变量设置 debug 模式
debug: !isProduction, debug: !isProduction,
enableLog: false enableLog:false
}; };
// 创建 TA 实例 // 创建 TA 实例
API._ta = new ThinkingAnalyticsAPI(config); API._ta = new ThinkingAnalyticsAPI(config);
@ -1154,7 +1154,7 @@ export namespace MiniGameSdk {
static shushu_Login() { static shushu_Login() {
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx !== 'undefined' && wx !== null) {
console.log("数数登录时获取到的openId:", cc.fx.GameConfig.GM_INFO.openid); console.log("数数登录时获取到的openId:",cc.fx.GameConfig.GM_INFO.openid);
API._ta.login(cc.fx.GameConfig.GM_INFO.openid); API._ta.login(cc.fx.GameConfig.GM_INFO.openid);
cc.fx.GameConfig.GM_INFO.shushu_AccountId = cc.fx.GameConfig.GM_INFO.openid; cc.fx.GameConfig.GM_INFO.shushu_AccountId = cc.fx.GameConfig.GM_INFO.openid;
const result = "success"; const result = "success";
@ -1170,14 +1170,6 @@ export namespace MiniGameSdk {
} }
} }
static updateCoinAndLevel() {
if (typeof wx !== 'undefined' && wx !== null) {
console.log("上传金币和关卡信息给数数")
API._ta.userSet({ current_level: cc.fx.GameConfig.GM_INFO.level });
API._ta.userSet({ current_coin: cc.fx.GameConfig.GM_INFO.coin });
}
}
/* /*
* *
*/ */
@ -1191,17 +1183,16 @@ export namespace MiniGameSdk {
tmp_coin: cc.fx.GameConfig.GM_INFO.coin,//当前金币 tmp_coin: cc.fx.GameConfig.GM_INFO.coin,//当前金币
version: cc.fx.GameConfig.GM_INFO.version.toString(),//当前版本号 version: cc.fx.GameConfig.GM_INFO.version.toString(),//当前版本号
}; };
if (register_time != null) { if(register_time != null){
superProperties = { superProperties = {
current_level: (cc.fx.GameConfig.GM_INFO.level + 1), //当前关卡等级 number current_level: (cc.fx.GameConfig.GM_INFO.level + 1), //当前关卡等级 number
current_health: cc.fx.GameConfig.GM_INFO.hp, //当前体力值 current_health: cc.fx.GameConfig.GM_INFO.hp, //当前体力值
tmp_coin: cc.fx.GameConfig.GM_INFO.coin,//当前金币 tmp_coin: cc.fx.GameConfig.GM_INFO.coin,//当前金币
version: cc.fx.GameConfig.GM_INFO.version.toString(), version: cc.fx.GameConfig.GM_INFO.version.toString(),
register_time: register_time register_time:register_time
}; };
} }
API._ta.setSuperProperties(superProperties);//设置公共事件属性 API._ta.setSuperProperties(superProperties);//设置公共事件属性
API.updateCoinAndLevel();
} }
} }
@ -1258,7 +1249,7 @@ export namespace MiniGameSdk {
} }
//#region 引力平台- //#region 引力平台-
static yinli_Init() { static yinli_Init(){
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx !== 'undefined' && wx !== null) {
const configYinli = { const configYinli = {
accessToken: "aGws0nluotbm6Jjiv9WMuzOAbXLydxwe", // 项目通行证,在:网站后台-->设置-->应用列表中找到Access Token列 复制(首次使用可能需要先新增应用) accessToken: "aGws0nluotbm6Jjiv9WMuzOAbXLydxwe", // 项目通行证,在:网站后台-->设置-->应用列表中找到Access Token列 复制(首次使用可能需要先新增应用)
@ -1277,9 +1268,9 @@ export namespace MiniGameSdk {
}, },
}; };
API._ge = new GravityAnalyticsAPI(configYinli); API._ge = new GravityAnalyticsAPI(configYinli);
API._ge.setupAndStart(); API._ge .setupAndStart();
API._ge.initialize({ API._ge .initialize({
name: cc.fx.GameConfig.GM_INFO.openid, name: cc.fx.GameConfig.GM_INFO.openid,
version: cc.fx.GameConfig.GM_INFO.version, version: cc.fx.GameConfig.GM_INFO.version,
openid: cc.fx.GameConfig.GM_INFO.openid, openid: cc.fx.GameConfig.GM_INFO.openid,
@ -1292,7 +1283,7 @@ export namespace MiniGameSdk {
console.log("引力引擎初始化失败 " + err); console.log("引力引擎初始化失败 " + err);
}); });
if (cc.fx.GameConfig.GM_INFO.shushu_AccountId == "") cc.fx.GameConfig.GM_INFO.shushu_AccountId = if(cc.fx.GameConfig.GM_INFO.shushu_AccountId == "") cc.fx.GameConfig.GM_INFO.shushu_AccountId =
cc.fx.GameConfig.GM_INFO.openid; cc.fx.GameConfig.GM_INFO.openid;
const CURRENT_USER_TA_ACCOUNT_ID = cc.fx.GameConfig.GM_INFO.shushu_AccountId; // 用户唯一标识如产品为小游戏则必须填用户openid注意不是小游戏的APPID const CURRENT_USER_TA_ACCOUNT_ID = cc.fx.GameConfig.GM_INFO.shushu_AccountId; // 用户唯一标识如产品为小游戏则必须填用户openid注意不是小游戏的APPID
@ -1302,8 +1293,8 @@ export namespace MiniGameSdk {
} }
} }
static yinli_Register() { static yinli_Register(){
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
API._ge.registerEvent(); API._ge.registerEvent();
} }
} }
@ -1316,14 +1307,14 @@ export namespace MiniGameSdk {
* @param payReason * @param payReason
* @param payMethod * @param payMethod
*/ */
static yinli_Pay(payAmount, orderId, payReason) { static yinli_Pay(payAmount,orderId,payReason){
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
API._ge.payEvent(payAmount, "CNY", orderId, payReason, "微信"); API._ge.payEvent(payAmount, "CNY", orderId, payReason, "微信");
} }
} }
static yinli_Login() { static yinli_Login(){
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
API._ge.loginEvent(); API._ge.loginEvent();
} }
} }

View File

@ -6,7 +6,7 @@ const { ccclass, property } = cc._decorator;
@ccclass('GameConfig') @ccclass('GameConfig')
export class GameConfig { export class GameConfig {
//所有控制信息都通过GameAppStart内控制 //所有控制信息都通过GameAppStart内控制
private static _instance: GameConfig = null; private static _instance : GameConfig = null;
static GAME_DATA: any[]; static GAME_DATA: any[];
//关卡数据 //关卡数据
@ -61,8 +61,6 @@ export class GameConfig {
mean_Time: number; //平均放箭速度 mean_Time: number; //平均放箭速度
hp: number; //体力值 hp: number; //体力值
review: number; //复活次数 review: number; //复活次数
reviewBoom: number; //炸弹复活次数
reviewDoor: number; //门复活次数
currSeed: number; //用于随机数种子 currSeed: number; //用于随机数种子
openid: string; //微信用户唯一id openid: string; //微信用户唯一id
gameId: string; //游戏ID gameId: string; //游戏ID
@ -94,21 +92,23 @@ export class GameConfig {
coinnum: number; //每局的金币数 coinnum: number; //每局的金币数
paid_user: boolean; //是否是付费用户 paid_user: boolean; //是否是付费用户
version: number; //版本号 version: number; //版本号
shushu_DistinctId: string; //数数访客ID shushu_DistinctId: string //数数访客ID
shushu_AccountId: string; //数数账号ID shushu_AccountId: string //数数账号ID
}; };
//游戏内信息 //游戏内信息
static get Instance() { static get Instance()
if (this._instance == null) { {
if (this._instance == null)
{
this._instance = new GameConfig(); this._instance = new GameConfig();
} }
return this._instance; return this._instance;
} }
//getSeedRandom //getSeedRandom
static init(Authentication) { static init(Authentication){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx !== 'undefined' && wx !== null) {
//@ts-ignore //@ts-ignore
@ -120,7 +120,7 @@ export class GameConfig {
this.TA = null; this.TA = null;
this.CLICK_init(); this.CLICK_init();
this.GM_INFO_init(); this.GM_INFO_init();
this.LEVEL_INFO_init(false, 0); this.LEVEL_INFO_init(false,0);
var self = this; var self = this;
//GAME_DATA 废弃了,暂时不删除以防后面修改回 一整局传一次 //GAME_DATA 废弃了,暂时不删除以防后面修改回 一整局传一次
@ -134,7 +134,7 @@ export class GameConfig {
static generateUUID(): string { static generateUUID(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0; const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8); const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);
@ -160,7 +160,7 @@ export class GameConfig {
return 0; return 0;
} }
static GM_INFO_SET(key, value) { static GM_INFO_SET(key,value) {
this.GM_INFO[key] = value; this.GM_INFO[key] = value;
} }
static CLICK_init() { static CLICK_init() {
@ -176,17 +176,17 @@ export class GameConfig {
optimizedSteps: 0, //关卡最短步数 optimizedSteps: 0, //关卡最短步数
usedSteps: 0, //玩家修建总步数 usedSteps: 0, //玩家修建总步数
stepList: [], //U、D、L、R X 息壤 F 加固 stepList: [], //U、D、L、R X 息壤 F 加固
startTime: -1, //从游戏开始到玩家操作的第一步截止时间 单位毫秒 startTime:-1, //从游戏开始到玩家操作的第一步截止时间 单位毫秒
submitTime: -1, //从第一步操作到提交时间,如果未提交为-1 单位毫秒 submitTime:-1, //从第一步操作到提交时间,如果未提交为-1 单位毫秒
duration: 0, //游戏总用时(截止到提交) 单位毫秒 如果未他移交则为时间上限 duration:0, //游戏总用时(截止到提交) 单位毫秒 如果未他移交则为时间上限
drawingBack: 0, //后退次数 drawingBack:0, //后退次数
drawingReset: 0, //清空次数 drawingReset:0, //清空次数
timer: 0 //测评倒计时剩余时间 去秒 timer: 0 //测评倒计时剩余时间 去秒
} }
} }
static CLICK_SET(key, value) { static CLICK_SET(key,value) {
this.CLICK_DATA[key] = value; this.CLICK_DATA[key] = value;
} }
@ -196,35 +196,33 @@ export class GameConfig {
// isEnd: false, // isEnd: false,
mean_Time: 0, //平均放箭速度 mean_Time: 0, //平均放箭速度
hp: 5, //体力值 hp: 5, //体力值
review: 0, //复活次数 review:0, //复活次数
reviewBoom: 0, //炸弹复活次数
reviewDoor: 0, //门复活次数
currSeed: 200000, //用于随机数种子 currSeed: 200000, //用于随机数种子
openid: "", //微信用户唯一id openid:"", //微信用户唯一id
gameId: "100001", //游戏ID gameId: "100001", //游戏ID
userId: 0, //用户ID userId: 0, //用户ID
scode: "", //用户code,从网页后缀获取 scode: "", //用户code,从网页后缀获取
username: "user", //用户名称 username:"user", //用户名称
useravatar: "", //用户头像地址 useravatar:"", //用户头像地址
guide: true, //是否有引导 guide: true, //是否有引导
url: "https://api.sparkus.cn",//访问域名 url: "https://api.sparkus.cn",//访问域名
coin: 0, //用户金币 coin: 0, //用户金币
success: false, //用户游戏成功与否 success: false, //用户游戏成功与否
matchId: null, //用于埋点上传的ID matchId: null, //用于埋点上传的ID
gameState: false, gameState:false,
custom: 0, //用于测试跳关卡 custom: 0, //用于测试跳关卡
round: 0, //回合数 round:0, //回合数
level: 0, //具体游戏内进行到第几步 level: 0, //具体游戏内进行到第几步
stepTimeList: 0, //整局游戏用时,由于涉及场景切换,数据需要保留 stepTimeList:0, //整局游戏用时,由于涉及场景切换,数据需要保留
successList: [], //整局胜负 successList:[], //整局胜负
first: false, //是否首次进入游戏 first:false, //是否首次进入游戏
score: 0, //总得分 score:0, //总得分
scale: 1, //玩家总计成功点火数 scale: 1, //玩家总计成功点火数
iosOutTradeNo: 0, //ios订单号 iosOutTradeNo:0, //ios订单号
min_Time: 0, //体力恢复的剩余时间 min_Time:0, //体力恢复的剩余时间
freezeAmount: 0, //冻结道具次数 freezeAmount:0, //冻结道具次数
hammerAmount: 0, //锤子道具次数 hammerAmount:0, //锤子道具次数
magicAmount: 0, //魔法棒道具次数 magicAmount:0, //魔法棒道具次数
musicOpen: true, //音乐 musicOpen: true, //音乐
effectOpen: true, //音效 effectOpen: true, //音效
vibrateOpen: true, //震动 vibrateOpen: true, //震动
@ -251,7 +249,7 @@ export class GameConfig {
} }
static LEVEL_INFO_init(type, time) { static LEVEL_INFO_init(type,time) {
// 示例 围墙会根据缺的地块自动生成 // 示例 围墙会根据缺的地块自动生成
// 带缺口 {"id":"1006","map":[10,11],"gap":[cc.v2(4,9),cc.v2(5,9)]}, // 带缺口 {"id":"1006","map":[10,11],"gap":[cc.v2(4,9),cc.v2(5,9)]},
// 带升降地块 {"id":"1004","map":[7,8],"risefall":[{pos:cc.v2(5,4),color:2},{pos:cc.v2(5,5),color:5}]}, // 带升降地块 {"id":"1004","map":[7,8],"risefall":[{pos:cc.v2(5,4),color:2},{pos:cc.v2(5,5),color:5}]},
@ -259,18 +257,18 @@ export class GameConfig {
var self = this; var self = this;
if ((cc.fx.GameConfig.GM_INFO.level) > 249) { if((cc.fx.GameConfig.GM_INFO.level) > 249){
cc.fx.GameConfig.GM_INFO.level = 249; cc.fx.GameConfig.GM_INFO.level = 249;
} }
let name = "Json/level" + (cc.fx.GameConfig.GM_INFO.level + 1); let name = "Json/level" + (cc.fx.GameConfig.GM_INFO.level+1);
// //console.log("关卡名称:",name); // //console.log("关卡名称:",name);
// name = "Json/level" + 68; // name = "Json/level" + 68;
// cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString()); // cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString());
cc.resources.load(name, (err: any, res: cc.JsonAsset) => { cc.resources.load(name, (err: any, res: cc.JsonAsset) => {
if (err) { if (err) {
cc.fx.GameTool.addLevel(null, null); cc.fx.GameTool.addLevel(null,null);
self.LEVEL_INFO_init(type, time); self.LEVEL_INFO_init(type,time);
return; return;
} }
let jsonData: object = res.json!; let jsonData: object = res.json!;
@ -278,10 +276,10 @@ export class GameConfig {
self.LEVEL_INFO = jsonData["LEVEL_INFO"]; self.LEVEL_INFO = jsonData["LEVEL_INFO"];
self.WALL_INFO = jsonData["WALL_INFO"]; self.WALL_INFO = jsonData["WALL_INFO"];
// //console.log("配置加载完成"); // //console.log("配置加载完成");
if (type) { if(type){
cc.director.preloadScene("GameScene", () => { cc.director.preloadScene("GameScene", ()=>{
if (time == 0) cc.director.loadScene("GameScene"); if(time == 0) cc.director.loadScene("GameScene");
else { else{
setTimeout(() => { setTimeout(() => {
cc.director.loadScene("GameScene"); cc.director.loadScene("GameScene");
}, time); }, time);
@ -484,11 +482,11 @@ export class GameConfig {
static setCode(code) { static setCode(code){
this.GM_INFO.scode = code; this.GM_INFO.scode = code;
} }
static getKey(key) { static getKey(key){
// var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i'); // var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i');
// var r = window.location.search.substring(1).match(reg); // var r = window.location.search.substring(1).match(reg);
// if (r != null) { // if (r != null) {
@ -498,7 +496,7 @@ export class GameConfig {
} }
static Authentication() { static Authentication(){
cc.fx.GameTool.Authentication(); cc.fx.GameTool.Authentication();
} }
} }

View File

@ -10,18 +10,18 @@ var GameTool = {
_totalTime: 0, _totalTime: 0,
//获取userId //获取userId
Authentication() { Authentication(){
let name = "user_" + cc.fx.GameConfig.GM_INFO.gameId; let name = "user_" + cc.fx.GameConfig.GM_INFO.gameId;
var data = JSON.parse(localStorage.getItem(name)); var data = JSON.parse(localStorage.getItem(name));
if (data == "undifend" || data == null || data == "") { if(data == "undifend" || data==null || data == ""){
var urlNow = window.location.href; var urlNow = window.location.href;
if (!this.containsTrain(urlNow)) { if(!this.containsTrain(urlNow)){
let url = "https://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback=" + location.href; let url = "https://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback="+location.href;
window.location.href = url; window.location.href = url;
} }
} }
else { else{
cc.fx.StorageMessage.setStorage(name, data); cc.fx.StorageMessage.setStorage(name,data);
cc.fx.GameConfig.GM_INFO.userId = parseInt(data.userId); cc.fx.GameConfig.GM_INFO.userId = parseInt(data.userId);
} }
}, },
@ -31,7 +31,7 @@ var GameTool = {
}, },
//埋点上传 //埋点上传
setGameData() { setGameData(){
//GAME_DATA 初始化 每次清零 //GAME_DATA 初始化 每次清零
cc.fx.GameConfig.GAME_DATA = []; cc.fx.GameConfig.GAME_DATA = [];
cc.fx.GameConfig.GAME_DATA.push(cc.fx.GameConfig.CLICK_DATA); cc.fx.GameConfig.GAME_DATA.push(cc.fx.GameConfig.CLICK_DATA);
@ -39,10 +39,10 @@ var GameTool = {
let data = cc.fx.GameConfig.GAME_DATA; let data = cc.fx.GameConfig.GAME_DATA;
let matchId = this.getMatchId(); let matchId = this.getMatchId();
let postData = { let postData = {
"gameId": cc.fx.GameConfig.GM_INFO.gameId, "gameId":cc.fx.GameConfig.GM_INFO.gameId,
"userId": cc.fx.GameConfig.GM_INFO.userId, "userId":cc.fx.GameConfig.GM_INFO.userId,
"scode": cc.fx.GameConfig.GM_INFO.scode, "scode": cc.fx.GameConfig.GM_INFO.scode,
"matchId": matchId, "matchId":matchId,
"data": data "data": data
}; };
@ -50,12 +50,12 @@ var GameTool = {
// cc.fx.HttpUtil.uploadUserLogData(postData,function(){}) // cc.fx.HttpUtil.uploadUserLogData(postData,function(){})
}, },
//上传排行榜 type为1 //上传排行榜 type为1
setRank(data) { setRank(data){
//GAME_DATA 初始化 每次清零 //GAME_DATA 初始化 每次清零
let postData = { let postData = {
"gameId": cc.fx.GameConfig.GM_INFO.gameId, "gameId":cc.fx.GameConfig.GM_INFO.gameId,
"userId": cc.fx.GameConfig.GM_INFO.userId, "userId":cc.fx.GameConfig.GM_INFO.userId,
"type": 1, "type":1,
"score": data.score, "score": data.score,
"accuracy": data.date, "accuracy": data.date,
"success": cc.fx.GameConfig.GM_INFO.success "success": cc.fx.GameConfig.GM_INFO.success
@ -63,41 +63,41 @@ var GameTool = {
// cc.fx.HttpUtil.rankData(1,function(){},postData); // cc.fx.HttpUtil.rankData(1,function(){},postData);
}, },
//获取排行榜 type为2 //获取排行榜 type为2
getRank(data, callback) { getRank(data,callback){
let rankLength = data.length; let rankLength = data.length;
let postData = { let postData = {
"gameId": cc.fx.GameConfig.GM_INFO.gameId, "gameId":cc.fx.GameConfig.GM_INFO.gameId,
"userId": cc.fx.GameConfig.GM_INFO.userId, "userId":cc.fx.GameConfig.GM_INFO.userId,
"page": 1, "page":1,
"pageSize": rankLength "pageSize":rankLength
}; };
//回调进getRankData //回调进getRankData
// cc.fx.HttpUtil.rankData(2,data =>{callback(data)},postData); // cc.fx.HttpUtil.rankData(2,data =>{callback(data)},postData);
}, },
//获取matchId 用于上传每次点击数据里面记录id方便查询 //获取matchId 用于上传每次点击数据里面记录id方便查询
getMatchId() { getMatchId (){
let matchId = cc.sys.localStorage.getItem("matchId"); let matchId = cc.sys.localStorage.getItem("matchId");
let tempId = matchId; let tempId = matchId;
if (matchId == "undifend" || matchId == null) { if(matchId == "undifend" || matchId==null){
matchId = this.setMatchId(); matchId = this.setMatchId();
} }
else { else{
if (this.containsNanana(matchId) == true) { if(this.containsNanana(matchId) == true){
matchId = this.setMatchId(); matchId = this.setMatchId();
} }
else { else{
let char = parseInt(tempId.substring(10, tempId.length)); let char = parseInt(tempId.substring(10,tempId.length));
if (cc.fx.GameConfig.GM_INFO.level == 1) { if(cc.fx.GameConfig.GM_INFO.level == 1){
char += 1; char += 1;
matchId = tempId.slice(0, 10) + char + ""; matchId = tempId.slice(0, 10) + char + "";
if (this.containsNanana(matchId)) matchId = this.setMatchId(); if(this.containsNanana(matchId)) matchId = this.setMatchId();
cc.fx.GameConfig.GM_INFO.matchId = matchId; cc.fx.GameConfig.GM_INFO.matchId = matchId;
cc.sys.localStorage.setItem("matchId", matchId); cc.sys.localStorage.setItem("matchId",matchId);
} }
} }
} }
if (this.containsNanana(matchId) == true) { if(this.containsNanana(matchId) == true){
matchId = this.setMatchId(); matchId = this.setMatchId();
} }
return matchId; return matchId;
@ -107,7 +107,7 @@ var GameTool = {
return /na/i.test(str); return /na/i.test(str);
}, },
//重新设置MatchId //重新设置MatchId
setMatchId() { setMatchId (){
// 定义包含可用字符的字符集 // 定义包含可用字符的字符集
const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
// 创建一个数组以保存随机字符 // 创建一个数组以保存随机字符
@ -122,20 +122,20 @@ var GameTool = {
uuidArray.push(randomChar); uuidArray.push(randomChar);
} }
let data = uuidArray.join('') + 1 + ""; let data = uuidArray.join('') + 1 + "";
cc.sys.localStorage.setItem("matchNumber", 1); cc.sys.localStorage.setItem("matchNumber",1);
cc.sys.localStorage.setItem("matchId", data); cc.sys.localStorage.setItem("matchId",data);
cc.fx.GameConfig.GM_INFO.matchId = data; cc.fx.GameConfig.GM_INFO.matchId = data;
return data; return data;
}, },
//截取名字 //截取名字
subName(name, length) { subName(name,length){
if (name.length > length) { if(name.length > length){
name = name.substring(0, length) + "..." name = name.substring(0,length) + "..."
} }
return name; return name;
}, },
//设置头像 //设置头像
setPic(node, pic) { setPic(node,pic){
node.active = false; node.active = false;
let url = pic; let url = pic;
setTimeout(() => { setTimeout(() => {
@ -144,7 +144,7 @@ var GameTool = {
return response.headers.get('Content-Length'); return response.headers.get('Content-Length');
}) })
.then(errNo => { .then(errNo => {
if (errNo == "5093") { if(errNo == "5093"){
node.active = true; node.active = true;
} }
}) })
@ -152,42 +152,42 @@ var GameTool = {
// console.error('Error fetching X-Info:', error); // console.error('Error fetching X-Info:', error);
}); });
}, 100); }, 100);
cc.assetManager.loadRemote(url, { ext: '.png' }, (err, texture: cc.Texture2D) => { cc.assetManager.loadRemote(url, {ext:'.png'},(err, texture:cc.Texture2D) => {
if (texture) { if(texture){
node.active = true; node.active = true;
node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture); node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
} }
else { else{
// console.log(err,texture) // console.log(err,texture)
} }
}) })
}, },
//第一个参数把目标带进来处理,第二个参数为名字长度,不同场景不同需求 //第一个参数把目标带进来处理,第二个参数为名字长度,不同场景不同需求
//名字4短小排行名字6长大排行 //名字4短小排行名字6长大排行
getRankData(data, target, nameLength) { getRankData(data,target,nameLength){
target.listData = data.data.list; target.listData = data.data.list;
target.selfData = data.data.info; target.selfData = data.data.info;
let rankData = []; let rankData = [];
let self = false; let self = false;
cc.fx.GameTool.setPic(target.selfNode.getChildByName("pic").getChildByName("icon"), target.selfData.pic); cc.fx.GameTool.setPic(target.selfNode.getChildByName("pic").getChildByName("icon"),target.selfData.pic);
for (let i = 0; i <= target.listData.length - 1; i++) { for(let i=0;i<=target.listData.length-1;i++){
rankData.push({ rank: (i + 1), name: target.listData[i].nickName, total: target.listData[i].score, time: null, pic: target.listData[i].pic }); rankData.push({rank:(i+1), name:target.listData[i].nickName, total:target.listData[i].score,time:null, pic:target.listData[i].pic});
if (cc.fx.GameConfig.GM_INFO.userId == target.listData[i].userId) { if(cc.fx.GameConfig.GM_INFO.userId == target.listData[i].userId){
self = true; self = true;
target.rankNumber = i; target.rankNumber = i;
target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string = (i + 1) + ""; target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string =(i+1) + "";
} }
if (i == (target.listData.length - 1) && self == false) { if(i == (target.listData.length-1) && self == false){
target.rankNumber = i; target.rankNumber = i;
target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string = "99+"; target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string = "99+";
} }
} }
target.selfData.nickName = cc.fx.GameTool.subName(target.selfData.nickName, nameLength); target.selfData.nickName = cc.fx.GameTool.subName(target.selfData.nickName,nameLength);
target.selfNode.getChildByName("nameLab").getComponent(cc.Label).string = target.selfData.nickName; target.selfNode.getChildByName("nameLab").getComponent(cc.Label).string = target.selfData.nickName;
target.selfNode.getChildByName("totalLab").getComponent(cc.Label).string = target.selfData.score; target.selfNode.getChildByName("totalLab").getComponent(cc.Label).string = target.selfData.score;
let timeTemp = cc.fx.GameTool.getTimeShenNong(target.selfData.totleTimes); let timeTemp = cc.fx.GameTool.getTimeShenNong(target.selfData.totleTimes);
// target.selfNode.getChildByName("timeLab").getComponent(cc.Label).string = timeTemp + ""; // target.selfNode.getChildByName("timeLab").getComponent(cc.Label).string = timeTemp + "";
switch (target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string) { switch(target.selfNode.getChildByName("rankLab").getComponent(cc.Label).string){
case "1": case "1":
target.selfNode.getChildByName("rank").getChildByName("one").active = true; target.selfNode.getChildByName("rank").getChildByName("one").active = true;
break; break;
@ -199,10 +199,10 @@ var GameTool = {
break; break;
} }
// 大排行 // 大排行
if (nameLength == 6) { if(nameLength == 6){
target.rankList.setData(rankData); target.rankList.setData(rankData);
target.selfNode.opacity = 255; target.selfNode.opacity = 255;
if (target.selfData.totalSunCount == 0) target.selfNode.opacity = 0; if(target.selfData.totalSunCount == 0) target.selfNode.opacity = 0;
} }
}, },
@ -216,33 +216,33 @@ var GameTool = {
return parseInt(tmp); return parseInt(tmp);
}, },
//获取关卡配置的那个关卡数 //获取关卡配置的那个关卡数
getCustom(type) { getCustom(type){
let custom = cc.fx.StorageMessage.getStorage(cc.fx.storageType.storageTypeCustom); let custom = cc.fx.StorageMessage.getStorage(cc.fx.storageType.storageTypeCustom);
if (custom == "undifend" || custom == null || custom == "") { if(custom == "undifend" || custom==null || custom == ""){
this.setCustom(); this.setCustom();
} }
else { else{
cc.fx.GameConfig.GM_INFO_SET("custom", custom[0]); cc.fx.GameConfig.GM_INFO_SET("custom",custom[0]);
if (custom[0] != 0 || type == true) { if(custom[0] != 0 || type == true){
custom.shift(); custom.shift();
if (custom.length == 0) { if(custom.length == 0){
this.setCustom(); this.setCustom();
} }
else cc.fx.StorageMessage.setStorage(cc.fx.storageType.storageTypeCustom, custom); else cc.fx.StorageMessage.setStorage(cc.fx.storageType.storageTypeCustom,custom);
} }
} }
}, },
//本地没有存储到配置,或者配置用完,重新创建配置 //本地没有存储到配置,或者配置用完,重新创建配置
setCustom() { setCustom(){
let arrayLength = cc.fx.GameConfig.LEVEL_INFO.length; let arrayLength = cc.fx.GameConfig.LEVEL_INFO.length;
let arrayList = []; let arrayList = [];
for (let i = 1; i < arrayLength; i++) { for(let i=1; i<arrayLength;i++){
arrayList.push(i); arrayList.push(i);
} }
arrayList.sort(() => Math.random() - 0.5); arrayList.sort(() => Math.random() - 0.5);
arrayList.unshift(0) arrayList.unshift(0)
cc.fx.GameConfig.GM_INFO_SET("custom", arrayList[0]); cc.fx.GameConfig.GM_INFO_SET("custom",arrayList[0]);
cc.fx.StorageMessage.setStorage(cc.fx.storageType.storageTypeCustom, arrayList); cc.fx.StorageMessage.setStorage(cc.fx.storageType.storageTypeCustom,arrayList);
}, },
@ -264,23 +264,23 @@ var GameTool = {
return flag; return flag;
}, },
//获取游戏信息 //获取游戏信息
getGameInfo: function (node) { getGameInfo: function(node){
var jg = false; var jg = false;
return jg; return jg;
}, },
//设置游戏信息 //设置游戏信息
setGameInfo: function (pd) { setGameInfo: function(pd){
}, },
//打字机效果 //打字机效果
typingAni(label, text, cb, target) { typingAni(label,text,cb,target){
var self = target; var self = target;
var html = ''; var html = '';
var arr = text.split(''); var arr = text.split('');
var len = arr.length; var len = arr.length;
var step = 0; var step = 0;
self.func = () => { self.func = ()=>{
html += arr[step]; html += arr[step];
label.string = html; label.string = html;
if (++step == len) { if (++step == len) {
@ -288,33 +288,33 @@ var GameTool = {
cb && cb(); cb && cb();
} }
} }
self.schedule(self.func, 0.1, cc.macro.REPEAT_FOREVER, 0) self.schedule(self.func,0.1, cc.macro.REPEAT_FOREVER, 0)
}, },
//输入秒,返回需要展示时间格式 //输入秒,返回需要展示时间格式
getTimeMargin: (second) => { getTimeMargin:(second) => {
let total = 0; let total = 0;
total = second; total = second;
let hour = 0; let hour = 0;
hour = parseInt((total / 3600) + "");//计算整数小时数 hour = parseInt((total / 3600) + "");//计算整数小时数
let afterHour = total - hour * 60 * 60;//取得算出小时数后剩余的秒数 let afterHour = total - hour * 60 * 60;//取得算出小时数后剩余的秒数
let min = parseInt((afterHour / 60) + "");//计算整数分 let min = parseInt((afterHour / 60)+"");//计算整数分
let m = "" + min; let m = "" + min;
if (min < 10) m = "0" + min; if(min < 10) m = "0"+min;
let afterMin = total - hour * 60 * 60 - min * 60;//取得算出分后剩余的秒数 let afterMin = total - hour * 60 * 60 - min * 60;//取得算出分后剩余的秒数
let miao = afterMin + ""; let miao = afterMin + "";
if (afterMin < 10) miao = "0" + afterMin; if(afterMin < 10) miao = "0" + afterMin;
return m + ':' + miao return m + ':' + miao
}, },
//输入秒,返回需要展示时间格式 //输入秒,返回需要展示时间格式
getTimeShenNong: (second) => { getTimeShenNong:(second) => {
second = parseInt(second / 1000 + ""); second = parseInt(second/1000+"");
let total = 0; let total = 0;
total = second; total = second;
let min = 0; let min = 0;
if (total > 60) { if(total > 60){
min = parseInt((total / 60) + "");//计算整数分 min = parseInt((total / 60)+"");//计算整数分
} }
let m = min + "'"; let m = min + "'";
@ -334,30 +334,30 @@ var GameTool = {
//增加关卡数 //增加关卡数
addLevel(time1, time2) { addLevel(time1,time2){
cc.fx.GameConfig.GM_INFO.level += 1; cc.fx.GameConfig.GM_INFO.level += 1;
if (cc.fx.GameConfig.GM_INFO.level > 249) { if(cc.fx.GameConfig.GM_INFO.level > 249){
cc.fx.GameConfig.GM_INFO.level = 249; cc.fx.GameConfig.GM_INFO.level = 249;
} }
const timestamp = Date.now(); const timestamp = Date.now();
let levelInfo = { let levelInfo = {
level: cc.fx.GameConfig.GM_INFO.level, level:cc.fx.GameConfig.GM_INFO.level,
timestamp: timestamp, timestamp:timestamp,
} }
console.log("55555存储关卡数据:", time1, time2); console.log("55555存储关卡数据:",time1,time2);
cc.fx.StorageMessage.setStorage("level", levelInfo); cc.fx.StorageMessage.setStorage("level",levelInfo);
if (time1 != null && time2 != null) { if(time1!=null && time2!=null){
let data = { let data = {
time: time1, time:time1,
add_Time: time2, add_Time:time2,
result: "success" result:"success"
} }
cc.fx.GameTool.shushu_Track("finish_stage", data); cc.fx.GameTool.shushu_Track("finish_stage",data);
MiniGameSdk.API.shushu_SetSuperProperties(null); MiniGameSdk.API.shushu_SetSuperProperties(null);
} }
cc.fx.GameTool.setUserLevel((data) => { cc.fx.GameTool.setUserLevel((data)=>{
// console.log("存储结果:",data); // console.log("存储结果:",data);
// console.log("上传",data); // console.log("上传",data);
}) })
@ -372,11 +372,11 @@ var GameTool = {
return; return;
} }
cc.fx.GameConfig.GM_INFO.coin += coin; cc.fx.GameConfig.GM_INFO.coin += coin;
if (coin > 0) { if(coin > 0){
// let data = "获得" + (coin) + "金币"; // let data = "获得" + (coin) + "金币";
// MiniGameSdk.API.showToast(data); // MiniGameSdk.API.showToast(data);
} }
else { else{
let data = "消耗" + (-coin) + "金币"; let data = "消耗" + (-coin) + "金币";
MiniGameSdk.API.showToast(data); MiniGameSdk.API.showToast(data);
} }
@ -397,11 +397,11 @@ var GameTool = {
// console.log("上传",data); // console.log("上传",data);
}) })
}, },
//@ts-ignore //@ts-ignore
//获取用户金币数量 //获取用户金币数量
getUserCoin(callback: Function) { getUserCoin(callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'userCoin', name: 'userCoin',
@ -410,7 +410,7 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log('读取用户金币数据成功', res.result) // console.log('读取用户金币数据成功', res.result)
if (callback) if(callback)
callback(res); callback(res);
}, },
@ -423,15 +423,15 @@ var GameTool = {
}, },
//改变用户金币 //改变用户金币
setUserCoin(callback) { setUserCoin(callback){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
if (cc.fx.GameConfig.GM_INFO.coin <= 0 || cc.fx.GameConfig.GM_INFO.coin == undefined) { if(cc.fx.GameConfig.GM_INFO.coin <= 0 || cc.fx.GameConfig.GM_INFO.coin == undefined){
console.log("金币上传失败", cc.fx.GameConfig.GM_INFO.coin); console.log("金币上传失败",cc.fx.GameConfig.GM_INFO.coin);
// MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.coin); // MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.coin);
cc.fx.GameConfig.GM_INFO.coin = 0; cc.fx.GameConfig.GM_INFO.coin = 0;
} }
console.log("即将上传的金币数量:", cc.fx.GameConfig.GM_INFO.coin); console.log("即将上传的金币数量:",cc.fx.GameConfig.GM_INFO.coin);
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'userCoin', name: 'userCoin',
@ -441,17 +441,17 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log('云函数返回结果:', res); // console.log('云函数返回结果:', res);
if (res.result.code == 200) { if(res.result.code == 200){
// console.log('存储金币数据成功',cc.fx.GameConfig.GM_INFO.coin); // console.log('存储金币数据成功',cc.fx.GameConfig.GM_INFO.coin);
} }
if (callback) { if(callback){
callback(res); callback(res);
} }
}, },
fail: err => { fail: err => {
// console.log('存储金币数据失败') // console.log('存储金币数据失败')
if (callback) { if(callback){
callback(err); callback(err);
} }
console.error('存储用户数据失败', err) console.error('存储用户数据失败', err)
@ -464,7 +464,7 @@ var GameTool = {
//获取用户关卡数 //获取用户关卡数
getUserLevel(callback: Function) { getUserLevel(callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'userLevel', name: 'userLevel',
@ -472,7 +472,7 @@ var GameTool = {
action: 'read' action: 'read'
}, },
success: res => { success: res => {
if (callback) if(callback)
callback(res); callback(res);
}, },
@ -485,48 +485,48 @@ var GameTool = {
}, },
//进游戏处理 体力值情况 //进游戏处理 体力值情况
getHealth(callback: Function) { getHealth(callback: Function){
let health = cc.fx.StorageMessage.getStorage("health"); let health = cc.fx.StorageMessage.getStorage("health");
const timestamp = Date.now(); const timestamp = Date.now();
cc.fx.GameConfig.GM_INFO.hp = 5; cc.fx.GameConfig.GM_INFO.hp = 5;
//没有存储过体力值 //没有存储过体力值
if (health == null || health == undefined || health == "") { if(health == null || health == undefined || health == ""){
console.log("没存储过体力值,初进"); console.log("没存储过体力值,初进");
cc.fx.GameConfig.GM_INFO.hp = 5; cc.fx.GameConfig.GM_INFO.hp = 5;
cc.fx.GameTool.getUserHealth((data) => { cc.fx.GameTool.getUserHealth((data)=>{
console.log("体力接口返回结果", data); console.log("体力接口返回结果",data);
if (data.result.code == 200) { if(data.result.code == 200){
cc.fx.GameConfig.GM_INFO.hp = data.result.data; cc.fx.GameConfig.GM_INFO.hp = data.result.data;
cc.fx.GameConfig.GM_INFO.min_Time = data.result.timestamp; cc.fx.GameConfig.GM_INFO.min_Time = data.result.timestamp;
let healthInfo = { let healthInfo = {
"health": cc.fx.GameConfig.GM_INFO.hp, "health":cc.fx.GameConfig.GM_INFO.hp,
"timestamp": data.result.timestamp "timestamp":data.result.timestamp
} }
MiniGameSdk.API.shushu_SetSuperProperties(null); MiniGameSdk.API.shushu_SetSuperProperties(null);
cc.fx.StorageMessage.setStorage("health", healthInfo); cc.fx.StorageMessage.setStorage("health",healthInfo);
} }
else if (data.result.code == 404 && data.result.message == "未找到体力数据") { else if(data.result.code == 404 && data.result.message == "未找到体力数据"){
cc.fx.GameTool.setUserHealth(0, () => { cc.fx.GameTool.setUserHealth(0,()=>{
}); });
} }
if (callback) callback(); if(callback) callback();
}) })
} }
else { else{
console.log("有存储过体力值:", health); console.log("有存储过体力值:",health);
cc.fx.GameConfig.GM_INFO.hp = health.health; cc.fx.GameConfig.GM_INFO.hp = health.health;
if (callback) { if(callback){
console.log("体力值读取完毕"); console.log("体力值读取完毕");
callback(); callback();
} }
if (health.health < 0) { if(health.health < 0){
console.log("体力值异常,归零"); console.log("体力值异常,归零");
cc.fx.GameConfig.GM_INFO.hp = 0; cc.fx.GameConfig.GM_INFO.hp = 0;
cc.fx.GameTool.setUserHealth(0, () => { cc.fx.GameTool.setUserHealth(0,()=>{
if (callback) callback(); if(callback) callback();
}); });
} }
else if (health.health < 5) { else if(health.health < 5){
// 30分钟的毫秒数 // 30分钟的毫秒数
const thirtyMinutes = 30 * 60 * 1000; const thirtyMinutes = 30 * 60 * 1000;
const elapsedTime = timestamp - health.timestamp; const elapsedTime = timestamp - health.timestamp;
@ -534,8 +534,8 @@ var GameTool = {
const recoveredHealth = Math.min(5 - health.health, Math.floor(elapsedTime / thirtyMinutes)); const recoveredHealth = Math.min(5 - health.health, Math.floor(elapsedTime / thirtyMinutes));
if (recoveredHealth > 0) { if (recoveredHealth > 0) {
health.health += recoveredHealth; health.health += recoveredHealth;
cc.fx.GameTool.setUserHealth(recoveredHealth, () => { cc.fx.GameTool.setUserHealth(recoveredHealth,()=>{
if (callback) callback(); if(callback) callback();
}); });
console.log(`体力值恢复 ${recoveredHealth} 点,当前体力值: ${cc.fx.GameConfig.GM_INFO.hp}`); console.log(`体力值恢复 ${recoveredHealth} 点,当前体力值: ${cc.fx.GameConfig.GM_INFO.hp}`);
} else { } else {
@ -551,7 +551,7 @@ var GameTool = {
//获取用户体力值 //获取用户体力值
getUserHealth(callback: Function) { getUserHealth(callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
console.log("即将进入体力获取接口"); console.log("即将进入体力获取接口");
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
@ -561,7 +561,7 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log("体力获取成功",res); // console.log("体力获取成功",res);
if (callback) if(callback)
callback(res); callback(res);
}, },
fail: err => { fail: err => {
@ -573,48 +573,48 @@ var GameTool = {
}, },
//设置用户体力值 有可能加,有可能定时器减 //设置用户体力值 有可能加,有可能定时器减
setUserHealth(health, callback) { setUserHealth(health,callback){
cc.fx.GameConfig.GM_INFO.hp += health; cc.fx.GameConfig.GM_INFO.hp += health;
// if(health < 0) { // if(health < 0) {
// } // }
// else MiniGameSdk.API.showToast("体力值恢复"); // else MiniGameSdk.API.showToast("体力值恢复");
const timestamp = Date.now(); const timestamp = Date.now();
let healthInfo = {} let healthInfo ={}
//如果消耗之前不是满体力,说明已经在恢复期,并不用修改时间 //如果消耗之前不是满体力,说明已经在恢复期,并不用修改时间
if (health < 0 && cc.fx.GameConfig.GM_INFO.hp != 4) { if(health < 0 && cc.fx.GameConfig.GM_INFO.hp != 4) {
let oldTime = cc.fx.StorageMessage.getStorage("health").timestamp; let oldTime = cc.fx.StorageMessage.getStorage("health").timestamp;
healthInfo = { healthInfo = {
"health": cc.fx.GameConfig.GM_INFO.hp, "health":cc.fx.GameConfig.GM_INFO.hp,
"timestamp": oldTime "timestamp":oldTime
} }
} }
else { else{
healthInfo = { healthInfo = {
"health": cc.fx.GameConfig.GM_INFO.hp, "health":cc.fx.GameConfig.GM_INFO.hp,
"timestamp": timestamp "timestamp":timestamp
} }
} }
cc.fx.StorageMessage.setStorage("health", healthInfo); cc.fx.StorageMessage.setStorage("health",healthInfo);
MiniGameSdk.API.shushu_SetSuperProperties(null); MiniGameSdk.API.shushu_SetSuperProperties(null);
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'userHealth', name: 'userHealth',
data: { data: {
action: 'save', action: 'save',
healthAmount: cc.fx.GameConfig.GM_INFO.hp, healthAmount: cc.fx.GameConfig.GM_INFO.hp,
timestamp: timestamp timestamp:timestamp
}, },
success: res => { success: res => {
if (callback) { if(callback){
callback(res); callback(res);
} }
}, },
fail: err => { fail: err => {
if (callback) { if(callback){
callback(err); callback(err);
} }
// console.error('存储关卡数据失败', err) // console.error('存储关卡数据失败', err)
@ -624,9 +624,9 @@ var GameTool = {
}, },
//购买行为 //购买行为
buyReview(coin, callback: Function) { buyReview(coin,callback: Function){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
// console.log("实际即将消耗金币:",coin); // console.log("实际即将消耗金币:",coin);
// this.changeCoin(coin); // this.changeCoin(coin);
callback(); callback();
@ -634,36 +634,36 @@ var GameTool = {
}, },
//更改用户道具数 //更改用户道具数
buyProp(propid, callback: Function) { buyProp(propid,callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
let num = 3; let num = 3;
let cost = 1500; let cost = 1500;
if (propid == 2002) { if(propid == 2002){
cost = 1000; cost = 1000;
num = 1; num = 1;
} }
cc.fx.GameTool.changeCoin(-cost); cc.fx.GameTool.changeCoin(-cost);
cc.fx.GameTool.setUserProp(propid, num, (data) => { cc.fx.GameTool.setUserProp(propid,num,(data)=>{
}) })
const data = { const data = {
id: (propid + ""), id: (propid + ""),
num: 3 num:3
} }
cc.fx.GameTool.shushu_Track("resource_get", data); cc.fx.GameTool.shushu_Track("resource_get",data);
let _id = ""; let _id = "";
if (propid == 2001) _id = "freeze_in_game"; if(propid == 2001) _id = "freeze_in_game";
else if (propid == 2002) _id = "hammer_in_game"; else if(propid == 2002) _id = "hammer_in_game";
else if (propid == 2003) _id = "wand_in_game"; else if(propid == 2003) _id = "wand_in_game";
const buyData = { const buyData = {
item_id: _id, item_id:_id,
item_num: 3, item_num:3,
item_price: cost, item_price:cost,
cost_type: "gold" cost_type:"gold"
} }
console.log("____________即将上传Shop_buy", buyData); console.log("____________即将上传Shop_buy",buyData);
cc.fx.GameTool.shushu_Track("shop_buy", buyData); cc.fx.GameTool.shushu_Track("shop_buy",buyData);
callback(); callback();
@ -672,9 +672,9 @@ var GameTool = {
//改变用户关卡 //改变用户关卡
setUserLevel(callback) { setUserLevel(callback){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
// if(cc.fx.GameConfig.GM_INFO.level <= 0 || cc.fx.GameConfig.GM_INFO.level == undefined){ // if(cc.fx.GameConfig.GM_INFO.level <= 0 || cc.fx.GameConfig.GM_INFO.level == undefined){
// console.log("等级重置为0"); // console.log("等级重置为0");
// cc.fx.GameConfig.GM_INFO.level = 0; // cc.fx.GameConfig.GM_INFO.level = 0;
@ -690,7 +690,7 @@ var GameTool = {
success: res => { success: res => {
// console.log('云函数返回结果:', res); // console.log('云函数返回结果:', res);
// console.log('存储关卡数据成功',cc.fx.GameConfig.GM_INFO.level); // console.log('存储关卡数据成功',cc.fx.GameConfig.GM_INFO.level);
if (callback) { if(callback){
callback(res); callback(res);
} }
@ -698,7 +698,7 @@ var GameTool = {
fail: err => { fail: err => {
// console.log('存储关卡数据失败') // console.log('存储关卡数据失败')
return; return;
if (callback) { if(callback){
callback(err); callback(err);
} }
console.error('存储关卡数据失败', err) console.error('存储关卡数据失败', err)
@ -710,7 +710,7 @@ var GameTool = {
//获取用户关卡数 //获取用户关卡数
getUserProp(callback: Function) { getUserProp(callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'userProp', name: 'userProp',
@ -719,12 +719,12 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log('读取用户道具数据成功', res.result) // console.log('读取用户道具数据成功', res.result)
if (res.result.data) { if(res.result.data){
// cc.fx.GameConfig.GM_INFO.freezeAmount = res.result.data.freeze; // cc.fx.GameConfig.GM_INFO.freezeAmount = res.result.data.freeze;
// cc.fx.GameConfig.GM_INFO.hammerAmount = res.result.data.hammer; // cc.fx.GameConfig.GM_INFO.hammerAmount = res.result.data.hammer;
// cc.fx.GameConfig.GM_INFO.magicAmount = res.result.data.magic_wand; // cc.fx.GameConfig.GM_INFO.magicAmount = res.result.data.magic_wand;
} }
if (callback) if(callback)
callback(res); callback(res);
}, },
@ -736,24 +736,24 @@ var GameTool = {
}, },
//改变用户道具 //改变用户道具
setUserProp(propid, amount, callback) { setUserProp(propid,amount,callback){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
let newPropData = null; let newPropData = null;
if (propid == 0) { if(propid == 0){
newPropData = { newPropData = {
freeze: cc.fx.GameConfig.GM_INFO.freezeAmount, freeze:cc.fx.GameConfig.GM_INFO.freezeAmount,
hammer: cc.fx.GameConfig.GM_INFO.hammerAmount, hammer:cc.fx.GameConfig.GM_INFO.hammerAmount,
magic_wand: cc.fx.GameConfig.GM_INFO.magicAmount, magic_wand:cc.fx.GameConfig.GM_INFO.magicAmount,
} }
} }
else if (propid == 2001) { else if(propid == 2001){
newPropData = amount; newPropData = amount;
} }
else if (propid == 2002) { else if(propid == 2002){
newPropData = amount; newPropData = amount;
} }
else if (propid == 2003) { else if(propid == 2003){
newPropData = amount; newPropData = amount;
} }
@ -767,14 +767,14 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log('云函数返回结果:', res); // console.log('云函数返回结果:', res);
if (callback) { if(callback){
callback(res); callback(res);
} }
// console.log('存储道具数据成功') // console.log('存储道具数据成功')
}, },
fail: err => { fail: err => {
// console.log('存储道具数据失败') // console.log('存储道具数据失败')
if (callback) { if(callback){
callback(err); callback(err);
} }
console.error('存储道具数据失败', err) console.error('存储道具数据失败', err)
@ -792,7 +792,7 @@ var GameTool = {
// 设置用户信息 // 设置用户信息
setUserInfo(callback: Function) { setUserInfo(callback: Function) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
const time = cc.fx.GameTool.formatDate(new Date()); const time = cc.fx.GameTool.formatDate(new Date());
let userInfo = { let userInfo = {
// 这里填写要存储的用户数据 // 这里填写要存储的用户数据
@ -810,13 +810,13 @@ var GameTool = {
}, },
success: res => { success: res => {
// console.log('存储用户数据成功') // console.log('存储用户数据成功')
if (callback) { if(callback){
callback(res); callback(res);
} }
}, },
fail: err => { fail: err => {
if (callback) { if(callback){
callback("fail"); callback("fail");
} }
} }
@ -825,10 +825,10 @@ var GameTool = {
}, },
//商城购买 //商城购买
shopBuy(productId) { shopBuy(productId){
let coin = 0; let coin = 0;
let price = 0; let price = 0;
switch (productId) { switch(productId){
case "gold_1": case "gold_1":
cc.fx.GameTool.changeCoin(1200); cc.fx.GameTool.changeCoin(1200);
coin = 1200; coin = 1200;
@ -867,12 +867,12 @@ var GameTool = {
break; break;
} }
const buyData = { const buyData = {
item_id: productId, item_id:productId,
item_num: coin, item_num:coin,
item_price: price, item_price:price,
cost_type: "cash" cost_type:"cash"
} }
cc.fx.GameTool.shushu_Track("shop_buy", buyData); cc.fx.GameTool.shushu_Track("shop_buy",buyData);
}, },
formatDate(date: Date): string { formatDate(date: Date): string {
@ -888,20 +888,20 @@ var GameTool = {
}, },
//获取时间戳 //获取时间戳
getTime() { getTime(){
const timestamp = (new Date().getTime()) const timestamp = (new Date().getTime())
return timestamp; return timestamp;
}, },
pushLister: function () { pushLister:function () {
}, },
removeAllLister: function () { removeAllLister:function () {
}, },
//上报数据 //上报数据
shushu_Track: function (name, data) { shushu_Track: function(name,data){
let eventData = {} let eventData = {}
switch (name) { switch(name){
case "login": case "login":
eventData = { eventData = {
register_time: data.register_time, register_time: data.register_time,
@ -927,16 +927,16 @@ var GameTool = {
break; break;
case "resource_get": case "resource_get":
eventData = { eventData = {
change_reason: "购买道具", //获得来源 change_reason:"购买道具", //获得来源
change_num: data.num, //获得数量 change_num:data.num, //获得数量
resource_id: data.id //道具id resource_id:data.id //道具id
} }
break; break;
case "resource_cost": case "resource_cost":
eventData = { eventData = {
change_reason: "使用道具", //获得来源 change_reason:"使用道具", //获得来源
change_num: data.num, //获得数量 change_num:data.num, //获得数量
resource_id: data.id //道具id resource_id:data.id //道具id
} }
break; break;
case "shop_buy": case "shop_buy":
@ -976,7 +976,7 @@ var GameTool = {
} }
break; break;
} }
if (name == "finish_stage") { if(name == "finish_stage"){
console.log("准备上报完成"); console.log("准备上报完成");
console.log(eventData); console.log(eventData);
// MiniGameSdk.API.showToast("准备上报完成游戏"); // MiniGameSdk.API.showToast("准备上报完成游戏");
@ -986,9 +986,9 @@ var GameTool = {
}, },
//获取微信小游戏版本号 //获取微信小游戏版本号
getWechatGameVersion: function () { getWechatGameVersion: function(){
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
const accountInfo = wx.getAccountInfoSync(); const accountInfo = wx.getAccountInfoSync();
const miniProgram = accountInfo.miniProgram; const miniProgram = accountInfo.miniProgram;
@ -1006,19 +1006,19 @@ var GameTool = {
}, },
//微信小游戏根据openId将用户分组有可能会两分三分六分 //微信小游戏根据openId将用户分组有可能会两分三分六分
setWechatGameGroup: function (type: 2 | 3 | 6) { setWechatGameGroup: function(type: 2 | 3 | 6) {
//@ts-ignore //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx!== 'undefined' && wx!== null) {
//@ts-ignore //@ts-ignore
if (cc.fx.GameConfig.GM_INFO.openid) { if(cc.fx.GameConfig.GM_INFO.openid) {
const openid = cc.fx.GameConfig.GM_INFO.openid; const openid = cc.fx.GameConfig.GM_INFO.openid;
const lastChar = openid[openid.length - 1]; const lastChar = openid[openid.length - 1];
const charCode = lastChar.charCodeAt(0); const charCode = lastChar.charCodeAt(0);
let groupNumber: number; let groupNumber: number;
console.log("openid尾数____________________:", charCode); console.log("openid尾数____________________:",charCode);
// 根据 type 参数计算分组编号 // 根据 type 参数计算分组编号
switch (type) { switch(type) {
case 2: case 2:
groupNumber = charCode % 2; groupNumber = charCode % 2;
break; break;
@ -1032,12 +1032,11 @@ var GameTool = {
console.log('type 参数值无效,必须为 2、3 或 6'); console.log('type 参数值无效,必须为 2、3 或 6');
return; return;
} }
console.log("type____________________:", type); console.log("type____________________:",type);
console.log("分组编号____________________:", groupNumber); console.log("分组编号____________________:",groupNumber);
return groupNumber;
} }
} }
else return 1;
} }
}; };

View File

@ -8,7 +8,7 @@
import MapConroler from "../Map"; import MapConroler from "../Map";
import NumberToImage from "../NumberToImage"; import NumberToImage from "../NumberToImage";
const { ccclass, property } = cc._decorator; const {ccclass, property} = cc._decorator;
@ -16,70 +16,54 @@ const { ccclass, property } = cc._decorator;
export default class Boom extends cc.Component { export default class Boom extends cc.Component {
static _instance: any; static _instance: any;
time: number = 60; time: number = 60;
over: boolean = false;
// mapInfo: number[][] = []; // mapInfo: number[][] = [];
onLoad() { onLoad () {
this.over = false;
} }
start() { start () {
this.over = false;
} }
init(time) { init(time){
if (time) this.time = time; if(time) this.time = time;
this.node.getChildByName("time").active = true; this.node.getChildByName("time").active = true;
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName("time"), false); NumberToImage.numberToImageNodes(this.time,20,8,"lock_",this.node.getChildByName("time"),false);
// this.node.getChildByName("time").getComponent(cc.Label).string = this.time.toString(); // this.node.getChildByName("time").getComponent(cc.Label).string = this.time.toString();
} }
startBoom() { startBoom(){
this.schedule(this.updateTime, 1); this.schedule(this.updateTime, 1);
} }
destroyBoom(type) { destroyBoom(){
if (this.over) return;
this.over = true;
this.unschedule(this.updateTime); this.unschedule(this.updateTime);
this.node.parent.getComponent("Block").resetFreeze(); this.node.parent.getComponent("Block").resetFreeze();
this.node.destroy(); this.node.destroy();
} }
stopBoom() { stopBoom(){
this.unschedule(this.updateTime); this.unschedule(this.updateTime);
} }
updateTime() { updateTime(){
this.time--; this.time --;
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName("time"), false); NumberToImage.numberToImageNodes(this.time,20,8,"lock_",this.node.getChildByName("time"),false);
if (this.time <= 0) { if(this.time <= 0){
// 创建模拟触摸事件对象
const mockTouchEvent = {
getLocation: () => {
// 获取父节点的位置作为触摸落点
const parentPos = this.node.parent.getPosition();
return parentPos;
}
};
// 触发父节点 Block 的 touchEnd 事件
this.node.parent.getComponent("Block").touchEnd(mockTouchEvent);
this.unschedule(this.updateTime); this.unschedule(this.updateTime);
this.node.getChildByName("time").active = false;
MapConroler._instance.failLevel("boom"); MapConroler._instance.failLevel("boom");
this.node.getChildByName("zhandan").active = true; this.node.getChildByName("zhandan").active = true;
this.node.getChildByName("bg").active = false; this.node.getChildByName("bg").active = false;
const skeleton = this.node.getChildByName("zhandan").getComponent(sp.Skeleton); const skeleton = this.node.getChildByName("zhandan").getComponent(sp.Skeleton);
skeleton.setAnimation(1, "eff", false); skeleton.setAnimation(1,"eff",false);
// 监听动画完成事件,销毁自身爆炸节点 // 监听动画完成事件
skeleton.setCompleteListener(() => { skeleton.setCompleteListener(() => {
// 动画播放完成后销毁节点 // 动画播放完成后销毁节点
this.destroyBoom(true); this.node.destroy();
}); });
// this.node.destroy(); // this.node.destroy();

View File

@ -6,7 +6,6 @@
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import JiaZai from "./JiaZai"; import JiaZai from "./JiaZai";
import MapConroler from "./Map";
import SceneManager from "./SceneManager"; import SceneManager from "./SceneManager";
@ -132,13 +131,8 @@ export default class setUi extends cc.Component {
//退出游戏 //退出游戏
clickExit() { clickExit() {
if(MapConroler._instance.gameStart == true) {
this.exit.active = true; this.exit.active = true;
} }
else{
MapConroler._instance.returnHome();
}
}
//取消 //取消
cancelExit() { cancelExit() {
this.exit.active = false; this.exit.active = false;