Commit e9739239 authored by 李维's avatar 李维

添加随机题目和宝石移动到袋子里动画

parent d8c1d017
...@@ -87,28 +87,28 @@ ...@@ -87,28 +87,28 @@
"__id__": 161 "__id__": 161
}, },
{ {
"__id__": 168 "__id__": 172
}, },
{ {
"__id__": 170 "__id__": 174
}, },
{ {
"__id__": 171 "__id__": 175
}, },
{ {
"__id__": 172 "__id__": 176
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 180 "__id__": 184
}, },
{ {
"__id__": 181 "__id__": 185
}, },
{ {
"__id__": 182 "__id__": 186
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8027,7 +8027,7 @@ ...@@ -8027,7 +8027,7 @@
"__id__": 162 "__id__": 162
}, },
{ {
"__id__": 165 "__id__": 167
} }
], ],
"_active": true, "_active": true,
...@@ -8090,6 +8090,9 @@ ...@@ -8090,6 +8090,9 @@
"_children": [ "_children": [
{ {
"__id__": 163 "__id__": 163
},
{
"__id__": 165
} }
], ],
"_active": true, "_active": true,
...@@ -8237,6 +8240,101 @@ ...@@ -8237,6 +8240,101 @@
"_N$cacheMode": 0, "_N$cacheMode": 0,
"_id": "4bnxvel6VKNL1Fhw3cWUkS" "_id": "4bnxvel6VKNL1Fhw3cWUkS"
}, },
{
"__type__": "cc.Node",
"_name": "bag",
"_objFlags": 0,
"_parent": {
"__id__": 162
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 166
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 80,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-121.778,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "276fkuLvVPMambHdBgdX3Q"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 165
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "背包",
"_N$string": "背包",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "43HDzTgvxFT4aLfZyveIds"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "blue", "_name": "blue",
...@@ -8246,7 +8344,10 @@ ...@@ -8246,7 +8344,10 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 166 "__id__": 168
},
{
"__id__": 170
} }
], ],
"_active": true, "_active": true,
...@@ -8304,13 +8405,13 @@ ...@@ -8304,13 +8405,13 @@
"_name": "people", "_name": "people",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 165 "__id__": 167
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 167 "__id__": 169
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8366,7 +8467,7 @@ ...@@ -8366,7 +8467,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 166 "__id__": 168
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -8394,6 +8495,101 @@ ...@@ -8394,6 +8495,101 @@
"_N$cacheMode": 0, "_N$cacheMode": 0,
"_id": "ef2xUZkgJO3IUU6v+r8Am6" "_id": "ef2xUZkgJO3IUU6v+r8Am6"
}, },
{
"__type__": "cc.Node",
"_name": "bag",
"_objFlags": 0,
"_parent": {
"__id__": 167
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 171
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 80,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-147.148,
0.846,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "9dJzFN/dJL7KeLM1Qj8IEF"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 170
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "背包",
"_N$string": "背包",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "cdt2OjgwNPnbNFeGxo2lD+"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "left_bottom", "_name": "left_bottom",
...@@ -8405,7 +8601,7 @@ ...@@ -8405,7 +8601,7 @@
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 169 "__id__": 173
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8461,7 +8657,7 @@ ...@@ -8461,7 +8657,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 168 "__id__": 172
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -8613,13 +8809,13 @@ ...@@ -8613,13 +8809,13 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 173 "__id__": 177
}, },
{ {
"__id__": 176 "__id__": 180
}, },
{ {
"__id__": 177 "__id__": 181
} }
], ],
"_active": false, "_active": false,
...@@ -8677,11 +8873,11 @@ ...@@ -8677,11 +8873,11 @@
"_name": "font", "_name": "font",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 172 "__id__": 176
}, },
"_children": [ "_children": [
{ {
"__id__": 174 "__id__": 178
} }
], ],
"_active": true, "_active": true,
...@@ -8739,13 +8935,13 @@ ...@@ -8739,13 +8935,13 @@
"_name": "BRLNSDB", "_name": "BRLNSDB",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 173 "__id__": 177
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 175 "__id__": 179
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8801,7 +8997,7 @@ ...@@ -8801,7 +8997,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 174 "__id__": 178
}, },
"_enabled": true, "_enabled": true,
"_materials": [], "_materials": [],
...@@ -8832,7 +9028,7 @@ ...@@ -8832,7 +9028,7 @@
"_name": "img", "_name": "img",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 172 "__id__": 176
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
...@@ -8890,11 +9086,11 @@ ...@@ -8890,11 +9086,11 @@
"_name": "audio", "_name": "audio",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 172 "__id__": 176
}, },
"_children": [ "_children": [
{ {
"__id__": 178 "__id__": 182
} }
], ],
"_active": true, "_active": true,
...@@ -8952,13 +9148,13 @@ ...@@ -8952,13 +9148,13 @@
"_name": "btn", "_name": "btn",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 177 "__id__": 181
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 179 "__id__": 183
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9014,7 +9210,7 @@ ...@@ -9014,7 +9210,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 178 "__id__": 182
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
......
...@@ -199,12 +199,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -199,12 +199,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
bluePlayerNode = null; bluePlayerNode = null;
redPlayerHomeNode = null; redPlayerHomeNode = null;
bluePlayerHomeNode = null; bluePlayerHomeNode = null;
redBagNode = null;
blueBagNode = null;
// 初始化玩家 // 初始化玩家
initPlayerNode() { initPlayerNode() {
this.redPlayerNode = cc.find("Canvas/player/red/people"); this.redPlayerNode = cc.find("Canvas/player/red/people");
this.bluePlayerNode = cc.find("Canvas/player/blue/people"); this.bluePlayerNode = cc.find("Canvas/player/blue/people");
this.redPlayerHomeNode = cc.find("Canvas/player/red"); this.redPlayerHomeNode = cc.find("Canvas/player/red");
this.bluePlayerHomeNode = cc.find("Canvas/player/blue"); this.bluePlayerHomeNode = cc.find("Canvas/player/blue");
this.redBagNode = cc.find("Canvas/player/red/bag");
this.blueBagNode = cc.find("Canvas/player/blue/bag");
} }
treeNode = null; treeNode = null;
...@@ -266,6 +270,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -266,6 +270,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
} }
// 将宝石移动进入宝箱
moveGemToBag(gemNode, boxNode) {
const pos1 = boxNode.convertToWorldSpaceAR(cc.v2(0, 0));
const pos2 = boxNode.parent.convertToNodeSpaceAR(pos1);
return new Promise((resovle, reject) =>{
cc.tween(gemNode).by(0.5, {x: pos2.x, y: pos2.y}).to(0.5,{scale: 0}).call(()=>{
gemNode.parent = boxNode;
resovle(null);
}).start();
})
}
// 异步游戏核心事件控制 // 异步游戏核心事件控制
allPlayerList; allPlayerList;
initNetworkListener() { initNetworkListener() {
...@@ -423,6 +439,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -423,6 +439,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
gemstoneGroup.children.forEach((gem,index)=>{ gemstoneGroup.children.forEach((gem,index)=>{
let itemData = gem.addComponent('OPW_BoardGame_L5R4_word_dataitem'); let itemData = gem.addComponent('OPW_BoardGame_L5R4_word_dataitem');
gem['__index'] = index; gem['__index'] = index;
gem['__isDone'] = false;
itemData.index = index; itemData.index = index;
itemData.word = gem.name.split("_")[0]; itemData.word = gem.name.split("_")[0];
itemData.score = Number(gem.name.split("_")[1]); itemData.score = Number(gem.name.split("_")[1]);
...@@ -431,12 +448,17 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -431,12 +448,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
itemData.beforeNode = cc.find("before", gem); itemData.beforeNode = cc.find("before", gem);
itemData.afterNode = cc.find("after", gem); itemData.afterNode = cc.find("after", gem);
if(itemData.score == 1) { if(itemData.score == 1) {
gem['__arrIndex1'] = 0;
this.gemstones[0].push(gem); this.gemstones[0].push(gem);
} else if(itemData.score == 2) { } else if(itemData.score == 2) {
gem['__arrIndex1'] = 1;
this.gemstones[1].push(gem); this.gemstones[1].push(gem);
} else if(itemData.score == 3) { } else if(itemData.score == 3) {
gem['__arrIndex1'] = 2;
this.gemstones[2].push(gem); this.gemstones[2].push(gem);
} }
gem['__arrIndex2'] = index;
this.gemstonesAll.push(gem); this.gemstonesAll.push(gem);
itemData.afterNode.active = false; itemData.afterNode.active = false;
}) })
...@@ -457,9 +479,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -457,9 +479,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 蓝色阵营 后手 禁止点击 // 蓝色阵营 后手 禁止点击
this.turntable.disable() this.turntable.disable()
} }
} }
// 注册自定义消息事件 // 注册自定义消息事件
...@@ -491,11 +510,17 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -491,11 +510,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
if(param.success) { if(param.success) {
if(this.currentGameSide == RED) { if(this.currentGameSide == RED) {
this.playerToHomeWithGem(this.redPlayerNode, this.redPlayerHomeNode, param.gemIndex).then(()=>{ this.playerToHomeWithGem(this.redPlayerNode, this.redPlayerHomeNode, param.gemIndex).then(()=>{
next() this.moveGemToBag(this.gemstonesAll[param.gemIndex], this.redBagNode).then(()=>{
this.setGemstoneDoneByIndex(param.gemIndex);
next()
})
}) })
} else { } else {
this.playerToHomeWithGem(this.bluePlayerNode, this.bluePlayerHomeNode, param.gemIndex).then(()=>{ this.playerToHomeWithGem(this.bluePlayerNode, this.bluePlayerHomeNode, param.gemIndex).then(()=>{
next() this.moveGemToBag(this.gemstonesAll[param.gemIndex], this.blueBagNode).then(()=>{
this.setGemstoneDoneByIndex(param.gemIndex);
next()
})
}) })
} }
} else { } else {
...@@ -531,8 +556,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -531,8 +556,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
next(); next();
}); });
}, ()=>{ }, ()=>{
// 游戏流程2: 走棋 index为序号 // 游戏流程2: 走棋
this.runEvent(MSG_GO, {index: 10}); const nextGemIndex = this.getNextQuestionIndex();
this.runEvent(MSG_GO, {index: nextGemIndex});
}) })
// 走棋 // 走棋
...@@ -560,11 +586,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -560,11 +586,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
if(Math.random() > 1) { if(Math.random() > 1) {
console.log("评测失败,后退") console.log("评测失败,后退")
// 后退 // 后退
this.runEvent(MSG_PLAYER_TO_HOME, {success: false, gemIndex: param.index}) this.runEvent(MSG_PLAYER_TO_HOME, {success: false, gemIndex: param.index});
} else { } else {
console.log("评测成功") console.log("评测成功")
// 玩家回家 // 玩家回家
this.runEvent(MSG_PLAYER_TO_HOME, {success: true, gemIndex: param.index}) this.runEvent(MSG_PLAYER_TO_HOME, {success: true, gemIndex: param.index});
} }
}, 2000); }, 2000);
}) })
...@@ -589,7 +615,63 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -589,7 +615,63 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 获取下一道题的索引
getNextQuestionIndex() {
let nums = []
// 根据当前宝石数量进行分组 - 每次从当前剩余宝石中随机出来 __isDone = true 表示当前宝石已经被拿走
let gem1 = [];
this.gemstones[0].forEach(gem=>{
if(!gem.__isDone) {
gem1.push(gem);
}
})
if(gem1.length > 0) {
nums.push(0)
}
let gem2 = [];
this.gemstones[1].forEach(gem=>{
if(!gem.__isDone) {
gem2.push(gem);
}
})
if(gem2.length > 0) {
nums.push(0)
}
let gem3 = [];
this.gemstones[2].forEach(gem=>{
if(!gem.__isDone) {
gem3.push(gem);
}
})
if(gem3.length > 0) {
nums.push(0)
}
// 随机出分值
let num = nums[Math.floor((Math.random() * nums.length * 10) / 10)];
// 从对应分值组中 找到一个宝石
let gIndex = -1;
let index = -1;
switch(num) {
case 0: gIndex = Math.floor((Math.random() * gem1.length * 10) / 10); console.log(gIndex); index = gem1[gIndex].__index; break;
case 1: gIndex = Math.floor((Math.random() * gem2.length * 10) / 10); console.log(gIndex); index = gem2[gIndex].__index; break;
case 2: gIndex = Math.floor((Math.random() * gem3.length * 10) / 10); console.log(gIndex); index = gem3[gIndex].__index; break;
default: gIndex = Math.floor((Math.random() * gem1.length * 10) / 10); console.log(gIndex); index = gem1[gIndex].__index; break;
}
return index;
}
// 将宝石设置为已经完成
setGemstoneDoneByIndex(gemIndex) {
const gem = this.gemstonesAll[gemIndex];
const arrIndex1 = gem.__arrIndex1;
const arrIndex2 = gem.__arrIndex2;
gem.__isDone = true;
console.log(this.gemstones[arrIndex1][arrIndex2]);
}
// 走棋 // 走棋
gameFlowGo() { gameFlowGo() {
......
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