Commit c213ad29 authored by liujiangnan's avatar liujiangnan

feat:为了更适配手机操作,改成拍气球

parent 58658daa
...@@ -85,7 +85,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -85,7 +85,6 @@ export class PlayComponent implements OnInit, OnDestroy {
bg; bg;
weapon_pic;
weaponTouch = false; weaponTouch = false;
...@@ -923,48 +922,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -923,48 +922,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this.restartArr.push(restart_pic); this.restartArr.push(restart_pic);
this.restartPic = restart_pic; this.restartPic = restart_pic;
//初始化武器图片
this.initWeaponPic();
}
/**
* 初始化武器图片
*/
initWeaponPic(){
const weapon = new MySprite();
weapon.init(this.images.get('weapon'));
weapon.x = this.canvasWidth / 2;
weapon.y = this.canvasHeight - weapon.height / 2;
weapon.alpha = 0;
weapon.setScaleXY(this.mapScale);
this.weapon_pic = weapon;
this.renderArr.push(weapon);
const weapon_fire = new MySprite();
weapon_fire.init(this.images.get('weapon_fire'));
weapon_fire.alpha = 0;
weapon_fire.setScaleXY(this.mapScale);
this.weapon_fire_pic = weapon_fire;
this.renderArr.push(weapon_fire);
}
/**
* 初始化子弹图片
*/
initBulletPic(){
const bullet = new MySprite();
bullet.init(this.images.get('bullet'));
bullet.y = this.canvasHeight - this.weapon_pic.height - bullet.height/2;
bullet.setScaleXY(this.mapScale);
return bullet;
} }
/** /**
...@@ -1332,12 +1289,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1332,12 +1289,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this.practiceEnd = false; this.practiceEnd = false;
this.temp_max_ballon = this.max_ballon; this.temp_max_ballon = this.max_ballon;
if(this.weapon_pic){
this.weapon_pic.x = this.canvasWidth / 2;
this.weapon_pic.y = this.canvasHeight - this.weapon_pic.height / 2 * this.mapScale;
}
} }
getAnswerPic(answer){ getAnswerPic(answer){
...@@ -1591,10 +1542,14 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1591,10 +1542,14 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
if (this.checkClickTarget(this.weapon_pic)) { // 点击漂浮出来的气球
this.weaponTouch = true; for (let i = 0; i < this.ballon_temp_arr.length; i++) {
const item = this.ballon_temp_arr[i];
if (item.show&&this.checkClickTarget(item.pic)) {
this.checkClickBoom(item);
return; return;
} }
}
if (this.checkClickTarget(this.playPic) && !this.playing) { if (this.checkClickTarget(this.playPic) && !this.playing) {
...@@ -1620,77 +1575,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1620,77 +1575,9 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
mapMove(event) { mapMove(event) {
//光标在武器满围内
if (this.checkClickTarget(this.weapon_pic)) {
//武器被按下,则随坐标移动
if(this.weaponTouch){
//如果移动超过屏幕,则不移动
if((this.mx + this.weapon_pic.width/2) > this.canvasWidth || this.mx < this.weapon_pic.width/2){
return;
}
this.weapon_pic.x = this.mx;
}
return;
}
} }
mapUp(event) { mapUp(event) {
if(!this.canTouch){
return;
}
//武器按下弹起,则发射子弹
if (this.checkClickTarget(this.weapon_pic)) {
this.weaponTouch = false;
//显示武器发射状态
this.weapon_fire_pic.x = this.weapon_pic.x;
this.weapon_fire_pic.y = this.weapon_pic.y;
this.weapon_fire_pic.alpha = 1;
this.weapon_pic.alpha = 0;
setTimeout(() => {
this.playAudio('fire');
}, 10);
//显示子弹
let bullet_pic = this.initBulletPic();
bullet_pic.x = this.weapon_pic.x;
this.bulletRenderArr.push(bullet_pic);
let bullet = {
pic:bullet_pic,
hit:false
};
let out = -bullet_pic.height;
let bulletTween = tweenChange(bullet.pic, {y: out}, 1, ()=>{
removeItemFromArr(this.bulletRenderArr, bullet);
},null,()=>{
this.checkHit(bullet, bulletTween);
});
//显示武器准备状态
this.weapon_fire_pic.alpha = 0;
this.weapon_pic.alpha = 1;
return;
}
else{
//如果是武器被按下,且坐标未在武器坐标内,则清除被按下状态
if(this.weaponTouch){
this.weaponTouch = false;
}
}
} }
/** /**
...@@ -1717,80 +1604,25 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1717,80 +1604,25 @@ export class PlayComponent implements OnInit, OnDestroy {
return canShoot; return canShoot;
} }
/** checkClickBoom(answer){
* 检查是否碰撞 if("1" !== answer.correct){
* @param item this.playAudio('wrong');
* @param bulletTween //console.log('answer.suspension', answer.suspension);
*/ answer.canShake = true;
checkHit(item, bulletTween){
if(!item){
return;
}
//已经击中,不检查
if(item.hit){
return;
}
let x = item.pic.x;
let y = item.pic.y;
//坐标出去后不检查
if(y < 0){
return; return;
} }
for(let i = 0; i < this.ballon_temp_arr.length; ++ i){
let answer = this.ballon_temp_arr[i];
const rect = answer.pic.getBoundingBox();
if (this.checkPointInRect(x, y, rect)) {
//气球飞出屏幕,不处理
if(answer.pic.y < 0){
break;
}
bulletTween.pause();
//延迟隐藏子弹
setTimeout(() => {
item.pic.scaleY = 0;
item.pic.scaleX = 0;
item.pic.alpha=0;
bulletTween.resume();
}, 100);
item.hit = true;
//正确答案 //正确答案
if("1" == answer.correct){
//设置答案被选中 //设置答案被选中
answer.hited = true; answer.hited = true;
answer.pic.scaleX = 0; answer.pic.scaleX = 0;
answer.pic.scaleY = 0; answer.pic.scaleY = 0;
answer.pic.visible = false; answer.pic.visible = false;
this.showParticle(answer.pic); this.showParticle(answer.pic);
this.playAudio('right'); this.playAudio('right');
this.curRightAnswerNum = this.curRightAnswerNum - 1; this.curRightAnswerNum = this.curRightAnswerNum - 1;
//练习题结束,播放庆祝界面 //练习题结束,播放庆祝界面
if(this.curRightAnswerNum < 1){ if(this.curRightAnswerNum < 1){
this.practiceEnd = true; this.practiceEnd = true;
//重置音频 //重置音频
...@@ -1801,81 +1633,44 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1801,81 +1633,44 @@ export class PlayComponent implements OnInit, OnDestroy {
//如果当前索引与练习题相等,则为最后一道题,则播放结束画面 //如果当前索引与练习题相等,则为最后一道题,则播放结束画面
if(this.nextPracticeIndex == this.data.practices.length){ if(this.nextPracticeIndex == this.data.practices.length){
this.playEnd(true); this.playEnd(true);
(<any> window).courseware.sendEvent('gameEnd'); (<any> window).courseware.sendEvent('gameEnd');
console.log('send gameEnd event'); console.log('send gameEnd event');
//显示重新开始按钮 //显示重新开始按钮
setTimeout(() => { setTimeout(() => {
this.restartPic.alpha = 1; this.restartPic.alpha = 1;
this.playPic.alpha = 0; this.playPic.alpha = 0;
this.weapon_pic.alpha=0;
let out = this.canvasHeight - (this.restartPic.height/2 - 40) * this.restartPic.scaleY; let out = this.canvasHeight - (this.restartPic.height/2 - 40) * this.restartPic.scaleY;
tweenChange(this.restartPic, {y: out}, 1, ()=>{ tweenChange(this.restartPic, {y: out}, 1, ()=>{
this.canRestart = true; this.canRestart = true;
this.canTouch = true; this.canTouch = true;
}); });
}, 1000); }, 1000);
}else{
}
else{
this.playEnd(false); this.playEnd(false);
} }
}else{
}
else{
removeItemFromArr(this.curAnswerArr, answer.pic); removeItemFromArr(this.curAnswerArr, answer.pic);
console.log('answer hit index', this.curanswers.indexOf(answer)); console.log('answer hit index', this.curanswers.indexOf(answer));
//将命中的气球从当前答案中移出 //将命中的气球从当前答案中移出
removeItemFromArr(this.curanswers, answer); removeItemFromArr(this.curanswers, answer);
console.log('answer hit index', this.ballon_temp_arr.indexOf(answer)); console.log('answer hit index', this.ballon_temp_arr.indexOf(answer));
removeItemFromArr(this.ballon_temp_arr, answer); removeItemFromArr(this.ballon_temp_arr, answer);
this.ballonProducer(false, answer.pic.x); this.ballonProducer(false, answer.pic.x);
} }
} }
else{
this.playAudio('wrong');
//console.log('answer.suspension', answer.suspension);
answer.canShake = true;
}
break;
}
}
/**
}
/**
* 开始游戏 * 开始游戏
*/ */
startGame(){ startGame(){
this.playAudio("start"); this.playAudio("start");
setTimeout(() => { setTimeout(() => {
let out = this.canvasHeight + this.startPic.height; let out = this.canvasHeight + this.startPic.height;
tweenChange(this.startPic, {y: out}, .3, ()=>{ tweenChange(this.startPic, {y: out}, .3, ()=>{
this.weapon_pic.alpha=1;
this.started = true; this.started = true;
this.playPic.alpha = 1; this.playPic.alpha = 1;
this.initPracticePic(); this.initPracticePic();
...@@ -1887,7 +1682,7 @@ startGame(){ ...@@ -1887,7 +1682,7 @@ startGame(){
}, 50); }, 50);
}); });
}, 200); }, 200);
} }
/** /**
* 重新开始游戏 * 重新开始游戏
...@@ -1896,8 +1691,6 @@ startGame(){ ...@@ -1896,8 +1691,6 @@ startGame(){
let out = this.canvasHeight + this.restartPic.height; let out = this.canvasHeight + this.restartPic.height;
tweenChange(this.restartPic, {y: out}, .3, ()=>{ tweenChange(this.restartPic, {y: out}, .3, ()=>{
this.weapon_pic.alpha=1;
this.playPic.alpha = 1; this.playPic.alpha = 1;
this.initRestartData(); this.initRestartData();
...@@ -1918,7 +1711,6 @@ startGame(){ ...@@ -1918,7 +1711,6 @@ startGame(){
* @param balloon * @param balloon
*/ */
showParticle(balloon){ showParticle(balloon){
showPopParticle(this.images.get('star'), {x: balloon.x,y: balloon.y} ,this.bg); showPopParticle(this.images.get('star'), {x: balloon.x,y: balloon.y} ,this.bg);
} }
......
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