Commit 4b867d64 authored by LWD's avatar LWD

代码提交

parent 8e892336
// Learn cc.Class: /**
// - https://docs.cocos.com/creator/manual/en/scripting/class.html * 游戏主逻辑
// Learn Attribute: */
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks: var game = cc.Class({
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component, extends: cc.Component,
properties: { properties: {
// foo: { Item: {
// // ATTRIBUTES: default: null,
// default: null, // The default value will be used only when the component attaching type: cc.Node,
// // to a node for the first time displayName: "预制体"
// type: cc.SpriteFrame, // optional, default is typeof default },
// serializable: true, // optional, default is true
// }, contentArr: {
// bar: { default: null,
// get () { type: cc.Node,
// return this._bar; displayName: "Layer"
// }, },
// set (value) {
// this._bar = value; dragonLion: {
// } default: null,
// }, type: dragonBones.ArmatureDisplay,
displayName: "狮子"
},
dragonCat: {
default: null,
type: dragonBones.ArmatureDisplay,
displayName: ""
}
},
ctor: function () {
game.inst = this;
g.game = game;
}, },
// LIFE-CYCLE CALLBACKS: // 生命周期 onLoad
onLoad() {
//初始化游戏
this.initGame();
// onLoad () {}, //监听尺寸变化
if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false)
} else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false)
}
},
//屏幕缩放
scaleEventCallBack: function () {
g.event_mgr.send("adjustUI");
},
//初始化游戏
initGame: function () {
//获得数据
g.res_mgr.getFormData();
},
setAABB() {
var node = this.dragonLion.node;
let svLeftBottomPoint = node.parent.convertToWorldSpaceAR(
cc.v2(
node.x - node.anchorX * node.width / 2,
node.y - node.anchorY * node.height / 2
)
);
// 求出 ScrollView 可视区域在世界坐标系中的矩形(碰撞盒)
let svBBoxRect = cc.rect(
svLeftBottomPoint.x - 300,
svLeftBottomPoint.y - 500,
node.width,
node.height
);
// console.log(Id + ":" + svLeftBottomPoint.x + "," + svLeftBottomPoint.y);
return svBBoxRect
},
//检查当前缩放倍数
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.getQuestionOneList(g.data_mgr.quesId);
itemArr.sort(function () { return Math.random() > 0.5 ? -1 : 1; })
g.data_mgr.nowNum = 0;
for (var i = 0; i < itemArr.length; i++) {
let newItem = cc.instantiate(this.Item);
//更新子项
var com = newItem.getChildByName("item").getComponent("item");
let itemInfo = itemArr[i];
com.updateUI(itemInfo);
newItem.active = true;
if (itemInfo.is_right == true) {
g.data_mgr.nowNum += 1;
}
newItem.getChildByName("item").is_right = itemInfo.is_right;
newItem.parent = this.contentArr;
};
},
//五秒没操作
hintPlay: function () {
// this.playLionDragon("openmouth")
this.playCatDragon("begin")
g.speaker.inst.playEffect(g.enum.E_Audio.CatHint);
for (var i = 0; i < this.contentArr.childrenCount; i++) {
cc.tween(this.contentArr.children[i].children[0])
.to(0.1, { x: -50 })
.to(0.1, { x: 0 })
.to(0.1, { x: 50 })
.to(0.1, { x: 0 })
.start();
}
},
//隐藏剩余物品并跳转下一题
resetQues: function () {
if (g.data_mgr.quesId >= 4) {
this.finish();
g.data_mgr.gameState = 2
} else {
for (var i = 0; i < this.contentArr.childrenCount; i++) {
cc.tween(this.contentArr.children[i].children[0])
.to(0.8, { opacity: 0 })
.start();
}
setTimeout(() => {
this.UpdataUi();
}, 1000);
}
},
//结束
finish() {
this.playLionDragon("normal")
this.playCatDragon("finish")
setTimeout(() => {
g.speaker.inst.playEffect(g.enum.E_Audio.CatComplete);
}, 500)
},
start () { //检测放到哪个节点底下
checkNodeParent: function () {
//获取到总列表
var itemArr = g.data_mgr.getSheepArr();
//
if (itemArr.length <= 7) {
var idx = 1;
} else {
var idx = 0;
}
return idx;
}, },
// update (dt) {}, //检查类别
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;
},
//更新界面信息
UpdataUi: function () {
g.data_mgr.gameState == 1;
var Info = {
tex_json: g.data_mgr.data.tex_json,
ske_json: g.data_mgr.data.ske_json,
tex_png: g.data_mgr.data.tex_png,
}
g.res_mgr.loadSpine(this.dragonLion, Info);
//刚进入课件
//播放第一题题干
//设置俩个人物状态
this.playCatDragon("begin");
this.playLionDragon("normal");
//播放题干
this.playAudioTitle();
// g.speaker.inst.playEffect(E_Audio.BtnCommom);
//重置UI界面
this.resetUI();
//添加项
this.addItem();
// //设置上下页按钮状态
// this.setButtonState();
},
//播放猫动画
playCatDragon(name) {
this.dragonCat.armatureName = "Armature";
this.dragonCat.playAnimation(name);
},
//播放猫动画
playLionDragon(name) {
this.dragonLion.armatureName = "armatureName";
this.dragonLion.playAnimation(name);
},
//播放题干
playAudioTitle: function () {
if (g.data_mgr.quesId >= 4) return
//获得播放路径
var path = g.data_mgr.getQuestionStem(g.data_mgr.quesId);
g.res_mgr.playAudioByUrl(path, (url) => {
g.snd_mgr.playEffect(url, () => {
//结束回调
this.playCatDragon("normal");
});
});
},
//重置UI界面
resetUI: function () {
//移除所有子节点
this.contentArr.removeAllChildren();
},
//重新开始
onBtnReStart: function () {
g.speaker.inst.play_btn();
//移除所有计时器
this.unscheduleAllCallbacks();
//初始化界面
this.UpdataUi();
g.speaker.inst.play_restart();
},
//游戏开始
gameStart: function () {
console.log("游戏开始:" + g.data_mgr);
//播放一个上面的音乐
this.setAudioInfo(1);
},
//设置上下页按钮状态
setButtonState: function () {
//先判断题目长度
if (g.data_mgr.data.contentObj.pageArr.length < 2) {
this.btnList[0].node.active = false;
this.btnList[1].node.active = false;
} else {
//如果第一页
if (g.data_mgr.pageId == 0) {
this.btnList[1].node.active = true;
this.btnList[0].node.active = false;
}
if (g.data_mgr.pageId == g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = false;
}
if (g.data_mgr.pageId > 0 && g.data_mgr.pageId < g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = true;
}
}
},
//下一关
onBtnNextQues: function () {
g.data_mgr.time = 0;
g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom);
g.data_mgr.quesId += 1;
g.game.inst.resetQues();
},
//重新开始
onBtnReStart() {
g.data_mgr.time = 0;
g.data_mgr.resetQuestion();
g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom);
g.data_mgr.quesId = 0;
this.UpdataUi();
},
//上一关
onBtnLastPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId - 1 >= 0) {
g.data_mgr.pageId -= 1;
this.setButtonState();
this.onBtnReStart();
}
},
//下一关
onBtnNextPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId + 1 < g.data_mgr.data.contentObj.pageArr.length) {
g.data_mgr.pageId += 1;
this.setButtonState();
this.onBtnReStart();
}
},
}); });
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "1b3e2d2b-4495-4d36-b3da-c0989df7fa4b", "uuid": "8b0b794c-7f5e-4e94-82b8-d1c85bc69eb8",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
/**
* 游戏主逻辑
*/
var game = cc.Class({
extends: cc.Component,
properties: {
Item: {
default: null,
type: cc.Node,
displayName: "预制体"
},
contentArr: {
default: null,
type: cc.Node,
displayName: "Layer"
},
dragonLion: {
default: null,
type: dragonBones.ArmatureDisplay,
displayName: "狮子"
},
dragonCat: {
default: null,
type: dragonBones.ArmatureDisplay,
displayName: ""
}
// lb_title: {
// default: null,
// type: cc.Label,
// displayName: "大标题"
// },
// btnList: {
// default: [],
// type: cc.Button,
// displayName: "上下页"
// },
},
ctor: function () {
game.inst = this;
g.game = game;
},
// 生命周期 onLoad
onLoad() {
//初始化游戏
this.initGame();
const scheduler = cc.director.getScheduler();
scheduler.enableForTarget(this);
scheduler.schedule(() => {
if (g.data_mgr.gameState == 2) {
return;
}
g.data_mgr.time += 1;
if (g.data_mgr.time >= 10) {
g.data_mgr.time = 0;
this.hintPlay();
}
}, this, 1, cc.macro.REPEAT_FOREVER, 0, false);
//监听尺寸变化
if (window.addEventListener) {
window.addEventListener('resize', this.scaleEventCallBack, false)
} else if (window.attachEvent) {
window.attachEvent('resize', this.scaleEventCallBack, false)
}
},
//屏幕缩放
scaleEventCallBack: function () {
g.event_mgr.send("adjustUI");
},
//初始化游戏
initGame: function () {
//获得数据
g.res_mgr.getFormData();
},
setAABB() {
var node = this.dragonLion.node;
let svLeftBottomPoint = node.parent.convertToWorldSpaceAR(
cc.v2(
node.x - node.anchorX * node.width / 2,
node.y - node.anchorY * node.height / 2
)
);
// 求出 ScrollView 可视区域在世界坐标系中的矩形(碰撞盒)
let svBBoxRect = cc.rect(
svLeftBottomPoint.x - 300,
svLeftBottomPoint.y - 500,
node.width,
node.height
);
// console.log(Id + ":" + svLeftBottomPoint.x + "," + svLeftBottomPoint.y);
return svBBoxRect
},
//检查当前缩放倍数
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.getQuestionOneList(g.data_mgr.quesId);
itemArr.sort(function () { return Math.random() > 0.5 ? -1 : 1; })
g.data_mgr.nowNum = 0;
for (var i = 0; i < itemArr.length; i++) {
let newItem = cc.instantiate(this.Item);
//更新子项
var com = newItem.getChildByName("item").getComponent("item");
let itemInfo = itemArr[i];
com.updateUI(itemInfo);
newItem.active = true;
if (itemInfo.is_right == true) {
g.data_mgr.nowNum += 1;
}
newItem.getChildByName("item").is_right = itemInfo.is_right;
newItem.parent = this.contentArr;
};
},
//五秒没操作
hintPlay: function () {
// this.playLionDragon("openmouth")
this.playCatDragon("begin")
g.speaker.inst.playEffect(g.enum.E_Audio.CatHint);
for (var i = 0; i < this.contentArr.childrenCount; i++) {
cc.tween(this.contentArr.children[i].children[0])
.to(0.1, { x: -50 })
.to(0.1, { x: 0 })
.to(0.1, { x: 50 })
.to(0.1, { x: 0 })
.start();
}
},
//隐藏剩余物品并跳转下一题
resetQues: function () {
if (g.data_mgr.quesId >= 4) {
this.finish();
g.data_mgr.gameState = 2
} else {
for (var i = 0; i < this.contentArr.childrenCount; i++) {
cc.tween(this.contentArr.children[i].children[0])
.to(0.8, { opacity: 0 })
.start();
}
setTimeout(() => {
this.UpdataUi();
}, 1000);
}
},
//结束
finish() {
this.playLionDragon("normal")
this.playCatDragon("finish")
setTimeout(() => {
g.speaker.inst.playEffect(g.enum.E_Audio.CatComplete);
}, 500)
},
//检测放到哪个节点底下
checkNodeParent: function () {
//获取到总列表
var itemArr = g.data_mgr.getSheepArr();
//
if (itemArr.length <= 7) {
var idx = 1;
} else {
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;
},
//更新界面信息
UpdataUi: function () {
var Info = {
tex_json: g.data_mgr.data.tex_json,
ske_json: g.data_mgr.data.ske_json,
tex_png: g.data_mgr.data.tex_png,
}
g.res_mgr.loadSpine(this.dragonLion, Info);
//刚进入课件
//播放第一题题干
//设置俩个人物状态
this.playCatDragon("begin");
this.playLionDragon("normal");
//播放题干
this.playAudioTitle();
// g.speaker.inst.playEffect(E_Audio.BtnCommom);
//重置UI界面
this.resetUI();
//添加项
this.addItem();
// //设置上下页按钮状态
// this.setButtonState();
},
//播放猫动画
playCatDragon(name) {
this.dragonCat.armatureName = "Armature";
this.dragonCat.playAnimation(name);
},
//播放猫动画
playLionDragon(name) {
this.dragonLion.armatureName = "armatureName";
this.dragonLion.playAnimation(name);
},
//播放题干
playAudioTitle: function () {
if (g.data_mgr.quesId >= 4) return
//获得播放路径
var path = g.data_mgr.getQuestionStem(g.data_mgr.quesId);
g.res_mgr.playAudioByUrl(path, (url) => {
g.snd_mgr.playEffect(url, () => {
//结束回调
this.playCatDragon("normal");
});
});
},
//重置UI界面
resetUI: function () {
//移除所有子节点
this.contentArr.removeAllChildren();
},
//重新开始
onBtnReStart: function () {
g.speaker.inst.play_btn();
//移除所有计时器
this.unscheduleAllCallbacks();
//初始化界面
this.UpdataUi();
g.speaker.inst.play_restart();
},
//游戏开始
gameStart: function () {
console.log("游戏开始:" + g.data_mgr);
//播放一个上面的音乐
this.setAudioInfo(1);
},
//设置上下页按钮状态
setButtonState: function () {
//先判断题目长度
if (g.data_mgr.data.contentObj.pageArr.length < 2) {
this.btnList[0].node.active = false;
this.btnList[1].node.active = false;
} else {
//如果第一页
if (g.data_mgr.pageId == 0) {
this.btnList[1].node.active = true;
this.btnList[0].node.active = false;
}
if (g.data_mgr.pageId == g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = false;
}
if (g.data_mgr.pageId > 0 && g.data_mgr.pageId < g.data_mgr.data.contentObj.pageArr.length - 1) {
this.btnList[0].node.active = true;
this.btnList[1].node.active = true;
}
}
},
//下一关
onBtnNextQues: function () {
g.data_mgr.time = 0;
g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom);
g.data_mgr.quesId += 1;
g.game.inst.resetQues();
},
//重新开始
onBtnReStart() {
g.data_mgr.time = 0;
g.data_mgr.resetQuestion();
g.speaker.inst.playEffect(g.enum.E_Audio.BtnCommom);
g.data_mgr.quesId = 0;
this.UpdataUi();
},
//上一关
onBtnLastPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId - 1 >= 0) {
g.data_mgr.pageId -= 1;
this.setButtonState();
this.onBtnReStart();
}
},
//下一关
onBtnNextPage: function () {
g.speaker.inst.play_btn();
if (g.data_mgr.pageId + 1 < g.data_mgr.data.contentObj.pageArr.length) {
g.data_mgr.pageId += 1;
this.setButtonState();
this.onBtnReStart();
}
},
});
{
"ver": "1.0.8",
"uuid": "8b0b794c-7f5e-4e94-82b8-d1c85bc69eb8",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -6,7 +6,7 @@ g.data_mgr = { ...@@ -6,7 +6,7 @@ g.data_mgr = {
quesId: 0,//题目id quesId: 0,//题目id
nowNum: 0,//剩余正确数量 nowNum: 0,//剩余正确数量
gameState: 0,//游戏状态1可操作 2不可操作 gameState: 2,//游戏状态1可操作 2不可操作
time: 0, time: 0,
//获得默认数据 //获得默认数据
...@@ -151,6 +151,18 @@ g.data_mgr = { ...@@ -151,6 +151,18 @@ g.data_mgr = {
//更新游戏界面信息 //更新游戏界面信息
g.game.inst.UpdataUi(); g.game.inst.UpdataUi();
clearInterval(this.timer)
this.timer = setInterval(() => {
if (g.data_mgr.gameState == 2) {
return;
}
g.data_mgr.time += 1;
if (g.data_mgr.time >= 10) {
g.data_mgr.time = 0;
g.game.inst.hintPlay();
}
}, 1000)
g.game.inst.isLoadEnd = true; g.game.inst.isLoadEnd = true;
}, },
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment