Commit 396d96dd authored by 范雪寒's avatar 范雪寒

feat: global问题

parent 181499e2
const tools = require("../script/tools"); const tools = require("../script/tools");
import { initGlobal_NGT_02 } from "../../script/common/_preDefine";
var picNode = cc.Class({ var picNode = cc.Class({
extends: cc.Component, extends: cc.Component,
...@@ -12,6 +14,7 @@ var picNode = cc.Class({ ...@@ -12,6 +14,7 @@ var picNode = cc.Class({
}, },
ctor: function () { ctor: function () {
initGlobal_NGT_02();
picNode.inst = this; picNode.inst = this;
g.picNode = picNode; g.picNode = picNode;
}, },
......
import { initGlobal_NGT_02 } from "../script/common/_preDefine";
/** /**
* 游戏主逻辑 * 游戏主逻辑
*/ */
var game = cc.Class({ var game = cc.Class({
extends: cc.Component, extends: cc.Component,
properties: { properties: {
btnRestart: { btnRestart: {
default: null, default: null,
type: cc.Node, type: cc.Node,
displayName: "重开按钮" displayName: "重开按钮",
} },
}, },
ctor: function () { ctor: function () {
initGlobal_NGT_02(); initGlobal_NGT_02();
game.inst = this; game.inst = this;
g.game = game; g.game = game;
}, },
// 生命周期 onLoad // 生命周期 onLoad
onLoad() { onLoad() {
//初始化游戏 //初始化游戏
this.initGame(); this.initGame();
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false) window.addEventListener("resize", this.scaleEventCallBack, false);
} else if (window.attachEvent) { } else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false) window.attachEvent("resize", this.scaleEventCallBack, false);
} }
cc.debug.setDisplayStats(false); cc.debug.setDisplayStats(false);
}, },
//屏幕缩放 //屏幕缩放
scaleEventCallBack: function () { scaleEventCallBack: function () {
g.event_mgr.send("adjustUI"); g.event_mgr.send("adjustUI");
}, },
//初始化游戏 //初始化游戏
initGame: function () { initGame: function () {
//获得数据 //获得数据
g.res_mgr.getFormData(); g.res_mgr.getFormData();
}, },
onBtnTest() { onBtnTest() {
g.Light.inst.addLightNum(3); g.Light.inst.addLightNum(3);
}, },
onBtnTest2() { onBtnTest2() {
g.Light.inst.showLight(); g.Light.inst.showLight();
}, },
//检查当前缩放倍数 //检查当前缩放倍数
checkScale: function (num) { checkScale: function (num) {
var scale = 1; var scale = 1;
if (num > 2 && num <= 4) { if (num > 2 && num <= 4) {
scale = 0.74 scale = 0.74;
} }
if (num > 4) { if (num > 4) {
scale = 0.65 scale = 0.65;
} }
return scale; return scale;
}, },
//添加节点 //添加节点
addItem: function () { addItem: function () {
let itemArr = g.data_mgr.getSheepArr(); let itemArr = g.data_mgr.getSheepArr();
this.idx = this.checkNodeParent(); this.idx = this.checkNodeParent();
g.data_mgr.nowNum = itemArr.length; g.data_mgr.nowNum = itemArr.length;
itemArr.sort(function () { return Math.random() > 0.5 ? -1 : 1; }) 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]); 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]; var com = newItem_0.getChildByName("item").getComponent("item");
com.updateUI(itemInfo); let itemInfo = itemArr[i];
newItem_0.active = true; com.updateUI(itemInfo);
//设置类别 newItem_0.active = true;
let sheepInfo = g.data_mgr.getSheep(i); //设置类别
newItem_0.getChildByName("item").type = this.checkType(sheepInfo.sheepfoldId); let sheepInfo = g.data_mgr.getSheep(i);
newItem_0.getChildByName("item").type = this.checkType(
sheepInfo.sheepfoldId
newItem_0.parent = this.contentArr_2[this.idx]; );
};
}, newItem_0.parent = this.contentArr_2[this.idx];
}
//检测放到哪个节点底下 },
checkNodeParent: function () {
//获取到总列表 //检测放到哪个节点底下
var itemArr = g.data_mgr.getSheepArr(); checkNodeParent: function () {
//获取到总列表
// var itemArr = g.data_mgr.getSheepArr();
if (itemArr.length <= 7) {
this.contentArr_2[1].active = true; //
var idx = 1; if (itemArr.length <= 7) {
} else { this.contentArr_2[1].active = true;
this.contentArr_2[0].active = true; var idx = 1;
var idx = 0; } else {
} this.contentArr_2[0].active = true;
return idx; var idx = 0;
}, }
return idx;
//检查类别 },
checkType: function (Id) {
for (var i in g.data_mgr.getSheepfoldArr()) { //检查类别
var sheepfoldInfo = g.data_mgr.getSheepfoldArr()[i]; checkType: function (Id) {
if (Id == sheepfoldInfo.id) { for (var i in g.data_mgr.getSheepfoldArr()) {
return ~~i + 1; var sheepfoldInfo = g.data_mgr.getSheepfoldArr()[i];
} if (Id == sheepfoldInfo.id) {
} return ~~i + 1;
return -1; }
}, }
return -1;
//设置目标节点类型 },
setOptionType: function () {
//设置类型 //设置目标节点类型
this.OptionType = g.data_mgr.getSheepfoldArr().length - 3; setOptionType: function () {
}, //设置类型
this.OptionType = g.data_mgr.getSheepfoldArr().length - 3;
getOptionType: function () { },
return this.OptionType;
}, getOptionType: function () {
return this.OptionType;
//更新界面信息 },
UpdataUi: function () {
this.btnRestart.active = false; //更新界面信息
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; g.scoreStart.inst.addStar(g.data_mgr.data.starArr.length);
//初始化单题题目 g.data_mgr.ansId = 0;
this.InitQuestion(); g.data_mgr.startId = 0;
}, //初始化单题题目
this.InitQuestion();
//初始化单个题目 },
InitQuestion() {
var question = g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId] //初始化单个题目
//初始化灯 InitQuestion() {
g.Light.inst.addLightNum(question.hotZoneItemArr.length); var question =
//初始化标题 g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId];
g.titleType.inst.showTitle(question.title, question.title_audio_url); //初始化灯
if (question.title_audio_url) { g.Light.inst.addLightNum(question.hotZoneItemArr.length);
g.data_mgr.gameState = 2; //初始化标题
setTimeout(() => { g.titleType.inst.showTitle(question.title, question.title_audio_url);
g.titleType.inst.onBtnPlayEffect(); if (question.title_audio_url) {
}, 500) g.data_mgr.gameState = 2;
} setTimeout(() => {
//设置中间图片 g.titleType.inst.onBtnPlayEffect();
g.picNode.inst.onShow(question); }, 500);
}, }
//设置中间图片
onBtnCheck() { 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) { //灯+1
g.data_mgr.ansId += 1; g.speaker.inst.playEffect(g.enum.E_Audio.Right);
if (g.data_mgr.ansId >= g.data_mgr.data.starArr[g.data_mgr.startId].queArr.length) { let num = g.Light.inst.showLight();
//大星星音效 if (num == -1) {
g.speaker.inst.playEffect(g.enum.E_Audio.Star); g.data_mgr.ansId += 1;
g.scoreStart.inst.showStar(); if (
g.data_mgr.ansId = 0; g.data_mgr.ansId >=
g.data_mgr.startId += 1; g.data_mgr.data.starArr[g.data_mgr.startId].queArr.length
} ) {
setTimeout(() => { //大星星音效
if (g.data_mgr.startId >= g.data_mgr.data.starArr.length) { g.speaker.inst.playEffect(g.enum.E_Audio.Star);
g.speaker.inst.playEffect(g.enum.E_Audio.Flowers); g.scoreStart.inst.showStar();
g.effect.inst.showEffect2(); g.data_mgr.ansId = 0;
this.btnRestart.active = true; g.data_mgr.startId += 1;
const middleLayer = cc.find('middleLayer'); }
if (middleLayer) { setTimeout(() => {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); if (g.data_mgr.startId >= g.data_mgr.data.starArr.length) {
if (middleLayerComponent.role == 'student') { g.speaker.inst.playEffect(g.enum.E_Audio.Flowers);
middleLayerComponent.onHomeworkFinish(() => { }); g.effect.inst.showEffect2();
} this.btnRestart.active = true;
} else { const middleLayer = cc.find("middleLayer");
console.log('onHomeworkFinish'); if (middleLayer) {
} const middleLayerComponent =
} else { middleLayer.getComponent("middleLayer");
this.InitQuestion(); if (middleLayerComponent.role == "student") {
} middleLayerComponent.onHomeworkFinish(() => {});
}, 1500) }
} } else {
}, console.log("onHomeworkFinish");
}
//播放标题音效 } else {
playAudioTitle: function () { this.InitQuestion();
//获得播放路径 }
var path = g.data_mgr.data.audio_url; }, 1500);
g.res_mgr.playAudioByUrl(path, (url) => { }
g.snd_mgr.playEffect(url, null); },
});
}, //播放标题音效
playAudioTitle: function () {
//重置UI界面 //获得播放路径
resetUI: function () { var path = g.data_mgr.data.audio_url;
//移除所有子节点 g.res_mgr.playAudioByUrl(path, (url) => {
this.contentArr_2[0].removeAllChildren(); g.snd_mgr.playEffect(url, null);
this.contentArr_2[1].removeAllChildren(); });
//移除所有子节点 },
g.event_mgr.send("reSetGame");
}, //重置UI界面
resetUI: function () {
//重新开始 //移除所有子节点
onBtnReStart: function () { this.contentArr_2[0].removeAllChildren();
g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom); this.contentArr_2[1].removeAllChildren();
//移除所有计时器 //移除所有子节点
this.unscheduleAllCallbacks(); g.event_mgr.send("reSetGame");
//初始化界面 },
this.UpdataUi();
}, //重新开始
onBtnReStart: function () {
//游戏开始 g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom);
gameStart: function () { //移除所有计时器
console.log("游戏开始:" + g.data_mgr); this.unscheduleAllCallbacks();
//播放一个上面的音乐 //初始化界面
this.setAudioInfo(1); this.UpdataUi();
}, },
//游戏开始
checkAnswer(caller, option_i) { gameStart: function () {
if (caller == undefined) { console.log("游戏开始:" + g.data_mgr);
return; //播放一个上面的音乐
} this.setAudioInfo(1);
},
if (option_i != -1) {
let nodOption = this.contType[this.OptionType].children[option_i - 1] checkAnswer(caller, option_i) {
if (nodOption) { if (caller == undefined) {
return;
let AABB = nodOption.getComponent("DragGameOptionObject").setAABB(); }
let callerAABB = this.getCallerAABB(caller);
var isIntersect = AABB.containsRect(callerAABB);//判断是否被包含 if (option_i != -1) {
console.log(isIntersect) let nodOption = this.contType[this.OptionType].children[option_i - 1];
if (isIntersect) { if (nodOption) {
return nodOption; let AABB = nodOption.getComponent("DragGameOptionObject").setAABB();
} let callerAABB = this.getCallerAABB(caller);
return false var isIntersect = AABB.containsRect(callerAABB); //判断是否被包含
} console.log(isIntersect);
} if (isIntersect) {
}, return nodOption;
}
getCallerAABB(caller) { return false;
let svLeftBottomPoint = caller.parent.convertToWorldSpaceAR( }
cc.v2( }
caller.x, },
caller.y
) getCallerAABB(caller) {
); let svLeftBottomPoint = caller.parent.convertToWorldSpaceAR(
var posNode_1 = cc.rect( cc.v2(caller.x, caller.y)
svLeftBottomPoint.x, );
svLeftBottomPoint.y, var posNode_1 = cc.rect(svLeftBottomPoint.x, svLeftBottomPoint.y, 0, 0);
0, return posNode_1;
0 },
);
return posNode_1 onDestroy() {
}, window.g = null;
},
onDestroy() {
window.g = null;
}
}); });
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'); console.log('window.g init');
window.g = {}; if (!window.g) {
initDataMgr_NGT_02(); window.g = {};
initEventMgr_NGT_02(); initDataMgr_NGT_02();
initStorageMgr_NGT_02(); initEventMgr_NGT_02();
initResMgr_NGT_02(); initStorageMgr_NGT_02();
initSndMgr_NGT_02(); initResMgr_NGT_02();
initUtils_NGT_02(); initSndMgr_NGT_02();
initUtils_NGT_02();
initEnumMgr_NGT_02();
}
} }
\ No newline at end of file
function initUtils_NGT_02() { export function initUtils_NGT_02() {
g.utils = { g.utils = {
// 范围随机 // 范围随机
randFromTo: function (_min, _max) { randFromTo: function (_min, _max) {
...@@ -42,227 +42,225 @@ function initUtils_NGT_02() { ...@@ -42,227 +42,225 @@ function initUtils_NGT_02() {
} }
}, },
}; };
}
export function getPosByAngle(angle, len) { export function getPosByAngle(angle, len) {
const radian = (angle * Math.PI) / 180; const radian = (angle * Math.PI) / 180;
const x = Math.sin(radian) * len; const x = Math.sin(radian) * len;
const y = Math.cos(radian) * len; const y = Math.cos(radian) * len;
return { x, y };
}
export function getAngleByPos(px, py, mx, my) { return { x, y };
const x = Math.abs(px - mx); }
const y = Math.abs(py - my);
const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); export function getAngleByPos(px, py, mx, my) {
const cos = y / z; const x = Math.abs(px - mx);
const radina = Math.acos(cos); // 用反三角函数求弧度 const y = Math.abs(py - my);
let angle = Math.floor((180 / (Math.PI / radina)) * 100) / 100; // 将弧度转换成角度
if (mx > px && my > py) { const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
// 鼠标在第四象限 const cos = y / z;
angle = 180 - angle; const radina = Math.acos(cos); // 用反三角函数求弧度
} let angle = Math.floor((180 / (Math.PI / radina)) * 100) / 100; // 将弧度转换成角度
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;
}
// console.log('angle: ', angle); if (mx > px && my > py) {
return angle; // 鼠标在第四象限
angle = 180 - angle;
} }
if (mx === px && my > py) {
export function exchangeNodePos(baseNode, targetNode) { // 鼠标在y轴负方向上
return baseNode.convertToNodeSpaceAR( angle = 180;
targetNode._parent.convertToWorldSpaceAR(
cc.v2(targetNode.x, targetNode.y)
)
);
} }
if (mx > px && my === py) {
export function RandomInt(a, b = 0) { // 鼠标在x轴正方向上
let max = Math.max(a, b); angle = 90;
let min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
} }
if (mx < px && my > py) {
export function Between(a, b, c) { // 鼠标在第三象限
return [a, b, c].sort((a, b) => a - b)[1]; angle = 180 + angle;
} }
if (mx < px && my === py) {
export function randomSortByArr(arr) { // 鼠标在x轴负方向
const newArr = []; angle = 270;
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) {
export async function asyncTweenTo(node, duration, obj, ease = undefined) { // 鼠标在第二象限
return new Promise((resolve, reject) => { angle = 360 - angle;
cc.tween(node)
.to(duration, obj, ease)
.call(() => {
resolve();
})
.start();
});
} }
export async function asyncTweenBy(node, duration, obj, ease = undefined) { // console.log('angle: ', angle);
return new Promise((resolve, reject) => { return angle;
cc.tween(node) }
.by(duration, obj, ease)
.call(() => { export function exchangeNodePos(baseNode, targetNode) {
resolve(); return baseNode.convertToNodeSpaceAR(
}) targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y))
.start(); );
}); }
}
export async function asyncPlayDragonBoneAnimation( export function RandomInt(a, b = 0) {
node, let max = Math.max(a, b);
animationName, let min = Math.min(a, b);
time = 1, return Math.floor(Math.random() * (max - min) + min);
onFrameEvent }
) {
return new Promise((resolve, reject) => {
node
.getComponent(dragonBones.ArmatureDisplay)
.once(dragonBones.EventObject.COMPLETE, () => {
resolve();
});
node export function Between(a, b, c) {
.getComponent(dragonBones.ArmatureDisplay) return [a, b, c].sort((a, b) => a - b)[1];
.on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => { }
if (onFrameEvent && typeof onFrameEvent == "function") {
onFrameEvent(name);
}
});
node export function randomSortByArr(arr) {
.getComponent(dragonBones.ArmatureDisplay) const newArr = [];
.playAnimation(animationName, time); 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) { export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
cc.assetManager.loadRemote(url, (err, clip) => { cc.tween(node)
console.log(clip); .to(duration, obj, ease)
cc.audioEngine.playEffect(clip, loop); .call(() => {
resolve(); resolve();
}); })
}); .start();
} });
}
export async function jelly(node) { export async function asyncTweenBy(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
cc.tween(node) cc.tween(node)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 }) .by(duration, obj, ease)
.to(0.1, { scaleX: 1.1, scaleY: 0.9 }) .call(() => {
.to(0.1, { scaleX: 1, scaleY: 1 }) resolve();
.call(resolve) })
.start(); .start();
}); });
} }
export async function asyncDelay(time) { export async function asyncPlayDragonBoneAnimation(
return new Promise((resolve, reject) => { node,
setTimeout(() => { animationName,
time = 1,
onFrameEvent
) {
return new Promise((resolve, reject) => {
node
.getComponent(dragonBones.ArmatureDisplay)
.once(dragonBones.EventObject.COMPLETE, () => {
resolve(); 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( export async function jelly(node) {
baseNode, return new Promise((resolve, reject) => {
nodeList, cc.tween(node)
pos = cc.v2(0, 0), .to(0.1, { scaleX: 0.9, scaleY: 1.1 })
side = cc.v2(0, 100), .to(0.1, { scaleX: 1.1, scaleY: 0.9 })
range = 50, .to(0.1, { scaleX: 1, scaleY: 1 })
number = 100 .call(resolve)
) { .start();
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;
let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]); export async function asyncDelay(time) {
node.parent = rabbonNode; return new Promise((resolve, reject) => {
node.active = true; setTimeout(() => {
node.x = 0; resolve();
node.y = 0; }, time * 1000);
node.angle = 0; });
}
const rate = Math.random(); export async function showFireworks(
const angle = Math.PI * (Math.random() * 2 - 1); 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( let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
rabbonNode, node.parent = rabbonNode;
0.3, node.active = true;
{ node.x = 0;
x: side.x * rate + Math.cos(angle) * range * rate, node.y = 0;
y: side.y * rate + Math.sin(angle) * range * rate, node.angle = 0;
},
{ const rate = Math.random();
easing: "quadIn", 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()); await asyncDelay(Math.random());
cc.tween(node) cc.tween(node)
.by(0.15, { x: -10, angle: -10 }) .by(0.15, { x: -10, angle: -10 })
.by(0.3, { x: 20, angle: 20 }) .by(0.3, { x: 20, angle: 20 })
.by(0.15, { x: -10, angle: -10 }) .by(0.15, { x: -10, angle: -10 })
.union() .union()
.repeatForever() .repeatForever()
.start(); .start();
cc.tween(rabbonNode) cc.tween(rabbonNode)
.delay(5) .delay(5)
.to(0.3, { opacity: 0 }) .to(0.3, { opacity: 0 })
.call(() => { .call(() => {
node.stopAllActions(); node.stopAllActions();
node.active = false; node.active = false;
node.parent = null; node.parent = null;
node = null; node = null;
}) })
.start(); .start();
}); });
} }
async function rabbonFall(node) { async function rabbonFall(node) {
const time = 1 + Math.random(); const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time; const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: (offsetX * 60) / 200 }); await asyncTweenBy(node, time, { x: offsetX, angle: (offsetX * 60) / 200 });
rabbonFall(node); rabbonFall(node);
}
} }
g.enum = { export function initEnumMgr_NGT_02() {
E_Audio: { g.enum = {
Star: 0,//大星星 E_Audio: {
BtnCommom: 1,//按钮 Star: 0, //大星星
Flowers: 2,//撒花 BtnCommom: 1, //按钮
Right: 3,//正确 Flowers: 2, //撒花
Error: 4,//错误 Right: 3, //正确
Question: 5,//题数 Error: 4, //错误
} Question: 5, //题数
},
};
} }
/** /**
* 音效 * 音效
*/ */
var speaker = cc.Class({ var speaker = cc.Class({
extends: cc.Component, extends: cc.Component,
properties: { properties: {
eff_audio: { eff_audio: {
default: [], default: [],
type: cc.AudioClip, type: cc.AudioClip,
displayName: "音效列表" displayName: "音效列表",
}, },
}, },
ctor: function () { ctor: function () {
speaker.inst = this; speaker.inst = this;
g.speaker = speaker; g.speaker = speaker;
}, },
// //播放音效 // //播放音效
// playEffect: function (num, cb) { // playEffect: function (num, cb) {
// g.snd_mgr.playEffect(this.eff_audio[num], cb); // g.snd_mgr.playEffect(this.eff_audio[num], cb);
// }, // },
playEffect: function (num, cb) { playEffect: function (num, cb) {
g.snd_mgr.playMusic(this.eff_audio[num], 1, cb); g.snd_mgr.playMusic(this.eff_audio[num], 1, cb);
}, },
}); });
/** /**
* 数据管理器 * 数据管理器
*/ */
function initDataMgr_NGT_02() { export function initDataMgr_NGT_02() {
g.data_mgr = { g.data_mgr = {
data: null, //表所有数据 data: null, //表所有数据
......
function initEventMgr_NGT_02() { export function initEventMgr_NGT_02() {
// 事件汞 // 事件汞
let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]]) let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]])
g.event_mgr = { g.event_mgr = {
......
function initStorageMgr_NGT_02() { export function initStorageMgr_NGT_02() {
// localStorage封装 // localStorage封装
g.local_storage = { g.local_storage = {
// 背景音乐音量 // 背景音乐音量
......
function initResMgr_NGT_02() { export function initResMgr_NGT_02() {
/** /**
* 资源管理器 * 资源管理器
*/ */
......
function initSndMgr_NGT_02() { export function initSndMgr_NGT_02() {
// 声音管理器 // 声音管理器
g.snd_mgr = { g.snd_mgr = {
bgmId: -1, // 背景音乐的音频ID bgmId: -1, // 背景音乐的音频ID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment