Commit 93afe146 authored by 范雪寒's avatar 范雪寒

feat: 除了猫崽子以外的基本完成

parent 6b2a6207
{
"ver": "2.0.1",
"uuid": "f0680ae0-c079-45ef-abd7-9e63d90b982b",
"uuid": "a544c1e7-32f5-4754-95a2-823398db0dcc",
"downloadMode": 0,
"duration": 0.130612,
"duration": 0.287347,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "293ae196-a9b5-4da0-a0b6-597baa25f7b1",
"downloadMode": 0,
"duration": 0.365714,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "b733b7d3-4082-4320-9fe0-2ce28088b687",
"downloadMode": 0,
"duration": 0.966531,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "e87d3f15-54b2-4a37-9793-9923fa34fda9",
"downloadMode": 0,
"duration": 0.626939,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "d9be9283-652e-44da-98d6-680406e71a03",
"downloadMode": 0,
"duration": 0.168,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "7bf9c308-8dd5-411d-8770-ddc8341386d0",
"downloadMode": 0,
"duration": 0.39185,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
import { onHomeworkFinish } from "../script/util";
import { onHomeworkFinish, randomSortByArr } from "../script/util";
import { defaultData } from "../script/defaultData";
cc.Class({
......@@ -150,7 +150,9 @@ cc.Class({
},
initView() {
this.jumpToQuestion(this.status.currentQuestionIdx);
this.coolCatSpeakStart(() => {
this.jumpToQuestion(this.status.currentQuestionIdx);
});
},
jumpToQuestion(questionIdx) {
......@@ -162,13 +164,21 @@ cc.Class({
const optionNum = this.data.question_arr[questionIdx].option_arr.length;
const maxOptionHeight = 500;
const maxOptionWidth = canvasWidth / optionNum;
this.data.question_arr[questionIdx].option_arr.forEach(async (option, idx) => {
const arr = randomSortByArr(this.data.question_arr[questionIdx].option_arr);
arr.forEach(async (option, idx) => {
const optionNode = await this.createOption(option);
optionNode.name = `option_${idx}`;
optionNode.x = (maxOptionWidth) * (idx + 0.5) - canvasWidth / 2 - box.x;
optionNode.x = canvasWidth + idx * maxOptionWidth;
optionNode.y = canvasHeight / 2 - box.y - 300;
optionNode.scale = Math.min(1, (maxOptionWidth - 10) / optionNode.width, maxOptionHeight / optionNode.height);
optionNode.parent = box;
const targetX = (maxOptionWidth) * (idx + 0.5) - canvasWidth / 2 - box.x;
const time = (optionNode.x - targetX) / 1000;
cc.tween(optionNode)
.to(time, { x: targetX }, cc.easing.quadIn)
.start();
});
},
......@@ -179,41 +189,64 @@ cc.Class({
resolve(optionNode);
});
optionNode.optionData = optionData;
optionNode.optionData.selected = false;
const box = cc.find('Canvas/bg/box');
optionNode.on(cc.Node.EventType.TOUCH_START, (event) => {
if (optionNode.optionData.selected) {
return;
}
const location = event.getLocation();
optionNode.startLocation = location;
optionNode.startPos = {
x: optionNode.x,
y: optionNode.y
}
const selectedNum = box.children.filter(child => child.optionData.selected == true).length;
optionNode.zIndex = selectedNum;
this.optionJump(optionNode);
this.playAudioByUrl(optionNode.optionData.audio_url);
});
optionNode.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
if (optionNode.optionData.selected) {
return;
}
const location = event.getLocation();
optionNode.x = optionNode.startPos.x + (location.x - optionNode.startLocation.x);
optionNode.y = optionNode.startPos.y + (location.y - optionNode.startLocation.y);
});
optionNode.on(cc.Node.EventType.TOUCH_END, (event) => {
const box = cc.find('Canvas/bg/box');
if (optionNode.optionData.selected) {
return;
}
const rectOption = optionNode.getBoundingBox();
if (!cc.Intersection.rectRect(box, rectOption)) {
optionNode.x = optionNode.startPos.x;
optionNode.y = optionNode.startPos.y;
cc.tween(optionNode)
.to(0.05, {
x: optionNode.startPos.x,
y: optionNode.startPos.y
}, cc.easing.quadOut)
.start();
this.playEffect('flyBack');
return;
}
cc.tween(optionNode)
.to(0.2, { x: 0, y: 0 }, cc.easing.quadOut)
.to(0.2, { x: 0, y: 100 }, cc.easing.quadOut)
.start();
this.boxJump();
optionNode.optionData.selected = true;
});
return optionNode;
});
// optionData.audio_url
// optionData.is_right
},
optionJump(node) {
......@@ -234,23 +267,102 @@ cc.Class({
initListener() {
const btnSubmit = cc.find('Canvas/bg/btnSubmit');
btnSubmit.on('click', () => {
this.optionJump(btnSubmit);
this.playEffect('submit');
const box = cc.find('Canvas/bg/box');
if (box.children.every(child => child.optionData.selected == child.optionData.is_right)) {
this.onAnswerRight();
} else {
this.onAnswerWrong();
if (!this.status.wrongOnce) {
this.status.wrongOnce = true;
this.onAnswerWrong();
} else {
this.onAnswerWrongTwice();
}
}
});
const btnNext = cc.find('Canvas/bg/btnNext');
btnNext.on('click', () => {
this.optionJump(btnNext);
});
},
onAnswerRight() {
this.nextQuestion();
},
onAnswerWrong() {
const box = cc.find('Canvas/bg/box');
box.children
.filter(child => child.optionData.selected)
.forEach(child => {
child.optionData.selected = false;
cc.tween(child)
.to(0.2, { x: child.startPos.x, y: child.startPos.y })
.start();
});
this.playEffect('flyBackAll');
},
onAnswerWrongTwice() {
this.nextQuestion();
this.playEffect('jumpAll');
},
nextQuestion() {
const box = cc.find('Canvas/bg/box');
box.children.forEach(child => {
cc.tween(child)
.to(0.1, { scaleX: 0, scaleY: 0 })
.removeSelf()
.start();
});
this.status.currentQuestionIdx++;
this.status.wrongOnce = false;
if (this.status.currentQuestionIdx < this.data.question_arr.length) {
setTimeout(() => {
this.jumpToQuestion(this.status.currentQuestionIdx);
}, 0.1 * 1000);
} else {
this.submitBtnMoveOut();
this.showNextBtn();
}
},
boxJump() {
const boxBehind = cc.find('Canvas/bg/box_behind');
const boxFront = cc.find('Canvas/bg/box_front');
this.playEffect('boxJump');
cc.tween(boxFront)
.to(0.1, { scaleX: 1.02, scaleY: 1.02 })
.to(0.1, { scaleX: 1.0, scaleY: 1.0 })
.start();
cc.tween(boxBehind)
.to(0.1, { scaleX: 1.02, scaleY: 1.02 })
.to(0.1, { scaleX: 1.0, scaleY: 1.0 })
.start();
},
coolCatSpeakStart(cb) {
cb();
},
submitBtnMoveOut() {
const submitBtn = cc.find('Canvas/bg/btnSubmit');
cc.tween(submitBtn)
.by(1, { y: -submitBtn.height })
.start();
},
showNextBtn() {
const btnNext = cc.find('Canvas/bg/btnNext');
btnNext.active = true;
},
......@@ -280,6 +392,15 @@ cc.Class({
});
},
playEffect(name, cb) {
const audioNode = cc.find(`audios/${name}`);
const audioClip = audioNode.getComponent(cc.AudioSource).clip;
const audioId = cc.audioEngine.playEffect(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, cb);
}
},
playAudioByUrl(audio_url, cb = null) {
if (!audio_url) {
if (cb) {
......
export const defaultData = {
question_arr: [{
question_audio_url: '',
option_arr: [{ //选项 (多选)
pic_url: 'http://staging-teach.cdn.ireadabc.com/994b3fce7a503cdb428fa0f735851d98.jpeg', // 图片路径
audio_url: '', //音频路径
is_right: true, //是否正确
}, {
pic_url: 'http://staging-teach.cdn.ireadabc.com/213871779bc2404f84bfa94672dd0e74.jpg', // 图片路径
audio_url: '',
is_right: false,
}, {
pic_url: 'http://staging-teach.cdn.ireadabc.com/213871779bc2404f84bfa94672dd0e74.jpg', // 图片路径
audio_url: '',
is_right: false,
}, {
pic_url: 'http://staging-teach.cdn.ireadabc.com/994b3fce7a503cdb428fa0f735851d98.jpeg', // 图片路径
audio_url: '',
is_right: false,
}, {
pic_url: 'http://staging-teach.cdn.ireadabc.com/994b3fce7a503cdb428fa0f735851d98.jpeg', // 图片路径
audio_url: '',
is_right: false,
}]
}, {
question_audio_url: '',
option_arr: [{ //选项 (多选)
pic_url: '', // 图片路径
audio_url: '', //音频路径
is_right: true, //是否正确
}, {
pic_url: '',
audio_url: '',
is_right: false,
"question_arr": [{
"question_audio_url": "",
"option_arr": [{
"pic_url": "http://staging-teach.cdn.ireadabc.com/251667ae3d4921582392f6bc42bd2a96.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/3c070a33d021725219ab7eec9e60cb39.mp3",
"is_right": false
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/48ecba3519b1d58a1fa434ae694fc831.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/736c616e8b66a3ae03c8e8636ca46f0f.mp3",
"is_right": false
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/b1f05766a01d797c00839a5554c00050.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/2b5058e2cf41b152c44ef13cba898455.mp3",
"is_right": false
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/1d74d3c390aa740bc2c91537fcefed61.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/b4e6f8abf69975813c2a44d1b5d3d9e0.mp3",
"is_right": true
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/5aebe09b50932e725006a1a28741f3d4.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/90e185c3f3e3872044d6370c3ae11e3e.mp3",
"is_right": true
}],
"audio_url": "http://staging-teach.cdn.ireadabc.com/d3e30a65afd6269dfc5cb2b17b21f872.mp3"
},
{
"question_audio_url": "",
"option_arr": [{
"pic_url": "http://staging-teach.cdn.ireadabc.com/5ba43828aef85c585743a0c898b43c42.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/79a67cfeb1fee086076bc7f46e1524f1.mp3",
"is_right": true
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/f0bcd7fa36f501fd16e5ea3b74d0eb57.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/baae6b4c92d8a95e184d6d18542e0d21.mp3",
"is_right": true
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/c6bfc85fcd5fd0640e216ed3da2a3886.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/2b5058e2cf41b152c44ef13cba898455.mp3",
"is_right": false
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/d69dee492fd35b3c066207c3fc8e3258.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/b75df34ef55bd1c6e3a799f1dac87fec.mp3",
"is_right": false
},
{
"pic_url": "http://staging-teach.cdn.ireadabc.com/44464e706225cfe43e918bf1167a2ac1.png",
"audio_url": "http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3",
"is_right": false
}]
}]
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"premultiplyAlpha": true,
"genMipmaps": false,
"packable": true,
"width": 209,
......
......@@ -4,7 +4,7 @@
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"premultiplyAlpha": true,
"genMipmaps": false,
"packable": true,
"width": 244,
......
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