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

feat: global问题

parent 181499e2
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;
},
......
import { initGlobal_NGT_02 } from "../script/common/_preDefine";
/**
* 游戏主逻辑
*/
......@@ -8,8 +10,8 @@ var game = cc.Class({
btnRestart: {
default: null,
type: cc.Node,
displayName: "重开按钮"
}
displayName: "重开按钮",
},
},
ctor: function () {
......@@ -23,9 +25,9 @@ var game = cc.Class({
//初始化游戏
this.initGame();
if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false)
window.addEventListener("resize", this.scaleEventCallBack, false);
} else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false)
window.attachEvent("resize", this.scaleEventCallBack, false);
}
cc.debug.setDisplayStats(false);
},
......@@ -52,10 +54,10 @@ var game = cc.Class({
checkScale: function (num) {
var scale = 1;
if (num > 2 && num <= 4) {
scale = 0.74
scale = 0.74;
}
if (num > 4) {
scale = 0.65
scale = 0.65;
}
return scale;
},
......@@ -66,8 +68,9 @@ var game = cc.Class({
this.idx = this.checkNodeParent();
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]);
......@@ -78,11 +81,12 @@ var game = cc.Class({
newItem_0.active = true;
//设置类别
let sheepInfo = g.data_mgr.getSheep(i);
newItem_0.getChildByName("item").type = this.checkType(sheepInfo.sheepfoldId);
newItem_0.getChildByName("item").type = this.checkType(
sheepInfo.sheepfoldId
);
newItem_0.parent = this.contentArr_2[this.idx];
};
}
},
//检测放到哪个节点底下
......@@ -136,7 +140,8 @@ var game = cc.Class({
//初始化单个题目
InitQuestion() {
var question = g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId]
var question =
g.data_mgr.data.starArr[g.data_mgr.startId].queArr[g.data_mgr.ansId];
//初始化灯
g.Light.inst.addLightNum(question.hotZoneItemArr.length);
//初始化标题
......@@ -145,7 +150,7 @@ var game = cc.Class({
g.data_mgr.gameState = 2;
setTimeout(() => {
g.titleType.inst.onBtnPlayEffect();
}, 500)
}, 500);
}
//设置中间图片
g.picNode.inst.onShow(question);
......@@ -161,7 +166,10 @@ var game = cc.Class({
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) {
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();
......@@ -173,19 +181,20 @@ var game = cc.Class({
g.speaker.inst.playEffect(g.enum.E_Audio.Flowers);
g.effect.inst.showEffect2();
this.btnRestart.active = true;
const middleLayer = cc.find('middleLayer');
const middleLayer = cc.find("middleLayer");
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
if (middleLayerComponent.role == 'student') {
middleLayerComponent.onHomeworkFinish(() => { });
const middleLayerComponent =
middleLayer.getComponent("middleLayer");
if (middleLayerComponent.role == "student") {
middleLayerComponent.onHomeworkFinish(() => {});
}
} else {
console.log('onHomeworkFinish');
console.log("onHomeworkFinish");
}
} else {
this.InitQuestion();
}
}, 1500)
}, 1500);
}
},
......@@ -223,45 +232,35 @@ var game = cc.Class({
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]
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)
var isIntersect = AABB.containsRect(callerAABB); //判断是否被包含
console.log(isIntersect);
if (isIntersect) {
return nodOption;
}
return false
return false;
}
}
},
getCallerAABB(caller) {
let svLeftBottomPoint = caller.parent.convertToWorldSpaceAR(
cc.v2(
caller.x,
caller.y
)
cc.v2(caller.x, caller.y)
);
var posNode_1 = cc.rect(
svLeftBottomPoint.x,
svLeftBottomPoint.y,
0,
0
);
return posNode_1
var posNode_1 = cc.rect(svLeftBottomPoint.x, svLeftBottomPoint.y, 0, 0);
return posNode_1;
},
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');
if (!window.g) {
window.g = {};
initDataMgr_NGT_02();
initEventMgr_NGT_02();
......@@ -8,4 +16,6 @@ function initGlobal_NGT_02() {
initResMgr_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 = {
// 范围随机
randFromTo: function (_min, _max) {
......@@ -42,16 +42,17 @@ function initUtils_NGT_02() {
}
},
};
}
export function getPosByAngle(angle, len) {
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 getAngleByPos(px, py, mx, my) {
export function getAngleByPos(px, py, mx, my) {
const x = Math.abs(px - mx);
const y = Math.abs(py - my);
......@@ -87,27 +88,25 @@ function initUtils_NGT_02() {
// console.log('angle: ', angle);
return angle;
}
}
export function exchangeNodePos(baseNode, targetNode) {
export function exchangeNodePos(baseNode, targetNode) {
return baseNode.convertToNodeSpaceAR(
targetNode._parent.convertToWorldSpaceAR(
cc.v2(targetNode.x, targetNode.y)
)
targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y))
);
}
}
export function RandomInt(a, b = 0) {
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);
}
}
export function Between(a, b, c) {
export function Between(a, b, c) {
return [a, b, c].sort((a, b) => a - b)[1];
}
}
export function randomSortByArr(arr) {
export function randomSortByArr(arr) {
const newArr = [];
const tmpArr = arr.concat();
while (tmpArr.length > 0) {
......@@ -116,9 +115,9 @@ function initUtils_NGT_02() {
tmpArr.splice(randomIndex, 1);
}
return newArr;
}
}
export async function asyncTweenTo(node, duration, obj, ease = undefined) {
export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(duration, obj, ease)
......@@ -127,9 +126,9 @@ function initUtils_NGT_02() {
})
.start();
});
}
}
export async function asyncTweenBy(node, duration, obj, ease = undefined) {
export async function asyncTweenBy(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.by(duration, obj, ease)
......@@ -138,14 +137,14 @@ function initUtils_NGT_02() {
})
.start();
});
}
}
export async function asyncPlayDragonBoneAnimation(
export async function asyncPlayDragonBoneAnimation(
node,
animationName,
time = 1,
onFrameEvent
) {
) {
return new Promise((resolve, reject) => {
node
.getComponent(dragonBones.ArmatureDisplay)
......@@ -165,9 +164,9 @@ function initUtils_NGT_02() {
.getComponent(dragonBones.ArmatureDisplay)
.playAnimation(animationName, time);
});
}
}
export async function asyncPlayEffectByUrl(url, loop = false) {
export async function asyncPlayEffectByUrl(url, loop = false) {
return new Promise((resolve, reject) => {
cc.assetManager.loadRemote(url, (err, clip) => {
console.log(clip);
......@@ -175,9 +174,9 @@ function initUtils_NGT_02() {
resolve();
});
});
}
}
export async function jelly(node) {
export async function jelly(node) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
......@@ -186,24 +185,24 @@ function initUtils_NGT_02() {
.call(resolve)
.start();
});
}
}
export async function asyncDelay(time) {
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, time * 1000);
});
}
}
export async function showFireworks(
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;
......@@ -257,12 +256,11 @@ function initUtils_NGT_02() {
})
.start();
});
}
}
async function 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);
}
}
g.enum = {
export function initEnumMgr_NGT_02() {
g.enum = {
E_Audio: {
Star: 0,//大星星
BtnCommom: 1,//按钮
Flowers: 2,//撒花
Right: 3,//正确
Error: 4,//错误
Question: 5,//题数
}
Star: 0, //大星星
BtnCommom: 1, //按钮
Flowers: 2, //撒花
Right: 3, //正确
Error: 4, //错误
Question: 5, //题数
},
};
}
/**
* 音效
......@@ -19,7 +21,7 @@ var speaker = cc.Class({
eff_audio: {
default: [],
type: cc.AudioClip,
displayName: "音效列表"
displayName: "音效列表",
},
},
......
/**
* 数据管理器
*/
function initDataMgr_NGT_02() {
export function initDataMgr_NGT_02() {
g.data_mgr = {
data: null, //表所有数据
......
function initEventMgr_NGT_02() {
export function initEventMgr_NGT_02() {
// 事件汞
let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]])
g.event_mgr = {
......
function initStorageMgr_NGT_02() {
export function initStorageMgr_NGT_02() {
// localStorage封装
g.local_storage = {
// 背景音乐音量
......
function initResMgr_NGT_02() {
export function initResMgr_NGT_02() {
/**
* 资源管理器
*/
......
function initSndMgr_NGT_02() {
export function initSndMgr_NGT_02() {
// 声音管理器
g.snd_mgr = {
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