Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dfzx_mb_03
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
dfzx_mb_03
Commits
c213ad29
Commit
c213ad29
authored
Jan 14, 2021
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:为了更适配手机操作,改成拍气球
parent
58658daa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
281 deletions
+73
-281
play.component.ts
src/app/play/play.component.ts
+73
-281
No files found.
src/app/play/play.component.ts
View file @
c213ad29
...
...
@@ -85,7 +85,6 @@ export class PlayComponent implements OnInit, OnDestroy {
bg
;
weapon_pic
;
weaponTouch
=
false
;
...
...
@@ -923,48 +922,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
restartArr
.
push
(
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 {
this
.
practiceEnd
=
false
;
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
){
...
...
@@ -1591,10 +1542,14 @@ export class PlayComponent implements OnInit, OnDestroy {
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
;
}
}
if
(
this
.
checkClickTarget
(
this
.
playPic
)
&&
!
this
.
playing
)
{
...
...
@@ -1620,77 +1575,9 @@ export class PlayComponent implements OnInit, OnDestroy {
}
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
)
{
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 {
return
canShoot
;
}
/**
* 检查是否碰撞
* @param item
* @param bulletTween
*/
checkHit
(
item
,
bulletTween
){
if
(
!
item
){
return
;
}
//已经击中,不检查
if
(
item
.
hit
){
return
;
}
let
x
=
item
.
pic
.
x
;
let
y
=
item
.
pic
.
y
;
//坐标出去后不检查
if
(
y
<
0
){
checkClickBoom
(
answer
){
if
(
"
1
"
!==
answer
.
correct
){
this
.
playAudio
(
'
wrong
'
);
//console.log('answer.suspension', answer.suspension);
answer
.
canShake
=
true
;
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
.
pic
.
scaleX
=
0
;
answer
.
pic
.
scaleY
=
0
;
answer
.
pic
.
visible
=
false
;
this
.
showParticle
(
answer
.
pic
);
this
.
playAudio
(
'
right
'
);
this
.
curRightAnswerNum
=
this
.
curRightAnswerNum
-
1
;
//练习题结束,播放庆祝界面
if
(
this
.
curRightAnswerNum
<
1
){
this
.
practiceEnd
=
true
;
//重置音频
...
...
@@ -1801,81 +1633,44 @@ export class PlayComponent implements OnInit, OnDestroy {
//如果当前索引与练习题相等,则为最后一道题,则播放结束画面
if
(
this
.
nextPracticeIndex
==
this
.
data
.
practices
.
length
){
this
.
playEnd
(
true
);
(
<
any
>
window
).
courseware
.
sendEvent
(
'
gameEnd
'
);
console
.
log
(
'
send gameEnd event
'
);
//显示重新开始按钮
setTimeout
(()
=>
{
this
.
restartPic
.
alpha
=
1
;
this
.
playPic
.
alpha
=
0
;
this
.
weapon_pic
.
alpha
=
0
;
let
out
=
this
.
canvasHeight
-
(
this
.
restartPic
.
height
/
2
-
40
)
*
this
.
restartPic
.
scaleY
;
tweenChange
(
this
.
restartPic
,
{
y
:
out
},
1
,
()
=>
{
this
.
canRestart
=
true
;
this
.
canTouch
=
true
;
});
},
1000
);
}
else
{
}
else
{
this
.
playEnd
(
false
);
}
}
else
{
}
else
{
removeItemFromArr
(
this
.
curAnswerArr
,
answer
.
pic
);
console
.
log
(
'
answer hit index
'
,
this
.
curanswers
.
indexOf
(
answer
));
//将命中的气球从当前答案中移出
removeItemFromArr
(
this
.
curanswers
,
answer
);
console
.
log
(
'
answer hit index
'
,
this
.
ballon_temp_arr
.
indexOf
(
answer
));
removeItemFromArr
(
this
.
ballon_temp_arr
,
answer
);
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
"
);
setTimeout
(()
=>
{
let
out
=
this
.
canvasHeight
+
this
.
startPic
.
height
;
tweenChange
(
this
.
startPic
,
{
y
:
out
},
.
3
,
()
=>
{
this
.
weapon_pic
.
alpha
=
1
;
this
.
started
=
true
;
this
.
playPic
.
alpha
=
1
;
this
.
initPracticePic
();
...
...
@@ -1887,7 +1682,7 @@ startGame(){
},
50
);
});
},
200
);
}
}
/**
* 重新开始游戏
...
...
@@ -1896,8 +1691,6 @@ startGame(){
let
out
=
this
.
canvasHeight
+
this
.
restartPic
.
height
;
tweenChange
(
this
.
restartPic
,
{
y
:
out
},
.
3
,
()
=>
{
this
.
weapon_pic
.
alpha
=
1
;
this
.
playPic
.
alpha
=
1
;
this
.
initRestartData
();
...
...
@@ -1918,7 +1711,6 @@ startGame(){
* @param balloon
*/
showParticle
(
balloon
){
showPopParticle
(
this
.
images
.
get
(
'
star
'
),
{
x
:
balloon
.
x
,
y
:
balloon
.
y
}
,
this
.
bg
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment