From 396d96dd98afd2adc99eb61ac80e1fadb70f4ba3 Mon Sep 17 00:00:00 2001 From: fanxuehan <fanxuehan@qq.com> Date: Thu, 24 Feb 2022 17:06:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20global=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/NGT_02/PU20/script/picNode.js | 3 + assets/NGT_02/scene/NGT_02.js | 523 +++++++++--------- assets/NGT_02/script/common/_preDefine.js | 26 +- assets/NGT_02/script/common/utils.js | 384 +++++++------ assets/NGT_02/script/game/speaker.js | 58 +- assets/NGT_02/script/manager/data_mgr.js | 2 +- assets/NGT_02/script/manager/event_mgr.js | 2 +- assets/NGT_02/script/manager/local_storage.js | 2 +- assets/NGT_02/script/manager/res_mgr.js | 2 +- assets/NGT_02/script/manager/snd_mgr.js | 2 +- 10 files changed, 508 insertions(+), 496 deletions(-) diff --git a/assets/NGT_02/PU20/script/picNode.js b/assets/NGT_02/PU20/script/picNode.js index f7db968..599dd6c 100644 --- a/assets/NGT_02/PU20/script/picNode.js +++ b/assets/NGT_02/PU20/script/picNode.js @@ -1,5 +1,7 @@ const tools = require("../script/tools"); +import { initGlobal_NGT_02 } from "../../script/common/_preDefine"; + var picNode = cc.Class({ extends: cc.Component, @@ -12,6 +14,7 @@ var picNode = cc.Class({ }, ctor: function () { + initGlobal_NGT_02(); picNode.inst = this; g.picNode = picNode; }, diff --git a/assets/NGT_02/scene/NGT_02.js b/assets/NGT_02/scene/NGT_02.js index 02d5f93..980d553 100644 --- a/assets/NGT_02/scene/NGT_02.js +++ b/assets/NGT_02/scene/NGT_02.js @@ -1,267 +1,266 @@ +import { initGlobal_NGT_02 } from "../script/common/_preDefine"; + /** * 游æˆä¸»é€»è¾‘ */ var game = cc.Class({ - extends: cc.Component, - - properties: { - btnRestart: { - default: null, - type: cc.Node, - displayName: "é‡å¼€æŒ‰é’®" - } - }, - - ctor: function () { - initGlobal_NGT_02(); - game.inst = this; - g.game = game; - }, - - // 生命周期 onLoad - onLoad() { - //åˆå§‹åŒ–æ¸¸æˆ - this.initGame(); - if (window.addEventListener) { - window.addEventListener('resize', this.scaleEventCallBack, false) - } else if (window.attachEvent) { - window.attachEvent('resize', this.scaleEventCallBack, false) - } - cc.debug.setDisplayStats(false); - }, - - //å±å¹•缩放 - scaleEventCallBack: function () { - g.event_mgr.send("adjustUI"); - }, - - //åˆå§‹åŒ–æ¸¸æˆ - initGame: function () { - //èŽ·å¾—æ•°æ® - g.res_mgr.getFormData(); - }, - - onBtnTest() { - g.Light.inst.addLightNum(3); - }, - onBtnTest2() { - g.Light.inst.showLight(); - }, - - //检查当å‰ç¼©æ”¾å€æ•° - checkScale: function (num) { - var scale = 1; - if (num > 2 && num <= 4) { - scale = 0.74 - } - if (num > 4) { - scale = 0.65 - } - return scale; - }, - - //æ·»åŠ èŠ‚ç‚¹ - addItem: function () { - let itemArr = g.data_mgr.getSheepArr(); - this.idx = this.checkNodeParent(); - g.data_mgr.nowNum = itemArr.length; - - itemArr.sort(function () { return Math.random() > 0.5 ? -1 : 1; }) - - - for (var i = 0; i < itemArr.length; i++) { - let newItem_0 = cc.instantiate(this.Item_0[itemArr.length > 14 ? 0 : 1]); - //æ›´æ–°å项 - var com = newItem_0.getChildByName("item").getComponent("item"); - let itemInfo = itemArr[i]; - com.updateUI(itemInfo); - newItem_0.active = true; - //设置类别 - let sheepInfo = g.data_mgr.getSheep(i); - newItem_0.getChildByName("item").type = this.checkType(sheepInfo.sheepfoldId); - - - newItem_0.parent = this.contentArr_2[this.idx]; - }; - }, - - //检测放到哪个节点底下 - checkNodeParent: function () { - //获å–到总列表 - var itemArr = g.data_mgr.getSheepArr(); - - // - if (itemArr.length <= 7) { - this.contentArr_2[1].active = true; - var idx = 1; - } else { - this.contentArr_2[0].active = true; - var idx = 0; - } - return idx; - }, - - //检查类别 - checkType: function (Id) { - for (var i in g.data_mgr.getSheepfoldArr()) { - var sheepfoldInfo = g.data_mgr.getSheepfoldArr()[i]; - if (Id == sheepfoldInfo.id) { - return ~~i + 1; - } - } - return -1; - }, - - //è®¾ç½®ç›®æ ‡èŠ‚ç‚¹ç±»åž‹ - setOptionType: function () { - //设置类型 - this.OptionType = g.data_mgr.getSheepfoldArr().length - 3; - }, - - getOptionType: function () { - return this.OptionType; - }, - - //更新界é¢ä¿¡æ¯ - UpdataUi: function () { - this.btnRestart.active = false; - - //设置题目长度 - g.scoreStart.inst.addStar(g.data_mgr.data.starArr.length); - g.data_mgr.ansId = 0; - g.data_mgr.startId = 0; - //åˆå§‹åŒ–å•题题目 - this.InitQuestion(); - }, - - //åˆå§‹åŒ–å•个题目 - InitQuestion() { - var question = g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId] - //åˆå§‹åŒ–ç¯ - g.Light.inst.addLightNum(question.hotZoneItemArr.length); - //åˆå§‹åŒ–æ ‡é¢˜ - g.titleType.inst.showTitle(question.title, question.title_audio_url); - if (question.title_audio_url) { - g.data_mgr.gameState = 2; - setTimeout(() => { - g.titleType.inst.onBtnPlayEffect(); - }, 500) - } - //设置ä¸é—´å›¾ç‰‡ - g.picNode.inst.onShow(question); - }, - - onBtnCheck() { - //默认ç”对 - - //æ’æ”¾ç‰¹æ•ˆ - - //ç¯+1 - g.speaker.inst.playEffect(g.enum.E_Audio.Right); - let num = g.Light.inst.showLight(); - if (num == -1) { - g.data_mgr.ansId += 1; - if (g.data_mgr.ansId >= g.data_mgr.data.starArr[g.data_mgr.startId].queArr.length) { - //大星星音效 - g.speaker.inst.playEffect(g.enum.E_Audio.Star); - g.scoreStart.inst.showStar(); - g.data_mgr.ansId = 0; - g.data_mgr.startId += 1; - } - setTimeout(() => { - if (g.data_mgr.startId >= g.data_mgr.data.starArr.length) { - g.speaker.inst.playEffect(g.enum.E_Audio.Flowers); - g.effect.inst.showEffect2(); - this.btnRestart.active = true; - const middleLayer = cc.find('middleLayer'); - if (middleLayer) { - const middleLayerComponent = middleLayer.getComponent('middleLayer'); - if (middleLayerComponent.role == 'student') { - middleLayerComponent.onHomeworkFinish(() => { }); - } - } else { - console.log('onHomeworkFinish'); - } - } else { - this.InitQuestion(); - } - }, 1500) - } - }, - - //æ’æ”¾æ ‡é¢˜éŸ³æ•ˆ - playAudioTitle: function () { - //èŽ·å¾—æ’æ”¾è·¯å¾„ - var path = g.data_mgr.data.audio_url; - g.res_mgr.playAudioByUrl(path, (url) => { - g.snd_mgr.playEffect(url, null); - }); - }, - - //é‡ç½®UIç•Œé¢ - resetUI: function () { - //移除所有å节点 - this.contentArr_2[0].removeAllChildren(); - this.contentArr_2[1].removeAllChildren(); - //移除所有å节点 - g.event_mgr.send("reSetGame"); - }, - - //釿–°å¼€å§‹ - onBtnReStart: function () { - g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom); - //移除所有计时器 - this.unscheduleAllCallbacks(); - //åˆå§‹åŒ–ç•Œé¢ - this.UpdataUi(); - }, - - //游æˆå¼€å§‹ - gameStart: function () { - console.log("游æˆå¼€å§‹:" + g.data_mgr); - //æ’æ”¾ä¸€ä¸ªä¸Šé¢çš„éŸ³ä¹ - this.setAudioInfo(1); - }, - - - checkAnswer(caller, option_i) { - if (caller == undefined) { - return; - } - - if (option_i != -1) { - let nodOption = this.contType[this.OptionType].children[option_i - 1] - if (nodOption) { - - let AABB = nodOption.getComponent("DragGameOptionObject").setAABB(); - let callerAABB = this.getCallerAABB(caller); - var isIntersect = AABB.containsRect(callerAABB);//åˆ¤æ–æ˜¯å¦è¢«åŒ…å« - console.log(isIntersect) - if (isIntersect) { - return nodOption; - } - return false - } - } - }, - - getCallerAABB(caller) { - let svLeftBottomPoint = caller.parent.convertToWorldSpaceAR( - cc.v2( - caller.x, - caller.y - ) - ); - var posNode_1 = cc.rect( - svLeftBottomPoint.x, - svLeftBottomPoint.y, - 0, - 0 - ); - return posNode_1 - }, - - onDestroy() { - window.g = null; - } + extends: cc.Component, + + properties: { + btnRestart: { + default: null, + type: cc.Node, + displayName: "é‡å¼€æŒ‰é’®", + }, + }, + + ctor: function () { + initGlobal_NGT_02(); + game.inst = this; + g.game = game; + }, + + // 生命周期 onLoad + onLoad() { + //åˆå§‹åŒ–æ¸¸æˆ + this.initGame(); + if (window.addEventListener) { + window.addEventListener("resize", this.scaleEventCallBack, false); + } else if (window.attachEvent) { + window.attachEvent("resize", this.scaleEventCallBack, false); + } + cc.debug.setDisplayStats(false); + }, + + //å±å¹•缩放 + scaleEventCallBack: function () { + g.event_mgr.send("adjustUI"); + }, + + //åˆå§‹åŒ–æ¸¸æˆ + initGame: function () { + //èŽ·å¾—æ•°æ® + g.res_mgr.getFormData(); + }, + + onBtnTest() { + g.Light.inst.addLightNum(3); + }, + onBtnTest2() { + g.Light.inst.showLight(); + }, + + //检查当å‰ç¼©æ”¾å€æ•° + checkScale: function (num) { + var scale = 1; + if (num > 2 && num <= 4) { + scale = 0.74; + } + if (num > 4) { + scale = 0.65; + } + return scale; + }, + + //æ·»åŠ èŠ‚ç‚¹ + addItem: function () { + let itemArr = g.data_mgr.getSheepArr(); + this.idx = this.checkNodeParent(); + g.data_mgr.nowNum = itemArr.length; + + itemArr.sort(function () { + return Math.random() > 0.5 ? -1 : 1; + }); + + for (var i = 0; i < itemArr.length; i++) { + let newItem_0 = cc.instantiate(this.Item_0[itemArr.length > 14 ? 0 : 1]); + //æ›´æ–°å项 + var com = newItem_0.getChildByName("item").getComponent("item"); + let itemInfo = itemArr[i]; + com.updateUI(itemInfo); + newItem_0.active = true; + //设置类别 + let sheepInfo = g.data_mgr.getSheep(i); + newItem_0.getChildByName("item").type = this.checkType( + sheepInfo.sheepfoldId + ); + + newItem_0.parent = this.contentArr_2[this.idx]; + } + }, + + //检测放到哪个节点底下 + checkNodeParent: function () { + //获å–到总列表 + var itemArr = g.data_mgr.getSheepArr(); + + // + if (itemArr.length <= 7) { + this.contentArr_2[1].active = true; + var idx = 1; + } else { + this.contentArr_2[0].active = true; + var idx = 0; + } + return idx; + }, + + //检查类别 + checkType: function (Id) { + for (var i in g.data_mgr.getSheepfoldArr()) { + var sheepfoldInfo = g.data_mgr.getSheepfoldArr()[i]; + if (Id == sheepfoldInfo.id) { + return ~~i + 1; + } + } + return -1; + }, + + //è®¾ç½®ç›®æ ‡èŠ‚ç‚¹ç±»åž‹ + setOptionType: function () { + //设置类型 + this.OptionType = g.data_mgr.getSheepfoldArr().length - 3; + }, + + getOptionType: function () { + return this.OptionType; + }, + + //更新界é¢ä¿¡æ¯ + UpdataUi: function () { + this.btnRestart.active = false; + + //设置题目长度 + g.scoreStart.inst.addStar(g.data_mgr.data.starArr.length); + g.data_mgr.ansId = 0; + g.data_mgr.startId = 0; + //åˆå§‹åŒ–å•题题目 + this.InitQuestion(); + }, + + //åˆå§‹åŒ–å•个题目 + InitQuestion() { + var question = + g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId]; + //åˆå§‹åŒ–ç¯ + g.Light.inst.addLightNum(question.hotZoneItemArr.length); + //åˆå§‹åŒ–æ ‡é¢˜ + g.titleType.inst.showTitle(question.title, question.title_audio_url); + if (question.title_audio_url) { + g.data_mgr.gameState = 2; + setTimeout(() => { + g.titleType.inst.onBtnPlayEffect(); + }, 500); + } + //设置ä¸é—´å›¾ç‰‡ + g.picNode.inst.onShow(question); + }, + + onBtnCheck() { + //默认ç”对 + + //æ’æ”¾ç‰¹æ•ˆ + + //ç¯+1 + g.speaker.inst.playEffect(g.enum.E_Audio.Right); + let num = g.Light.inst.showLight(); + if (num == -1) { + g.data_mgr.ansId += 1; + if ( + g.data_mgr.ansId >= + g.data_mgr.data.starArr[g.data_mgr.startId].queArr.length + ) { + //大星星音效 + g.speaker.inst.playEffect(g.enum.E_Audio.Star); + g.scoreStart.inst.showStar(); + g.data_mgr.ansId = 0; + g.data_mgr.startId += 1; + } + setTimeout(() => { + if (g.data_mgr.startId >= g.data_mgr.data.starArr.length) { + g.speaker.inst.playEffect(g.enum.E_Audio.Flowers); + g.effect.inst.showEffect2(); + this.btnRestart.active = true; + const middleLayer = cc.find("middleLayer"); + if (middleLayer) { + const middleLayerComponent = + middleLayer.getComponent("middleLayer"); + if (middleLayerComponent.role == "student") { + middleLayerComponent.onHomeworkFinish(() => {}); + } + } else { + console.log("onHomeworkFinish"); + } + } else { + this.InitQuestion(); + } + }, 1500); + } + }, + + //æ’æ”¾æ ‡é¢˜éŸ³æ•ˆ + playAudioTitle: function () { + //èŽ·å¾—æ’æ”¾è·¯å¾„ + var path = g.data_mgr.data.audio_url; + g.res_mgr.playAudioByUrl(path, (url) => { + g.snd_mgr.playEffect(url, null); + }); + }, + + //é‡ç½®UIç•Œé¢ + resetUI: function () { + //移除所有å节点 + this.contentArr_2[0].removeAllChildren(); + this.contentArr_2[1].removeAllChildren(); + //移除所有å节点 + g.event_mgr.send("reSetGame"); + }, + + //釿–°å¼€å§‹ + onBtnReStart: function () { + g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom); + //移除所有计时器 + this.unscheduleAllCallbacks(); + //åˆå§‹åŒ–ç•Œé¢ + this.UpdataUi(); + }, + + //游æˆå¼€å§‹ + gameStart: function () { + console.log("游æˆå¼€å§‹:" + g.data_mgr); + //æ’æ”¾ä¸€ä¸ªä¸Šé¢çš„éŸ³ä¹ + this.setAudioInfo(1); + }, + + checkAnswer(caller, option_i) { + if (caller == undefined) { + return; + } + + if (option_i != -1) { + let nodOption = this.contType[this.OptionType].children[option_i - 1]; + if (nodOption) { + let AABB = nodOption.getComponent("DragGameOptionObject").setAABB(); + let callerAABB = this.getCallerAABB(caller); + var isIntersect = AABB.containsRect(callerAABB); //åˆ¤æ–æ˜¯å¦è¢«åŒ…å« + console.log(isIntersect); + if (isIntersect) { + return nodOption; + } + return false; + } + } + }, + + getCallerAABB(caller) { + let svLeftBottomPoint = caller.parent.convertToWorldSpaceAR( + cc.v2(caller.x, caller.y) + ); + var posNode_1 = cc.rect(svLeftBottomPoint.x, svLeftBottomPoint.y, 0, 0); + return posNode_1; + }, + + onDestroy() { + window.g = null; + }, }); diff --git a/assets/NGT_02/script/common/_preDefine.js b/assets/NGT_02/script/common/_preDefine.js index 7780f9c..711e9a6 100644 --- a/assets/NGT_02/script/common/_preDefine.js +++ b/assets/NGT_02/script/common/_preDefine.js @@ -1,11 +1,21 @@ +import { initDataMgr_NGT_02 } from "../manager/data_mgr"; +import { initEventMgr_NGT_02 } from "../manager/event_mgr"; +import { initStorageMgr_NGT_02 } from "../manager/local_storage"; +import { initResMgr_NGT_02 } from "../manager/res_mgr"; +import { initSndMgr_NGT_02 } from "../manager/snd_mgr"; +import { initUtils_NGT_02 } from "./utils"; +import { initEnumMgr_NGT_02 } from "../game/speaker"; // 全局环境预声明 -function initGlobal_NGT_02() { +export function initGlobal_NGT_02() { console.log('window.g init'); - window.g = {}; - initDataMgr_NGT_02(); - initEventMgr_NGT_02(); - initStorageMgr_NGT_02(); - initResMgr_NGT_02(); - initSndMgr_NGT_02(); - initUtils_NGT_02(); + if (!window.g) { + window.g = {}; + initDataMgr_NGT_02(); + initEventMgr_NGT_02(); + initStorageMgr_NGT_02(); + initResMgr_NGT_02(); + initSndMgr_NGT_02(); + initUtils_NGT_02(); + initEnumMgr_NGT_02(); + } } \ No newline at end of file diff --git a/assets/NGT_02/script/common/utils.js b/assets/NGT_02/script/common/utils.js index 40db56e..f56f5b6 100644 --- a/assets/NGT_02/script/common/utils.js +++ b/assets/NGT_02/script/common/utils.js @@ -1,4 +1,4 @@ -function initUtils_NGT_02() { +export function initUtils_NGT_02() { g.utils = { // èŒƒå›´éšæœº randFromTo: function (_min, _max) { @@ -42,227 +42,225 @@ function initUtils_NGT_02() { } }, }; +} - export function getPosByAngle(angle, len) { - const radian = (angle * Math.PI) / 180; - const x = Math.sin(radian) * len; - const y = Math.cos(radian) * len; - - return { x, y }; - } +export function getPosByAngle(angle, len) { + const radian = (angle * Math.PI) / 180; + const x = Math.sin(radian) * len; + const y = Math.cos(radian) * len; - export function getAngleByPos(px, py, mx, my) { - const x = Math.abs(px - mx); - const y = Math.abs(py - my); + return { x, y }; +} - const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); - const cos = y / z; - const radina = Math.acos(cos); // 用å三角函数求弧度 - let angle = Math.floor((180 / (Math.PI / radina)) * 100) / 100; // å°†å¼§åº¦è½¬æ¢æˆè§’度 +export function getAngleByPos(px, py, mx, my) { + const x = Math.abs(px - mx); + const y = Math.abs(py - my); - if (mx > px && my > py) { - // é¼ æ ‡åœ¨ç¬¬å››è±¡é™ - angle = 180 - angle; - } - if (mx === px && my > py) { - // é¼ æ ‡åœ¨yè½´è´Ÿæ–¹å‘上 - angle = 180; - } - if (mx > px && my === py) { - // é¼ æ ‡åœ¨xè½´æ£æ–¹å‘上 - angle = 90; - } - if (mx < px && my > py) { - // é¼ æ ‡åœ¨ç¬¬ä¸‰è±¡é™ - angle = 180 + angle; - } - if (mx < px && my === py) { - // é¼ æ ‡åœ¨xè½´è´Ÿæ–¹å‘ - angle = 270; - } - if (mx < px && my < py) { - // é¼ æ ‡åœ¨ç¬¬äºŒè±¡é™ - angle = 360 - angle; - } + const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + const cos = y / z; + const radina = Math.acos(cos); // 用å三角函数求弧度 + let angle = Math.floor((180 / (Math.PI / radina)) * 100) / 100; // å°†å¼§åº¦è½¬æ¢æˆè§’度 - // console.log('angle: ', angle); - return angle; + if (mx > px && my > py) { + // é¼ æ ‡åœ¨ç¬¬å››è±¡é™ + angle = 180 - angle; } - - export function exchangeNodePos(baseNode, targetNode) { - return baseNode.convertToNodeSpaceAR( - targetNode._parent.convertToWorldSpaceAR( - cc.v2(targetNode.x, targetNode.y) - ) - ); + if (mx === px && my > py) { + // é¼ æ ‡åœ¨yè½´è´Ÿæ–¹å‘上 + angle = 180; } - - export function RandomInt(a, b = 0) { - let max = Math.max(a, b); - let min = Math.min(a, b); - return Math.floor(Math.random() * (max - min) + min); + if (mx > px && my === py) { + // é¼ æ ‡åœ¨xè½´æ£æ–¹å‘上 + angle = 90; } - - export function Between(a, b, c) { - return [a, b, c].sort((a, b) => a - b)[1]; + if (mx < px && my > py) { + // é¼ æ ‡åœ¨ç¬¬ä¸‰è±¡é™ + angle = 180 + angle; } - - export function randomSortByArr(arr) { - const newArr = []; - const tmpArr = arr.concat(); - while (tmpArr.length > 0) { - const randomIndex = Math.floor(tmpArr.length * Math.random()); - newArr.push(tmpArr[randomIndex]); - tmpArr.splice(randomIndex, 1); - } - return newArr; + if (mx < px && my === py) { + // é¼ æ ‡åœ¨xè½´è´Ÿæ–¹å‘ + angle = 270; } - - export async function asyncTweenTo(node, duration, obj, ease = undefined) { - return new Promise((resolve, reject) => { - cc.tween(node) - .to(duration, obj, ease) - .call(() => { - resolve(); - }) - .start(); - }); + if (mx < px && my < py) { + // é¼ æ ‡åœ¨ç¬¬äºŒè±¡é™ + angle = 360 - angle; } - export async function asyncTweenBy(node, duration, obj, ease = undefined) { - return new Promise((resolve, reject) => { - cc.tween(node) - .by(duration, obj, ease) - .call(() => { - resolve(); - }) - .start(); - }); - } + // console.log('angle: ', angle); + return angle; +} + +export function exchangeNodePos(baseNode, targetNode) { + return baseNode.convertToNodeSpaceAR( + targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)) + ); +} - export async function asyncPlayDragonBoneAnimation( - node, - animationName, - time = 1, - onFrameEvent - ) { - return new Promise((resolve, reject) => { - node - .getComponent(dragonBones.ArmatureDisplay) - .once(dragonBones.EventObject.COMPLETE, () => { - resolve(); - }); +export function RandomInt(a, b = 0) { + let max = Math.max(a, b); + let min = Math.min(a, b); + return Math.floor(Math.random() * (max - min) + min); +} - node - .getComponent(dragonBones.ArmatureDisplay) - .on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => { - if (onFrameEvent && typeof onFrameEvent == "function") { - onFrameEvent(name); - } - }); +export function Between(a, b, c) { + return [a, b, c].sort((a, b) => a - b)[1]; +} - node - .getComponent(dragonBones.ArmatureDisplay) - .playAnimation(animationName, time); - }); +export function randomSortByArr(arr) { + const newArr = []; + const tmpArr = arr.concat(); + while (tmpArr.length > 0) { + const randomIndex = Math.floor(tmpArr.length * Math.random()); + newArr.push(tmpArr[randomIndex]); + tmpArr.splice(randomIndex, 1); } + return newArr; +} - export async function asyncPlayEffectByUrl(url, loop = false) { - return new Promise((resolve, reject) => { - cc.assetManager.loadRemote(url, (err, clip) => { - console.log(clip); - cc.audioEngine.playEffect(clip, loop); +export async function asyncTweenTo(node, duration, obj, ease = undefined) { + return new Promise((resolve, reject) => { + cc.tween(node) + .to(duration, obj, ease) + .call(() => { resolve(); - }); - }); - } + }) + .start(); + }); +} - export async function jelly(node) { - return new Promise((resolve, reject) => { - cc.tween(node) - .to(0.1, { scaleX: 0.9, scaleY: 1.1 }) - .to(0.1, { scaleX: 1.1, scaleY: 0.9 }) - .to(0.1, { scaleX: 1, scaleY: 1 }) - .call(resolve) - .start(); - }); - } +export async function asyncTweenBy(node, duration, obj, ease = undefined) { + return new Promise((resolve, reject) => { + cc.tween(node) + .by(duration, obj, ease) + .call(() => { + resolve(); + }) + .start(); + }); +} - export async function asyncDelay(time) { - return new Promise((resolve, reject) => { - setTimeout(() => { +export async function asyncPlayDragonBoneAnimation( + node, + animationName, + time = 1, + onFrameEvent +) { + return new Promise((resolve, reject) => { + node + .getComponent(dragonBones.ArmatureDisplay) + .once(dragonBones.EventObject.COMPLETE, () => { resolve(); - }, time * 1000); + }); + + node + .getComponent(dragonBones.ArmatureDisplay) + .on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => { + if (onFrameEvent && typeof onFrameEvent == "function") { + onFrameEvent(name); + } + }); + + node + .getComponent(dragonBones.ArmatureDisplay) + .playAnimation(animationName, time); + }); +} + +export async function asyncPlayEffectByUrl(url, loop = false) { + return new Promise((resolve, reject) => { + cc.assetManager.loadRemote(url, (err, clip) => { + console.log(clip); + cc.audioEngine.playEffect(clip, loop); + resolve(); }); - } + }); +} - export async function showFireworks( - baseNode, - nodeList, - pos = cc.v2(0, 0), - side = cc.v2(0, 100), - range = 50, - number = 100 - ) { - new Array(number).fill(" ").forEach(async (_, i) => { - let rabbonNode = new cc.Node(); - rabbonNode.parent = baseNode; - rabbonNode.x = pos.x; - rabbonNode.y = pos.y; - rabbonNode.angle = 60 * Math.random() - 30; +export async function jelly(node) { + return new Promise((resolve, reject) => { + cc.tween(node) + .to(0.1, { scaleX: 0.9, scaleY: 1.1 }) + .to(0.1, { scaleX: 1.1, scaleY: 0.9 }) + .to(0.1, { scaleX: 1, scaleY: 1 }) + .call(resolve) + .start(); + }); +} - let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]); - node.parent = rabbonNode; - node.active = true; - node.x = 0; - node.y = 0; - node.angle = 0; +export async function asyncDelay(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(); + }, time * 1000); + }); +} - const rate = Math.random(); - const angle = Math.PI * (Math.random() * 2 - 1); +export async function showFireworks( + baseNode, + nodeList, + pos = cc.v2(0, 0), + side = cc.v2(0, 100), + range = 50, + number = 100 +) { + new Array(number).fill(" ").forEach(async (_, i) => { + let rabbonNode = new cc.Node(); + rabbonNode.parent = baseNode; + rabbonNode.x = pos.x; + rabbonNode.y = pos.y; + rabbonNode.angle = 60 * Math.random() - 30; - await asyncTweenBy( - rabbonNode, - 0.3, - { - x: side.x * rate + Math.cos(angle) * range * rate, - y: side.y * rate + Math.sin(angle) * range * rate, - }, - { - easing: "quadIn", - } - ); + let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]); + node.parent = rabbonNode; + node.active = true; + node.x = 0; + node.y = 0; + node.angle = 0; + + const rate = Math.random(); + const angle = Math.PI * (Math.random() * 2 - 1); + + await asyncTweenBy( + rabbonNode, + 0.3, + { + x: side.x * rate + Math.cos(angle) * range * rate, + y: side.y * rate + Math.sin(angle) * range * rate, + }, + { + easing: "quadIn", + } + ); - cc.tween(rabbonNode).by(8, { y: -2000 }).start(); + cc.tween(rabbonNode).by(8, { y: -2000 }).start(); - rabbonFall(rabbonNode); + rabbonFall(rabbonNode); - await asyncDelay(Math.random()); - cc.tween(node) - .by(0.15, { x: -10, angle: -10 }) - .by(0.3, { x: 20, angle: 20 }) - .by(0.15, { x: -10, angle: -10 }) - .union() - .repeatForever() - .start(); + await asyncDelay(Math.random()); + cc.tween(node) + .by(0.15, { x: -10, angle: -10 }) + .by(0.3, { x: 20, angle: 20 }) + .by(0.15, { x: -10, angle: -10 }) + .union() + .repeatForever() + .start(); - cc.tween(rabbonNode) - .delay(5) - .to(0.3, { opacity: 0 }) - .call(() => { - node.stopAllActions(); - node.active = false; - node.parent = null; - node = null; - }) - .start(); - }); - } + cc.tween(rabbonNode) + .delay(5) + .to(0.3, { opacity: 0 }) + .call(() => { + node.stopAllActions(); + node.active = false; + node.parent = null; + node = null; + }) + .start(); + }); +} - async function rabbonFall(node) { - const time = 1 + Math.random(); - const offsetX = RandomInt(-200, 200) * time; - await asyncTweenBy(node, time, { x: offsetX, angle: (offsetX * 60) / 200 }); - rabbonFall(node); - } +async function rabbonFall(node) { + const time = 1 + Math.random(); + const offsetX = RandomInt(-200, 200) * time; + await asyncTweenBy(node, time, { x: offsetX, angle: (offsetX * 60) / 200 }); + rabbonFall(node); } diff --git a/assets/NGT_02/script/game/speaker.js b/assets/NGT_02/script/game/speaker.js index 88405fe..27c4d24 100644 --- a/assets/NGT_02/script/game/speaker.js +++ b/assets/NGT_02/script/game/speaker.js @@ -1,39 +1,41 @@ -g.enum = { - E_Audio: { - Star: 0,//大星星 - BtnCommom: 1,//按钮 - Flowers: 2,//撒花 - Right: 3,//æ£ç¡® - Error: 4,//错误 - Question: 5,//题数 - } +export function initEnumMgr_NGT_02() { + g.enum = { + E_Audio: { + Star: 0, //大星星 + BtnCommom: 1, //按钮 + Flowers: 2, //撒花 + Right: 3, //æ£ç¡® + Error: 4, //错误 + Question: 5, //题数 + }, + }; } /** * 音效 */ var speaker = cc.Class({ - extends: cc.Component, + extends: cc.Component, - properties: { - eff_audio: { - default: [], - type: cc.AudioClip, - displayName: "音效列表" - }, - }, + properties: { + eff_audio: { + default: [], + type: cc.AudioClip, + displayName: "音效列表", + }, + }, - ctor: function () { - speaker.inst = this; - g.speaker = speaker; - }, + ctor: function () { + speaker.inst = this; + g.speaker = speaker; + }, - // //æ’æ”¾éŸ³æ•ˆ - // playEffect: function (num, cb) { - // g.snd_mgr.playEffect(this.eff_audio[num], cb); - // }, + // //æ’æ”¾éŸ³æ•ˆ + // playEffect: function (num, cb) { + // g.snd_mgr.playEffect(this.eff_audio[num], cb); + // }, - playEffect: function (num, cb) { - g.snd_mgr.playMusic(this.eff_audio[num], 1, cb); - }, + playEffect: function (num, cb) { + g.snd_mgr.playMusic(this.eff_audio[num], 1, cb); + }, }); diff --git a/assets/NGT_02/script/manager/data_mgr.js b/assets/NGT_02/script/manager/data_mgr.js index 4008caf..d6bba8b 100644 --- a/assets/NGT_02/script/manager/data_mgr.js +++ b/assets/NGT_02/script/manager/data_mgr.js @@ -1,7 +1,7 @@ /** * æ•°æ®ç®¡ç†å™¨ */ -function initDataMgr_NGT_02() { +export function initDataMgr_NGT_02() { g.data_mgr = { data: null, //è¡¨æ‰€æœ‰æ•°æ® diff --git a/assets/NGT_02/script/manager/event_mgr.js b/assets/NGT_02/script/manager/event_mgr.js index 5b57ef4..7c48383 100644 --- a/assets/NGT_02/script/manager/event_mgr.js +++ b/assets/NGT_02/script/manager/event_mgr.js @@ -1,4 +1,4 @@ -function initEventMgr_NGT_02() { +export function initEventMgr_NGT_02() { // 事件汞 let eventList = {}; // å“åº”åˆ—è¡¨ï¼ˆå…ƒç´ ç»“æž„ï¼ševentName,[[target:cb]]) g.event_mgr = { diff --git a/assets/NGT_02/script/manager/local_storage.js b/assets/NGT_02/script/manager/local_storage.js index 32b1d7f..66d4616 100644 --- a/assets/NGT_02/script/manager/local_storage.js +++ b/assets/NGT_02/script/manager/local_storage.js @@ -1,4 +1,4 @@ -function initStorageMgr_NGT_02() { +export function initStorageMgr_NGT_02() { // localStorageå°è£… g.local_storage = { // 背景音ä¹éŸ³é‡ diff --git a/assets/NGT_02/script/manager/res_mgr.js b/assets/NGT_02/script/manager/res_mgr.js index 5da5060..22881bc 100644 --- a/assets/NGT_02/script/manager/res_mgr.js +++ b/assets/NGT_02/script/manager/res_mgr.js @@ -1,4 +1,4 @@ -function initResMgr_NGT_02() { +export function initResMgr_NGT_02() { /** * 资æºç®¡ç†å™¨ */ diff --git a/assets/NGT_02/script/manager/snd_mgr.js b/assets/NGT_02/script/manager/snd_mgr.js index d0d9343..5c1b4fc 100644 --- a/assets/NGT_02/script/manager/snd_mgr.js +++ b/assets/NGT_02/script/manager/snd_mgr.js @@ -1,4 +1,4 @@ -function initSndMgr_NGT_02() { +export function initSndMgr_NGT_02() { // 声音管ç†å™¨ g.snd_mgr = { bgmId: -1, // 背景音ä¹çš„音频ID -- 2.21.0