Commit 32145a06 authored by Tt's avatar Tt

泡泡完成

parent 82e98919
{
"ver": "2.0.1",
"uuid": "8e715c85-2d8c-46f2-9efb-e5f742f79f5d",
"downloadMode": 0,
"duration": 0.470204,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "876dacc2-d8fc-4ed9-915b-b9555362d5e3",
"downloadMode": 0,
"duration": 0.313469,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "72c3bfcb-1b37-4cec-929b-2ae0c3dd2293",
"downloadMode": 0,
"duration": 0.809796,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
...@@ -21,44 +21,62 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -21,44 +21,62 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
private speed: number; private speed: number;
private isCorrect: boolean;
private targetPosition: number; private targetPosition: number;
private touchNumber: number = 1; private touchNumber: number = -1;
async onLoadEnd() { async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData() this.initData()
this.initView() this.initView()
this.initEvent() this.initEvent()
this.initGame() this.nextQuestion()
} }
initData() { initData() {
this.current = -1; this.current = -1;
this.data.questions.forEach(question => {
question.options.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
.sort((A, B) => Math.random() - 0.5)
})
} }
initView() { } initView() { }
initEvent() { initEvent() {
let bottom_megaphone = pg.view.find(this, 'layer_game/bottom_megaphone') let btn_megaphone = pg.view.find(this, 'layer_game/btn_megaphone')
// 底部海螺点击事件 // 底部海螺点击事件
pg.view.touchOn(bottom_megaphone, this.create_bubbles, this) pg.view.touchOn(btn_megaphone, this.onTouchMegaphone, this)
} }
initGame() { private rightList: Array<any>;
nextQuestion() {
this.current++;// 自动切换下一题 this.current++;// 自动切换下一题
if (!this.currentQuestion) { if (!this.currentQuestion) {
this.gameOver(); this.gameOver();
return; return;
} }
this.speed = 30 this.speed = 30
this.touchNumber = -1;
this.rightList = [];
console.log(this.data) console.log(this.data)
let layer_paopao = pg.view.find(this, 'layer_game/layer_paopao')
layer_paopao.removeAllChildren();
// 底部海螺 // 底部海螺
let bottom_megaphone = pg.view.find(this, 'layer_game/bottom_megaphone') let btn_megaphone = pg.view.find(this, 'layer_game/btn_megaphone')
// 开始海螺从底部升起 // 开始海螺从底部升起
let btn = cc.tween(bottom_megaphone) let btn = cc.tween(btn_megaphone)
btn.to(1.5, { y: -438 }) btn.to(1.5, { y: -438 }).call(() => { }).start()
.call(() => { // 播放音频
// 海螺第一次从底部升起后自动制造气泡一次 pg.event.emit('img_voice_play_voice_start')
this.create_bubbles() pg.audio.playAudioByUrl(this.currentQuestion.questionAudio, () => {
pg.event.emit('img_voice_play_voice_end')
// 摇晃海螺
this.aniShake(btn_megaphone).then(() => {
this.startCreate = true;
}) })
btn.start() });
} }
gameOver() { gameOver() {
console.log("游戏结束"); console.log("游戏结束");
...@@ -67,42 +85,69 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -67,42 +85,69 @@ export default class SceneComponent extends MyCocosSceneComponent {
get currentQuestion() { get currentQuestion() {
return this.data.questions[this.current]; return this.data.questions[this.current];
} }
get currentRightList() {
return this.currentQuestion.options.filter(op => op.right);
}
onTouchMegaphone() {
if (!this.startCreate) return;
//发音
pg.event.emit('img_voice_play_voice_start')
pg.audio.playAudioByUrl(this.currentQuestion.questionAudio, () => {
pg.event.emit('img_voice_play_voice_end')
});
}
onPlayMegaphone() {
}
update() {
this.create_bubbles();
}
// 制造气泡 // 制造气泡
async create_bubbles() { private startCreate: boolean;
if (this.touchNumber > this.currentQuestion.options.length) { private lastTime: number;
console.log('此题结束') create_bubbles() {
if (!this.startCreate) return;
let nowTime = new Date().getTime();
if (!this.lastTime) {
this.lastTime = nowTime;
} else { } else {
let bottom_megaphone = pg.view.find(this, 'layer_game/bottom_megaphone') if (nowTime - this.lastTime < 2 * 1000) return;
let layer_paopao = pg.view.find(this, 'layer_game/layer_paopao') this.lastTime = nowTime;
let paoaoParent = pg.view.find(this, 'layer_game/paopao')
// 创建泡泡
let newPaoPao = cc.instantiate(paoaoParent)
layer_paopao.addChild(newPaoPao)
this.updatePaoPao(newPaoPao, this.currentQuestion.options[this.touchNumber - 1]);
// 做动画
this.aniShake(bottom_megaphone).then(() => {
this.aniPaoPaoFly(newPaoPao).then(() => {
// 泡泡自行销毁
newPaoPao.parent = null;
})
})
} }
this.touchNumber++; this.touchNumber++;
let data = this.currentQuestion.options[this.touchNumber % this.currentQuestion.options.length]
if (!data) return;
if (this.rightList.some(dt => JSON.stringify(dt) == JSON.stringify(data))) return;
let layer_paopao = pg.view.find(this, 'layer_game/layer_paopao')
if (layer_paopao.children.some(child => JSON.stringify(child.data) == JSON.stringify(data))) return;
let paoaoParent = pg.view.find(this, 'layer_game/paopao')
// 创建泡泡
let newPaoPao = cc.instantiate(paoaoParent)
layer_paopao.addChild(newPaoPao)
this.updatePaoPao(newPaoPao, data);
// 做动画
pg.hw.playLocalAudio('create')
this.aniPaoPaoFly(newPaoPao).then(() => {
// 泡泡自行销毁
newPaoPao.parent = null;
})
} }
aniPaoPaoFly(item) { aniPaoPaoFly(item) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
pg.view.visible(item, true) pg.view.visible(item, true)
item.x = 135 item.x = 135
item.y = -450 item.y = -450
item.scale = 0;
item.opacity = 0 item.opacity = 0
let positionY = Math.floor(Math.random() * 300) let positionY = Math.floor(Math.random() * 300)
let positionX = this.getPositionX() let positionX = this.getPositionX()
cc.tween(item).to(0.8, { opacity: 255 }) let timeTo = 2 + Math.random() * 3;
.call(() => { let timeUp = 5 + Math.random() * 5;
this.targetPosition = positionY this.targetPosition = positionY
}) cc.tween(item).to(0.3, { scale: 0.3, opacity: 255 }).to(0.5, { scale: 1 }).start();
.to(positionY / this.speed, { x: positionX, y: positionY, scale: 3 }) cc.tween(item)
.to((750 - item.y) / this.speed, { y: cc.winSize.height + 105 }) .to(timeTo * 3, { x: positionX, y: positionY })
.to(timeUp, { y: cc.winSize.height / 2 + 105 })
.call(() => { .call(() => {
resolve(''); resolve('');
}).start() }).start()
...@@ -119,27 +164,34 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -119,27 +164,34 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
} }
updatePaoPao(item, data) { updatePaoPao(item, data) {
let paopao = item.getChildByName("bubble") let bubble = item.getChildByName("bubble")
let broken = item.getChildByName("bubble_broken") let broken = item.getChildByName("bubble_broken")
let img = item.getChildByName("img") let img = bubble.getChildByName("img")
let text = item.getChildByName("text") let text = bubble.getChildByName("text")
paopao.width = 70
paopao.height = 70
pg.view.visible(broken, false) pg.view.visible(broken, false)
// 判断是显示图片还是文字 // 判断是显示图片还是文字
if (data.type === 'img') { if (data.type === 'img') {
pg.view.visible(img, true) pg.view.visible(img, true)
pg.view.visible(text, false) pg.view.visible(text, false)
pg.view.setNetImg(img, data.image, { w: 60, h: 60 }) pg.view.setNetImg(img, data.image, { w: 150, h: 150 })
} else { } else {
pg.view.visible(img, false) pg.view.visible(img, false)
pg.view.visible(text, true) pg.view.visible(text, true)
pg.view.setString(text, data.text) pg.view.setString(text, data.text)
} }
// 点击泡泡 // 点击泡泡
item.data = data;
pg.view.touchOn(item, this.touchPaoPao, this) pg.view.touchOn(item, this.touchPaoPao, this)
} }
checkFinish() {
if (this.rightList.length == this.currentRightList.length) {
cc.Tween.stopAll();
this.startCreate = false;
this.scheduleOnce(() => {
this.nextQuestion();
}, 0.5)
}
}
getPositionX() { getPositionX() {
if (Math.random() < 0.5) { if (Math.random() < 0.5) {
...@@ -151,21 +203,33 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -151,21 +203,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 点击泡泡 // 点击泡泡
touchPaoPao(e: any) { touchPaoPao(e: any) {
// 如果泡泡没有到指定位置不允许点击 // 如果泡泡没有到指定位置不允许点击
if (this.targetPosition > e.target.y) return let item = e.target;
if (this.isCorrect) { let data = e.target.data;
if (data.right) {
pg.hw.playLocalAudio('right')
cc.Tween.stopAllByTarget(item)
// 成功 泡泡破碎 里面的内容消失 // 成功 泡泡破碎 里面的内容消失
let paopao = e.target.getChildByName("bubble") let bubble = e.target.getChildByName("bubble")
let broken = e.target.getChildByName("bubble_broken") let broken = e.target.getChildByName("bubble_broken")
broken.width = 70 let img = bubble.getChildByName("img")
broken.height = 70 let text = bubble.getChildByName("text")
pg.view.visible(paopao, false) pg.view.visible(bubble, false)
pg.view.visible(broken, true) pg.view.visible(broken, true)
// cc.tween(img).to(0.1, { opacity: 0 }).start();
// cc.tween(text).to(0.1, { opacity: 0 }).start();
this.scheduleOnce(() => {
item.parent = null;
}, 0.2);
this.rightList.push(data);
this.checkFinish();
} else { } else {
pg.hw.playLocalAudio('error')
// 失败 泡泡左右微晃两次 // 失败 泡泡左右微晃两次
let obj = cc.tween(e.target) cc.tween(pg.view.find(item, 'bubble'))
obj.by(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 }) .to(0.1, { x: -5 }).to(0.1, { x: 0 }).to(0.1, { x: 5 }).to(0.1, { x: 0 })
obj.by(0.1, { x: -5 }).by(0.1, { x: 0 }).by(0.1, { x: 5 }).by(0.1, { x: 0 }) .start()
obj.start()
} }
} }
} }
......
export const defaultData = export const defaultData =
{"onlineFlg":false,"title":"钓鱼大作战","questionText":"海洋里有很多鱼,每条鱼身上都藏着魔法信息!亲爱的小玩家,请仔细听游戏指令,找到含有正确魔法信息的鱼,快速完成钓鱼。 在本次的游戏中,你将和其他玩家进行PK,游戏结束,钓鱼数量最多的玩家,将获得胜利。最后根据钓鱼的数量,你将获得相应的能量石奖励!开始挑战吧!","questionTextAudio":"http://staging-teach.cdn.ireadabc.com/e422c682ff3304a532937db64573caa4.mp3","questions":[{"questionAudio":"http://staging-teach.cdn.ireadabc.com/c9db9c8f9c256b928a7f0e1498963404_l.mp3","duration":120,"options":[{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/7782399d0ad0b9578b2109c620d64465.png","audio":"","text":"","right":true},{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/e283a9417dbb578b83c05c5969b4865b.png","audio":"","text":"","right":true},{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/bd01e5bfb67be451fc282671d1b9d883.png","audio":"","text":"","right":false},{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/5ac88495707336f3d34708f0f174a8f0.jpg","audio":"","text":"","right":false}],"audioName":"ready go.mp3"},{"questionAudio":"http://staging-teach.cdn.ireadabc.com/cb76dbc838567b58e2af36e2d2faa923_l.mp3","duration":120,"options":[{"type":"txt","image":"","audio":"","text":"push","right":false},{"type":"txt","image":"","audio":"","text":"monkey","right":true},{"type":"txt","image":"","audio":"","text":"book","right":true},{"type":"txt","image":"","audio":"","text":"bee","right":false}],"audioName":"图片卡片出现.mp3"},{"questionAudio":"http://staging-teach.cdn.ireadabc.com/6d742645880f902efae878facc78da07_l.mp3","duration":120,"options":[{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/3a7fdd71c900985e8f493d8e4035bf84.png","audio":"","text":"","right":false},{"type":"img","image":"http://staging-teach.cdn.ireadabc.com/e6ea7e0efa41ddfbcbbd6e01581a1d2f.png","audio":"","text":"","right":false},{"type":"txt","image":"","audio":"","text":"like","right":false},{"type":"txt","image":"","audio":"","text":"six","right":false}],"audioName":"请在5秒内说出正确答案.mp3"}],"bgAudio":"","bgAudioName":"","audioName":""} {
"onlineFlg": false,
"title": "钓鱼大作战", "questionText": "海洋里有很多鱼,每条鱼身上都藏着魔法信息!亲爱的小玩家,请仔细听游戏指令,找到含有正确魔法信息的鱼,快速完成钓鱼。 在本次的游戏中,你将和其他玩家进行PK,游戏结束,钓鱼数量最多的玩家,将获得胜利。最后根据钓鱼的数量,你将获得相应的能量石奖励!开始挑战吧!", "questionTextAudio": "http://staging-teach.cdn.ireadabc.com/e422c682ff3304a532937db64573caa4.mp3", "questions": [{
"questionAudio": "http://staging-teach.cdn.ireadabc.com/c9db9c8f9c256b928a7f0e1498963404_l.mp3", "duration": 120,
"options": [
{ "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/7782399d0ad0b9578b2109c620d64465.png", "audio": "", "text": "", "right": true },
{ "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/e283a9417dbb578b83c05c5969b4865b.png", "audio": "", "text": "", "right": true }, { "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/bd01e5bfb67be451fc282671d1b9d883.png", "audio": "", "text": "", "right": false }, { "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/5ac88495707336f3d34708f0f174a8f0.jpg", "audio": "", "text": "", "right": false }], "audioName": "ready go.mp3"
}, { "questionAudio": "http://staging-teach.cdn.ireadabc.com/cb76dbc838567b58e2af36e2d2faa923_l.mp3", "duration": 120, "options": [{ "type": "txt", "image": "", "audio": "", "text": "push", "right": false }, { "type": "txt", "image": "", "audio": "", "text": "monkey", "right": true }, { "type": "txt", "image": "", "audio": "", "text": "book", "right": true }, { "type": "txt", "image": "", "audio": "", "text": "bee", "right": false }], "audioName": "图片卡片出现.mp3" }, { "questionAudio": "http://staging-teach.cdn.ireadabc.com/6d742645880f902efae878facc78da07_l.mp3", "duration": 120, "options": [{ "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/3a7fdd71c900985e8f493d8e4035bf84.png", "audio": "", "text": "", "right": false }, { "type": "img", "image": "http://staging-teach.cdn.ireadabc.com/e6ea7e0efa41ddfbcbbd6e01581a1d2f.png", "audio": "", "text": "", "right": false }, { "type": "txt", "image": "", "audio": "", "text": "like", "right": false }, { "type": "txt", "image": "", "audio": "", "text": "six", "right": false }], "audioName": "请在5秒内说出正确答案.mp3" }], "bgAudio": "", "bgAudioName": "", "audioName": ""
}
// { // {
// "recordFlag": true, // "recordFlag": true,
// "title": "test", // "title": "test",
......
[
{
"__type__": "cc.SceneAsset",
"_name": "",
"_objFlags": 0,
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_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,
"y": 0
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_is3DNode": true,
"_groupIndex": 0,
"groupIndex": 0,
"autoReleaseAssets": false,
"_id": "80e5878a-4056-40c6-9d42-0202779a00d0"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
}
],
"_active": true,
"_components": [
{
"__id__": 5
},
{
"__id__": 6
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
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": "3cBzD9IotHb5Pj5l8g4Kym"
},
{
"__type__": "cc.Node",
"_name": "Main Camera",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_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": [
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": "9eZOLudRdCqJ30e4xDyXYZ"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"_cullingMask": 4294967295,
"_clearFlags": 7,
"_backgroundColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": -1,
"_zoomRatio": 1,
"_targetTexture": null,
"_fov": 60,
"_orthoSize": 10,
"_nearClip": 1,
"_farClip": 4096,
"_ortho": true,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_renderStages": 1,
"_alignWithScreen": true,
"_id": "9eFwUZ+NpBK6r8zbor4ASZ"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_fitWidth": false,
"_fitHeight": true,
"_id": "c0+F2WFRNDjbsIROVJbsav"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "32T3e0fMBHYpgPSorh6UPM"
}
]
\ No newline at end of file
{
"ver": "1.2.9",
"uuid": "ba2f24ba-f64f-40a7-bbf0-47f557a7c27c",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
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