Commit 04ee877a authored by 李维's avatar 李维

dev commit

parent 96c2aee5
......@@ -114,19 +114,22 @@
"__id__": 179
},
{
"__id__": 180
"__id__": 182
},
{
"__id__": 183
}
],
"_active": true,
"_components": [
{
"__id__": 190
"__id__": 195
},
{
"__id__": 191
"__id__": 196
},
{
"__id__": 192
"__id__": 197
}
],
"_prefab": null,
......@@ -8906,6 +8909,162 @@
"_atlas": null,
"_id": "63pCec93BEkpAqHho7leib"
},
{
"__type__": "cc.Node",
"_name": "bottomButtons",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [
{
"__id__": 180
}
],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
509.947,
-325.202,
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": "2e692LFYZDk6UBiSgScZ5P"
},
{
"__type__": "cc.Node",
"_name": "restart",
"_objFlags": 0,
"_parent": {
"__id__": 179
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 181
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 47,
"height": 57
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-5,
7,
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": "00TYfHicZFSJPBfFzy95b+"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 180
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "607a2f52-a26c-434f-b331-afa9335ca6e6"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "ee6Xcxm+FBtZe7cQHxudAu"
},
{
"__type__": "cc.Node",
"_name": "MaskLayer",
......@@ -8972,14 +9131,14 @@
"__id__": 2
},
"_children": [
{
"__id__": 181
},
{
"__id__": 184
},
{
"__id__": 187
},
{
"__id__": 192
}
],
"_active": false,
......@@ -9037,11 +9196,11 @@
"_name": "font",
"_objFlags": 0,
"_parent": {
"__id__": 180
"__id__": 183
},
"_children": [
{
"__id__": 182
"__id__": 185
}
],
"_active": true,
......@@ -9099,13 +9258,13 @@
"_name": "Comic Sans MS",
"_objFlags": 0,
"_parent": {
"__id__": 181
"__id__": 184
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 183
"__id__": 186
}
],
"_prefab": null,
......@@ -9161,7 +9320,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 182
"__id__": 185
},
"_enabled": true,
"_materials": [],
......@@ -9193,11 +9352,14 @@
"_name": "img",
"_objFlags": 0,
"_parent": {
"__id__": 180
"__id__": 183
},
"_children": [
{
"__id__": 185
"__id__": 188
},
{
"__id__": 190
}
],
"_active": true,
......@@ -9255,13 +9417,13 @@
"_name": "card_demo",
"_objFlags": 0,
"_parent": {
"__id__": 184
"__id__": 187
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 186
"__id__": 189
}
],
"_prefab": null,
......@@ -9317,7 +9479,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 185
"__id__": 188
},
"_enabled": true,
"_materials": [],
......@@ -9340,16 +9502,106 @@
"_atlas": null,
"_id": "12k+fbxEVAxKNoPu5dURjd"
},
{
"__type__": "cc.Node",
"_name": "black",
"_objFlags": 0,
"_parent": {
"__id__": 187
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 191
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
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": "dbn85feHFExo1q+nsQtN4n"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 190
},
"_enabled": true,
"_materials": [],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "7a2d99d6-2009-4341-83f8-f18980e6405d"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "86147ZoQBOpKg5wejgeXRf"
},
{
"__type__": "cc.Node",
"_name": "audio",
"_objFlags": 0,
"_parent": {
"__id__": 180
"__id__": 183
},
"_children": [
{
"__id__": 188
"__id__": 193
}
],
"_active": true,
......@@ -9407,13 +9659,13 @@
"_name": "test_audio",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 192
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 189
"__id__": 194
}
],
"_prefab": null,
......@@ -9469,7 +9721,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 188
"__id__": 193
},
"_enabled": true,
"_clip": {
......
......@@ -105,6 +105,8 @@ export default class Cartoon {
subscribeTouchEvent(key, callBack) {
if(!this.touchEventCallback[key]) {
this.touchEventCallback[key] = callBack
this.elements[key].node.off(cc.Node.EventType.TOUCH_START)
this.elements[key].node.on(cc.Node.EventType.TOUCH_START, ()=>{
if(this.touchEventCallback[key]) {
this.touchEventCallback[key]()
......
......@@ -15,6 +15,7 @@ export default class GameLogic {
m_currentQuestion = -1;
m_questionDone = false;
m_currentQuestionArray = []
m_gameEnd = false;
constructor(formData, systemOption) {
this.g_systemOption = systemOption;
this.g_canvas = cc.find('Canvas');
......@@ -39,6 +40,8 @@ export default class GameLogic {
this.initImageCards();
this.initTitle();
this.loadQuestion();
this.initBottomButtons();
this.initMaskLayer();
// this.initQuestionPannel();
// this.initButtons();
// this.initMaskLayer();
......@@ -58,10 +61,14 @@ export default class GameLogic {
}
initNodes() {
let dataLength = this.g_formData.dataArray.length;
this.g_cartoon.initCartoonElement("title_text", this.g_cartoon.getNodeByPath(`Canvas/title/text`))
for(let index=0; index<10; index++) {
const card = this.g_cartoon.initCartoonElement(`card_${index+1}`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}`))
card.node.zIndex = 1
if(index>=dataLength) {
card.node.active = false;
}
this.g_cartoon.initCartoonElement(`card_${index+1}_normal`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}/normal`));
this.g_cartoon.initCartoonElement(`card_${index+1}_selected`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}/selected`));
this.g_cartoon.initCartoonElement(`card_${index+1}_bell`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}/bell`))
......@@ -69,6 +76,16 @@ export default class GameLogic {
this.g_cartoon.initCartoonElement(`card_${index+1}_bell_outline`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}/bell/bell_outline`));
this.g_cartoon.initCartoonElement(`card_${index+1}_image_container`, this.g_cartoon.getNodeByPath(`Canvas/card_${index+1}/container/image`));
}
if(dataLength==0) {
this.g_cartoon.getNodeByPath(`Canvas/shengzi/line_1`).active = false;
this.g_cartoon.getNodeByPath(`Canvas/shengzi/line_2`).active = false;
} else if(dataLength<=5) {
this.g_cartoon.getNodeByPath(`Canvas/shengzi/line_2`).active = false;
}
this.g_cartoon.initCartoonElement(`bottomButtons`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons`));
this.g_cartoon.initCartoonElement(`restart_button`, this.g_cartoon.getNodeByPath(`Canvas/bottomButtons/restart`));
}
initBg() {
......@@ -92,13 +109,27 @@ export default class GameLogic {
bgNodeTitle.y = cc.winSize.height / 2 - bgNodeTitle.height / 2 - 50
bgNodeSnow.y = -cc.winSize.height / 2 + bgNodeSnow.height / 2
bgNodeShuicao.y = -cc.winSize.height / 2 + bgNodeShuicao.height / 2
const cardPos = [
{x: -500, y: 128}, {x: -250, y: 128}, {x: 0, y: 128}, {x: 250, y: 128}, {x: 500, y: 128},
{x: -500, y: -128}, {x: -250, y: -128}, {x: 0, y: -128}, {x: 250, y: -128}, {x: 500, y: -128}
]
for(let index=0; index<10; index++) {
const card = this.g_cartoon.getCartoonElement(`card_${index+1}`)
card.node.setPosition(cardPos[index].x, cardPos[index].y)
}
}
initImageCards() {
let newIndex = this.getRandomArray(10)
console.log("正确序号:", newIndex)
this.m_currentQuestionArray = [0,1,2,3,4,5,6,7,8,9]
for (let index = 0; index < 10; index++) {
let dataLength = this.g_formData.dataArray.length;
let newIndex = this.getRandomArray(dataLength)
this.m_currentQuestionArray = []
for(let index=0; index<dataLength; index++) {
this.m_currentQuestionArray.push(index)
}
for (let index = 0; index<dataLength; index++) {
let dataItem = this.g_formData.dataArray[newIndex[index]];
let card = this.g_cartoon.getCartoonElement(`card_${index+1}`)
card.open = false;
......@@ -132,20 +163,10 @@ export default class GameLogic {
bellOutline.node.setScale(0);
this.g_cartoon.subscribeTouchEvent(`card_${index+1}_image_container`, ()=>{
if(card.open) {
if(card.open || this.m_gameEnd) {
return;
}
// for(let i=0; i<10; i++) {
// if(i!=index && i != this.m_currentQuestion) {
// this.g_cartoon.getCartoonElement(`card_${i+1}_normal`).node.opacity = 255;
// this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 0;
// } else {
// this.g_cartoon.getCartoonElement(`card_${i+1}_normal`).node.opacity = 0;
// this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 255;
// }
// }
if(this.m_currentQuestion == imageContainer.correctIndex ) {
card.open = true;
this.g_cartoon.getCartoonElement(`card_${imageContainer.cardIndex+1}_normal`).node.opacity = 0;
......@@ -195,8 +216,8 @@ export default class GameLogic {
let x_2 = card_2.node.x
let y_2 = card_2.node.y
card_1.node.setSiblingIndex(100);
card_2.node.setSiblingIndex(100);
card_1.node.setSiblingIndex(10);
card_2.node.setSiblingIndex(10);
let bell1 = this.g_cartoon.getCartoonElement(`card_${i1}_bell`)
let bell2 = this.g_cartoon.getCartoonElement(`card_${toIndex+1}_bell`)
......@@ -231,30 +252,12 @@ export default class GameLogic {
return this.m_currentQuestionArray.indexOf(index)
}
initCenterImage() {
let imageContainer = this.g_cartoon.getCartoonElement("center_image_container")
if(!this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url) {
let fr = this.getSpriteFrimeByResName("default_stage")
imageContainer.node.setScale(1)
imageContainer.node.getComponent(cc.Sprite).spriteFrame = fr
} else {
let parentWidth = imageContainer.node.parent.width
let parentHeight = imageContainer.node.parent.height
this.getSpriteFrimeByUrl(this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url, (fr)=>{
imageContainer.node.getComponent(cc.Sprite).spriteFrame = fr
imageContainer.node.scaleX = parentWidth / imageContainer.node.width
imageContainer.node.scaleY = parentHeight / imageContainer.node.height
})
}
}
initTitle() {
this.g_cartoon.getCartoonElement("title_text").node.getComponent(cc.Label).string = "It's My Day"
this.g_cartoon.getCartoonElement("title_text").node.getComponent(cc.Label).font = this.g_cartoon.getFontFamily("Comic Sans MS")
this.g_cartoon.getCartoonElement("title_text").node.getComponent(cc.Label).fontSize = 32
}
getRandomArray(length) {
Array.prototype.shuffle = function() {
let m = this.length, i;
......@@ -322,14 +325,96 @@ export default class GameLogic {
loadQuestion() {
let index = null;
let dataLength = this.g_formData.dataArray.length;
for(let i=0; i<10; i++) {
this.g_cartoon.getCartoonElement(`card_${i+1}_normal`).node.opacity = 255;
this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 0;
}
this.m_currentQuestion++;
index = this.m_currentQuestionArray[this.m_currentQuestion]
this.g_cartoon.getCartoonElement(`card_${index+1}_normal`).node.opacity = 0;
this.g_cartoon.getCartoonElement(`card_${index+1}_selected`).node.opacity = 255;
if((this.m_currentQuestion+1)==dataLength) {
this.endGame()
} else {
index = this.m_currentQuestionArray[this.m_currentQuestion]
this.g_cartoon.getCartoonElement(`card_${index+1}_normal`).node.opacity = 0;
this.g_cartoon.getCartoonElement(`card_${index+1}_selected`).node.opacity = 255;
}
}
endGame() {
this.m_gameEnd = true;
let resetBtn = this.g_cartoon.getCartoonElement("restart_button")
resetBtn.node.active = true;
}
restartGame(callback) {
this.m_questionAudioPlayed = false;
this.m_currentQuestion = -1;
this.m_questionDone = false;
this.m_currentQuestionArray = []
this.m_gameEnd = false;
for(let index=0; index<10; index++) {
const card = this.g_cartoon.getCartoonElement(`card_${index+1}`)
}
this.g_cartoon.stopAllAudio()
this.showMaskLayer(()=>{
this.resetPosition();
this.initImageCards();
this.initTitle();
this.loadQuestion();
this.hideMaskLayer(()=>{
if(callback) {
callback()
}
})
})
}
initBottomButtons() {
let bottomButtons = this.g_cartoon.getCartoonElement("bottomButtons")
bottomButtons.node.x = cc.winSize.width / 2 - 100
bottomButtons.node.y = -cc.winSize.height / 2 + 50
let resetBtn = this.g_cartoon.getCartoonElement("restart_button")
resetBtn.node.active = false;
this.g_cartoon.subscribeTouchEvent(resetBtn.key, ()=>{
jelly(resetBtn.node).then(()=>{
resetBtn.node.active = false;
})
this.restartGame()
})
}
initCenterImage() {
let imageContainer = this.g_cartoon.getCartoonElement("center_image_container")
if(!this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url) {
let fr = this.getSpriteFrimeByResName("default_stage")
imageContainer.node.setScale(1)
imageContainer.node.getComponent(cc.Sprite).spriteFrame = fr
} else {
let parentWidth = imageContainer.node.parent.width
let parentHeight = imageContainer.node.parent.height
this.getSpriteFrimeByUrl(this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url, (fr)=>{
imageContainer.node.getComponent(cc.Sprite).spriteFrame = fr
imageContainer.node.scaleX = parentWidth / imageContainer.node.width
imageContainer.node.scaleY = parentHeight / imageContainer.node.height
})
}
}
initQuestionPannel() {
......@@ -786,6 +871,7 @@ export default class GameLogic {
bNode.scaleY = cc.winSize.height / bNode.height;
bNode.x = 0
bNode.y = 0
parentNode.setSiblingIndex(255)
bNode.parent = cc.find('Canvas');
bNode.active = false;
this.maskLayer = bNode;
......
......@@ -87,7 +87,8 @@ cc.Class({
},
getDefaultData() {
const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png"}]}}'
// const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png"}]}}'
const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"}]}}'
const data = JSON.parse(dataJson);
return data;
},
......
{
"ver": "2.3.5",
"uuid": "2415e777-ac95-43f5-a9e9-14a21908331e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 47,
"height": 57,
"platformSettings": {},
"subMetas": {
"btn_restart": {
"ver": "1.0.4",
"uuid": "607a2f52-a26c-434f-b331-afa9335ca6e6",
"rawTextureUuid": "2415e777-ac95-43f5-a9e9-14a21908331e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 47,
"height": 57,
"rawWidth": 47,
"rawHeight": 57,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ 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