Commit 3061251d authored by linzhiguo's avatar linzhiguo

+ 基本逻辑完成

parent fe697c57
This diff is collapsed.
......@@ -10,12 +10,13 @@ cc.Class({
default:[],
type: cc.Node
},
flyVirus:{
flyPositions:{
default:[],
type: cc.Node
},
virusFalls:{
flyVirus:{
default:[],
type: cc.Node
},
......@@ -95,11 +96,7 @@ cc.Class({
preView(){
for(let i = 0; i < 2; i ++){
this.setOrignPos(this.flys[i]);
this.setOrignPos(this.virusFalls[i]);
this.setTextVar(this.flyVirus[i]);
this.setTextVar(this.virusFalls[i]);
this.setTextVar(this.virusOks[i]);
}
......@@ -131,16 +128,17 @@ cc.Class({
this._cup = cc.find('Canvas/bg/cup');
this._bad_water = this._cup.getChildByName('bad_water');
this._bad_water.active = false;
this._flyswatter = cc.find('Canvas/flyswatter');
this.setOrignPos(this._flyswatter);
},
cleanFlys(){
this.flys[0].x = this.flys[0]._x + this._frameSize.width * 1.5;
this.flys[1].x = this.flys[1]._x + this._frameSize.width * 1.5;
this.virusFalls[0].active = false;
this.virusFalls[1].active = false;
this.virusOks[0].active = false;
this.virusOks[1].active = false;
for(let i = 0; i < 2; i++){
this.flys[i].x = this.flys[i]._x + this._frameSize.width * 1.5;
this.flys[i].y = this.flys[i]._y;
this.virusOks[i].active = false;
}
},
setTextVar(node){
......@@ -214,7 +212,7 @@ cc.Class({
initView() {
this._time_node = cc.find('res/time');
this._index = 0;
this._time = this.data.time;
this.titleText.string = this.data.title;
......@@ -223,6 +221,19 @@ cc.Class({
let data = this.shuffle(this.data.sitems);
this.data = data;
let bg = cc.find('Canvas/bg');
for(let i = 0; i < 2; i ++){
let pos = this.flyPositions[i].convertToWorldSpaceAR(cc.v2(0,0));
let pos1 = bg.convertToNodeSpaceAR(cc.v2(pos.x, pos.y))
console.log(pos);
console.log(pos1);
this.flys[i]._x = pos1.x;
this.flys[i]._y = pos1.y;
}
this.cleanFlys();
this.updateArea();
this.updateItem();
this._cup._y = this._cup.y;
......@@ -235,6 +246,43 @@ cc.Class({
else{
this.playGame();
}
this.node.on(cc.Node.EventType.TOUCH_START, (event)=>{
if (this._touched == true)
return;
let canvas = cc.find('Canvas');
let pos = canvas.convertToNodeSpaceAR(cc.v2(event.touch._point.x, event.touch._point.y))
let item;
for(let i = 0; i < 2; i++){
item = this.flys[i];
if (cc.rect(item.getBoundingBoxToWorld()).contains(event.touch._point)){
this._flyswatter.x = pos.x;
this._flyswatter.y = pos.y;
this._touched = false;
cc.tween(this._flyswatter)
.delay(0.5)
.call(()=>{
this._flyswatter.y = -10000;
})
.start();
this.cleanTimer();
if (i != this._correct_index){
playDragonBoneAnimation(item, 'dizzy', 1, ()=>{
this.setTimer();
playDragonBoneAnimation(item, 'nomral', -1);
});
}
else{
this.fallCare();
}
return;
}
}
}, this);
},
playGame(){
......@@ -249,12 +297,32 @@ cc.Class({
},
setTimer(){
this._timer_ani = cc.tween(this.node)
.delay(this._time)
this._current_time = this._time_node.x;
this._timer_ani = cc.tween(this._time_node)
.to(this._current_time, {x: 0})
.call(()=>{
this.flyOut();
})
.start();
for(let i = 0; i < 2; i++){
this.flys[i]._move_to_cup = cc.tween(this.flys[i])
.to(this._current_time, {y: this.flys[i]._y -120})
.start();
}
},
cleanTimer(){
if (this._timer_ani){
this._timer_ani.stop();
this._timer_ani = null;
}
for(let i = 0; i < 2; i++){
if (this.flys[i]._move_to_cup){
this.flys[i]._move_to_cup.stop();
this.flys[i]._move_to_cup = null;
}
}
},
updateArea(){
......@@ -280,19 +348,21 @@ cc.Class({
updateItem(){
this._tapped = false;
this._time_node.x = this._time;
let info = this.data[this._index];
info.correct.length = Math.min(info.correct.length, 3);
info.incorrect.length = Math.min(info.incorrect.length, 3);
this._correct_index = 0;
let idxs = [info.correct, info.incorrect];
if (RandomInt(2) == 0){
idxs = [info.incorrect, info.correct]
this._correct_index = 1;
}
for(let i = 0; i < 2; i++){
this.flyVirus[i]._text.string = idxs[i];
this.virusFalls[i]._text.string = idxs[i];
this.virusOks[i]._text.string = idxs[i];
}
},
......@@ -362,24 +432,17 @@ cc.Class({
.to(0.8, {x: this.flys[i]._x - this._frameSize.width * 1.5})
.start();
});
this.virusFalls[i].active = true;
this.virusFalls[i].y = this.virusFalls[i]._y;
cc.tween(this.virusFalls[i])
.to(0.5, {y: this.virusFalls[i]._y -118},{ easing: 'quadIn' })
.start();
}
cc.tween(this.node)
.delay(0.5)
.delay(0.2)
.call(()=>{
this.virusFalls[0].active = false;
this.virusFalls[1].active = false;
this.virusOks[0].active = true;
this.virusOks[1].active = true;
this._bad_water.active = true;
})
.delay(0.5)
.call(()=>{
this.cupMoveDown();
})
.start();
......@@ -387,7 +450,32 @@ cc.Class({
},
fallCare(){
this.updateFlag();
let fly;
for(let i = 0; i < 2; i++){
fly = this.flys[i];
if (i == this._correct_index){
playDragonBoneAnimation(fly, 'dizzy', -1);
cc.tween(fly)
.to(1, {y: fly._x - this._frameSize.height*1.5})
.start();
continue;
}
playDragonBoneAnimation(fly, 'scare', -1);
cc.tween(fly)
.to(1, {x: fly._x - this._frameSize.width * 1.5})
.start();
}
cc.tween(this._time_node)
.delay(1)
.call(()=>{
playDragonBoneAnimation(this.flys[0], 'normal', -1);
playDragonBoneAnimation(this.flys[1], 'normal', -1);
this.cupMoveDown();
})
.start();
},
cupMoveUp(){
......
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