Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSIWB2504
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
SSIWB2504
Commits
761b51d8
Commit
761b51d8
authored
Aug 02, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
8071bf10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
451 deletions
+10
-451
play.component.ts
src/app/play/play.component.ts
+10
-451
No files found.
src/app/play/play.component.ts
View file @
761b51d8
...
@@ -112,10 +112,6 @@ const position = {
...
@@ -112,10 +112,6 @@ const position = {
const
zIndexMap
=
{
const
zIndexMap
=
{
background
:
-
1001
,
background
:
-
1001
,
smallGrass
:
-
1000
,
cylinder
:
100
,
grass
:
10000
,
monkey
:
500
,
card
:
1000
card
:
1000
}
}
...
@@ -173,12 +169,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -173,12 +169,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// ------------ 游戏逻辑数据 ------------
// ------------ 游戏逻辑数据 ------------
m_moveElementArray
=
[]
m_moveElementArray
=
[]
m_stageRoll_x
=
0
;
m_gameOver
=
false
;
// 游戏结束标志
m_stageLength
=
0
;
m_monkeyPoints
=
[];
m_currentMonkeyPointer
=
0
;
m_totalQuestions
=
0
;
m_gameOver
=
false
;
// ------------------------------------
// ------------------------------------
...
@@ -291,7 +282,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -291,7 +282,7 @@ export class PlayComponent implements OnInit, OnDestroy {
/**
/**
* 初始化游戏
* 初始化游戏
* 依次初始化游戏中的各个元素,包括背景、
圆柱、草地、小草和猴子
* 依次初始化游戏中的各个元素,包括背景、
标题、按钮和字母块
*/
*/
initGame
()
{
initGame
()
{
// 初始化游戏背景
// 初始化游戏背景
...
@@ -311,16 +302,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -311,16 +302,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
initWords
();
this
.
initWords
();
// 初始化连接线
// 初始化连接线
this
.
drawConnectionLines
();
this
.
drawConnectionLines
();
// // 初始化圆柱(游戏中猴子跳跃的平台)
// this.initCylinder()
// // 初始化草地(游戏场景底部的装饰元素)
// this.initGrass()
// // 初始化小草(随机分布在场景中的装饰元素)
// this.initSmallGarss()
// // 初始化猴子(游戏的主角)
// this.initMonkey()
// // 让猴子进入场景
// this.g_cartoon.getCartoonElement("monkey").in()
}
}
/**
/**
...
@@ -330,16 +311,6 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -330,16 +311,6 @@ export class PlayComponent implements OnInit, OnDestroy {
cleanGameVar
()
{
cleanGameVar
()
{
// 清空移动元素数组
// 清空移动元素数组
this
.
m_moveElementArray
=
[]
this
.
m_moveElementArray
=
[]
// 重置舞台滚动距离
this
.
m_stageRoll_x
=
0
;
// 重置舞台长度
this
.
m_stageLength
=
0
;
// 清空猴子跳跃点数组
this
.
m_monkeyPoints
=
[];
// 重置当前猴子位置指针
this
.
m_currentMonkeyPointer
=
0
;
// 重置问题总数
this
.
m_totalQuestions
=
0
;
// 重置游戏结束标志
// 重置游戏结束标志
this
.
m_gameOver
=
false
;
this
.
m_gameOver
=
false
;
// 停止所有循环任务
// 停止所有循环任务
...
@@ -357,12 +328,10 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -357,12 +328,10 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
m_gameOver
=
true
;
this
.
m_gameOver
=
true
;
// 延迟500毫秒后执行结束动画
// 延迟500毫秒后执行结束动画
setTimeout
(()
=>
{
setTimeout
(()
=>
{
// 显示猴子周围的花瓣效果
// 显示花瓣效果
this
.
showCorrectPatal
(
"
monkey
"
,
5000
)
this
.
showCorrectPatal
(
"
card
"
,
5000
)
// 让猴子执行庆祝跳跃动画(跳动10次,每次500毫秒)
// 播放结束音效
this
.
g_cartoon
.
getCartoonElement
(
"
monkey
"
).
jumpCelebrate
(
10
)
// 跳动一次500ms
this
.
g_cartoon
.
playAudio
(
"
success
"
)
// 播放猴子跳动的音效
this
.
g_cartoon
.
playAudio
(
"
houzitiaodongsahua
"
)
},
500
)
},
500
)
}
}
...
@@ -1098,10 +1067,8 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1098,10 +1067,8 @@ export class PlayComponent implements OnInit, OnDestroy {
})
})
// 累加已移动的距离
// 累加已移动的距离
runDistance
+=
step
;
runDistance
+=
step
;
// 更新舞台滚动的总距离
// 判断是否达到目标距离
this
.
m_stageRoll_x
+=
step
if
(
runDistance
>
distance
)
{
// 判断是否达到目标距离或舞台右边界
if
(
runDistance
>
distance
||
this
.
m_stageRoll_x
>
(
this
.
m_stageLength
-
(
1280
*
this
.
g_mapScale
)))
{
// 清除定时器
// 清除定时器
clearInterval
(
id
)
clearInterval
(
id
)
// 如果有回调函数,则执行
// 如果有回调函数,则执行
...
@@ -1118,411 +1085,11 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1118,411 +1085,11 @@ export class PlayComponent implements OnInit, OnDestroy {
*/
*/
// 移除了stageDragMove方法,因为不再需要背景拖动功能
// 移除了stageDragMove方法,因为不再需要背景拖动功能
initCylinder
()
{
let
data
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
g_formData
.
dataArray
));
let
pos_y
=
[
510
,
550
,
600
]
let
currentX
=
150
let
distance
=
[
250
,
300
,
350
]
let
lastRandom
=
-
1
;
let
currentIndex
=
-
1
;
data
.
unshift
({})
data
.
push
({})
this
.
m_totalQuestions
=
data
.
length
let
last_index
=
data
.
length
-
1
data
.
forEach
((
item
,
index
)
=>
{
let
random_Y
=
Math
.
floor
(
Math
.
random
()
*
3
)
while
(
random_Y
==
lastRandom
)
{
random_Y
=
Math
.
floor
(
Math
.
random
()
*
3
)
}
lastRandom
=
random_Y
let
random_dis
=
Math
.
floor
(
Math
.
random
()
*
3
)
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
`cylinder-
${
index
}
`
,
"
MySprite
"
)
// 影子
let
shadowRight
=
new
MySprite
()
let
shadowLeft
=
new
MySprite
()
if
(
index
==
last_index
)
{
shadowRight
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
shadow-3
"
))
shadowLeft
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
shadow-4
"
))
}
else
{
shadowRight
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
shadow-1
"
))
shadowLeft
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
shadow-2
"
))
}
shadowRight
.
scaleX
=
43
/
shadowRight
.
width
shadowRight
.
scaleY
=
14
/
shadowRight
.
height
shadowLeft
.
scaleX
=
38
/
shadowLeft
.
width
shadowLeft
.
scaleY
=
16
/
shadowLeft
.
height
if
(
index
==
0
)
{
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
1-3
"
));
element
.
ref
.
scaleX
=
231
*
this
.
g_mapScale
/
element
.
ref
.
width
element
.
ref
.
scaleY
=
235
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
currentX
*
this
.
g_mapScale
element
.
ref
.
y
=
this
.
g_cartoon
.
getOrigin
().
y
+
350
*
this
.
g_mapScale
shadowRight
.
x
=
48
;
shadowRight
.
y
=
-
18
;
shadowLeft
.
x
=
-
53
;
shadowLeft
.
y
=
-
14
;
shadowRight
.
alpha
=
0
shadowLeft
.
alpha
=
0
element
.
switchToNormal
=
()
=>
{
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
1-4
"
))
element
.
ref
.
scaleX
=
197
*
this
.
g_mapScale
/
element
.
ref
.
width
element
.
ref
.
scaleY
=
156
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
x
=
element
.
ref
.
x
-
4
*
this
.
g_mapScale
element
.
ref
.
y
=
this
.
g_cartoon
.
getOrigin
().
y
+
387
*
this
.
g_mapScale
}
element
.
switchToHeighlight
=
()
=>
{
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
1-3
"
));
element
.
ref
.
scaleX
=
231
*
this
.
g_mapScale
/
element
.
ref
.
width
element
.
ref
.
scaleY
=
235
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
150
*
this
.
g_mapScale
element
.
ref
.
y
=
this
.
g_cartoon
.
getOrigin
().
y
+
350
*
this
.
g_mapScale
tweenChange
(
shadowRight
,
{
alpha
:
0.8
},
0.2
)
tweenChange
(
shadowLeft
,
{
alpha
:
0.8
},
0.2
)
}
element
.
switchToNormal
();
}
else
if
(
index
==
last_index
)
{
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
1
"
));
element
.
ref
.
scaleX
=
197
*
this
.
g_mapScale
/
element
.
ref
.
width
element
.
ref
.
scaleY
=
156
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
currentX
*
this
.
g_mapScale
element
.
ref
.
y
=
this
.
g_cartoon
.
getOrigin
().
y
+
480
*
this
.
g_mapScale
shadowRight
.
x
=
50
;
shadowRight
.
y
=
-
55
;
shadowLeft
.
x
=
-
55
;
shadowLeft
.
y
=
-
53
;
shadowRight
.
alpha
=
0
shadowLeft
.
alpha
=
0
}
else
{
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
1-2
"
));
element
.
ref
.
scaleX
=
197
*
this
.
g_mapScale
/
element
.
ref
.
width
element
.
ref
.
scaleY
=
156
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
currentX
*
this
.
g_mapScale
element
.
ref
.
y
=
this
.
g_cartoon
.
getOrigin
().
y
+
pos_y
[
random_Y
]
*
this
.
g_mapScale
shadowRight
.
x
=
50
;
shadowRight
.
y
=
-
53
;
shadowLeft
.
x
=
-
53
;
shadowLeft
.
y
=
-
50
;
shadowRight
.
alpha
=
0
shadowLeft
.
alpha
=
0
}
this
.
m_monkeyPoints
.
push
({
foot
:
element
.
ref
.
y
-
50
*
this
.
g_mapScale
,
line
:
random_Y
})
if
(
index
==
last_index
)
{
this
.
m_stageLength
=
currentX
*
this
.
g_mapScale
+
(
197
*
this
.
g_mapScale
)
/
2
+
100
*
this
.
g_mapScale
}
currentX
+=
distance
[
random_dis
]
element
.
ref
.
addChild
(
shadowRight
)
element
.
ref
.
addChild
(
shadowLeft
)
element
.
hideShadow
=
()
=>
{
tweenChange
(
shadowRight
,
{
alpha
:
0
},
0.1
)
tweenChange
(
shadowLeft
,
{
alpha
:
0
},
0.1
,
()
=>
{
if
(
index
==
0
)
{
setTimeout
(()
=>
{
element
.
switchToNormal
()
},
300
)
}
})
}
element
.
showShadow
=
()
=>
{
tweenChange
(
shadowRight
,
{
alpha
:
0.7
},
0.1
)
tweenChange
(
shadowLeft
,
{
alpha
:
0.7
},
0.1
)
}
element
.
getShadow
=
()
=>
{
return
{
right
:
shadowRight
,
left
:
shadowLeft
}
}
this
.
subscribeMoveEvent
(
`cylinder-
${
index
}
`
)
this
.
render
(
element
.
ref
,
zIndexMap
.
cylinder
+
index
)
let
cardVisbale
=
true
;
if
(
index
==
0
||
index
==
last_index
)
{
cardVisbale
=
false
}
this
.
createCard
(
item
,
`card-
${
index
}
`
,
element
.
ref
.
x
,
element
.
ref
.
y
,
cardVisbale
)
});
}
/**
* 初始化草地元素
* 在游戏场景中创建左右两侧的草地以及中间的草地元素
*/
initGrass
()
{
// 创建左侧草地元素
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
`grass-left`
,
"
MySprite
"
)
// 初始化左侧草地图像
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
grass-left
"
));
// 设置左侧草地X方向的缩放比例
element
.
ref
.
scaleX
=
249
*
this
.
g_mapScale
/
element
.
ref
.
width
// 设置左侧草地Y方向的缩放比例
element
.
ref
.
scaleY
=
169
*
this
.
g_mapScale
/
element
.
ref
.
height
// 设置左侧草地的X坐标位置
element
.
ref
.
x
=
(
element
.
ref
.
width
*
this
.
g_mapScale
)
/
2
// 设置左侧草地的Y坐标位置(位于画布底部)
element
.
ref
.
y
=
this
.
g_canvasHeight
-
(
element
.
ref
.
height
*
this
.
g_mapScale
)
/
2
// 订阅左侧草地的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
`grass-left`
)
// 将左侧草地添加到渲染队列,设置其Z轴顺序
this
.
render
(
element
.
ref
,
zIndexMap
.
grass
+
1
)
// 创建右侧草地元素
element
=
this
.
g_cartoon
.
createCartoonElement
(
`grass-right`
,
"
MySprite
"
)
// 初始化右侧草地图像
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
grass-right
"
));
// 设置右侧草地X方向的缩放比例
element
.
ref
.
scaleX
=
257
*
this
.
g_mapScale
/
element
.
ref
.
width
// 设置右侧草地Y方向的缩放比例
element
.
ref
.
scaleY
=
181
*
this
.
g_mapScale
/
element
.
ref
.
height
// 计算右侧草地的X坐标位置(位于舞台最右侧)
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
this
.
m_stageLength
-
(
element
.
ref
.
width
*
this
.
g_mapScale
)
/
2
+
(
this
.
g_canvasWidth
-
1280
*
this
.
g_mapScale
)
/
2
;
// 确保右侧草地不会超出画布左侧
if
(
element
.
ref
.
x
<
this
.
g_canvasWidth
)
{
element
.
ref
.
x
=
this
.
g_canvasWidth
-
(
element
.
ref
.
width
*
this
.
g_mapScale
)
/
2
;
}
// 设置右侧草地的Y坐标位置(位于画布底部)
element
.
ref
.
y
=
this
.
g_canvasHeight
-
(
element
.
ref
.
height
*
this
.
g_mapScale
)
/
2
// 订阅右侧草地的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
`grass-right`
)
// 将右侧草地添加到渲染队列,设置其Z轴顺序
this
.
render
(
element
.
ref
,
zIndexMap
.
grass
+
2
)
// 创建起始旗帜元素(默认不可见)
let
startFlag
=
this
.
g_cartoon
.
createCartoonElement
(
`start-flag`
,
"
MySprite
"
)
// 初始化起始旗帜图像
startFlag
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
flag
"
));
// 设置起始旗帜的X坐标位置
startFlag
.
ref
.
x
=
0
// 设置起始旗帜的Y坐标位置
startFlag
.
ref
.
y
=
0
// 默认隐藏起始旗帜
startFlag
.
ref
.
visible
=
false
;
// 订阅起始旗帜的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
"
start-flag
"
)
// 将起始旗帜添加到渲染队列,设置其Z轴顺序
this
.
render
(
startFlag
.
ref
,
-
2
)
// 创建结束旗帜元素(默认不可见)
let
endFlag
=
this
.
g_cartoon
.
createCartoonElement
(
`end-flag`
,
"
MySprite
"
)
// 初始化结束旗帜图像
endFlag
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
flag
"
));
// 设置结束旗帜的X坐标位置(位于右侧草地中间)
endFlag
.
ref
.
x
=
element
.
ref
.
x
+
(
element
.
ref
.
width
*
this
.
g_mapScale
)
/
2
// 设置结束旗帜的Y坐标位置
endFlag
.
ref
.
y
=
0
// 默认隐藏结束旗帜
endFlag
.
ref
.
visible
=
false
;
// 订阅结束旗帜的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
"
end-flag
"
)
// 将结束旗帜添加到渲染队列,设置其Z轴顺序
this
.
render
(
endFlag
.
ref
,
-
2
)
// 计算中间草地的数量:根据舞台长度计算需要多少组中间草地
let
total
=
Math
.
ceil
(
this
.
m_stageLength
/
(
1200
*
this
.
g_mapScale
))
// 定义三种不同尺寸的中间草地
let
midGlass
=
[
{
w
:
225
,
h
:
112
},
// 第一种中间草地尺寸
{
w
:
161
,
h
:
94
},
// 第二种中间草地尺寸
{
w
:
313
,
h
:
95
}
// 第三种中间草地尺寸
]
// 循环创建中间草地元素
for
(
let
index
=
0
;
index
<
total
-
1
;
index
++
)
{
// 随机选择一种中间草地类型
let
random
=
Math
.
floor
(
Math
.
random
()
*
3
);
// 创建中间草地元素
element
=
this
.
g_cartoon
.
createCartoonElement
(
`grass-min-
${
index
}
`
,
"
MySprite
"
)
// 初始化中间草地图像(根据随机选择的类型)
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
grass-mid-
"
+
(
random
+
1
)));
// 设置中间草地X方向的缩放比例
element
.
ref
.
scaleX
=
midGlass
[
random
].
w
*
this
.
g_mapScale
/
element
.
ref
.
width
// 设置中间草地Y方向的缩放比例
element
.
ref
.
scaleY
=
midGlass
[
random
].
h
*
this
.
g_mapScale
/
element
.
ref
.
height
// 设置中间草地的X坐标位置(均匀分布在舞台上)
element
.
ref
.
x
=
this
.
g_cartoon
.
getOrigin
().
x
+
(
index
+
1
)
*
800
*
this
.
g_mapScale
;
// 设置中间草地的Y坐标位置(位于画布底部)
element
.
ref
.
y
=
this
.
g_canvasHeight
-
(
element
.
ref
.
height
*
this
.
g_mapScale
)
/
2
// 订阅中间草地的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
`grass-min-
${
index
}
`
)
// 将中间草地添加到渲染队列,设置其Z轴顺序
this
.
render
(
element
.
ref
,
zIndexMap
.
grass
+
2
+
index
)
}
}
/**
* 初始化小草元素
* 在游戏场景中随机分布小草,增加场景丰富度
*/
initSmallGarss
()
{
// 计算小草的总数量:根据舞台长度计算需要多少组小草,每组5个
// 舞台长度除以1200像素(考虑缩放比例),向上取整后乘以5
let
total
=
Math
.
ceil
(
this
.
m_stageLength
/
(
1200
*
this
.
g_mapScale
))
*
5
// 计算垂直方向可以放置的小草行数
let
lineNumber
=
Math
.
floor
(
this
.
g_canvasHeight
/
(
20
*
this
.
g_mapScale
))
// 确定舞台长度,如果舞台长度小于1280,则使用1280作为最小长度
let
length
=
this
.
m_stageLength
<
1280
?
1280
:
this
.
m_stageLength
// 计算水平方向可以放置的小草列数
let
rowNumber
=
Math
.
floor
(
length
/
(
50
*
this
.
g_mapScale
))
// 循环创建指定数量的小草元素
for
(
let
index
=
0
;
index
<
total
;
index
++
)
{
// 随机生成小草的X坐标位置
let
randomX
=
Math
.
floor
(
Math
.
random
()
*
rowNumber
);
// 随机生成小草的Y坐标位置
let
randomY
=
Math
.
floor
(
Math
.
random
()
*
lineNumber
);
// 创建小草元素,使用MySprite类型
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
`small-grass-min-
${
index
}
`
,
"
MySprite
"
)
// 初始化小草图像
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
6-10
"
));
// 设置小草X方向的缩放比例
element
.
ref
.
scaleX
=
50
*
this
.
g_mapScale
/
element
.
ref
.
width
// 设置小草Y方向的缩放比例
element
.
ref
.
scaleY
=
20
*
this
.
g_mapScale
/
element
.
ref
.
height
// 设置小草的X坐标位置(随机分布)
element
.
ref
.
x
=
randomX
*
50
*
this
.
g_mapScale
//this.g_cartoon.getOrigin().x + (index+1)*800*this.g_mapScale;
// 设置小草的Y坐标位置(随机分布)
element
.
ref
.
y
=
randomY
*
20
*
this
.
g_mapScale
//this.g_canvasHeight - (element.ref.height*this.g_mapScale)/2
// 订阅小草的移动事件,使其能够随场景移动
this
.
subscribeMoveEvent
(
`small-grass-min-
${
index
}
`
)
// 将小草添加到渲染队列,设置其Z轴顺序
this
.
render
(
element
.
ref
,
zIndexMap
.
smallGrass
+
index
)
}
}
initMonkey
()
{
let
lineScale
=
[
1
,
1
,
1
]
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
"
monkey
"
,
"
MySprite
"
)
let
height
=
45
element
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
"
mike-1-2
"
));
let
sx
=
171
*
this
.
g_mapScale
/
element
.
ref
.
width
let
sy
=
241
*
this
.
g_mapScale
/
element
.
ref
.
height
element
.
ref
.
scaleX
=
sx
*
lineScale
[
this
.
m_monkeyPoints
[
0
].
line
];
element
.
ref
.
scaleY
=
sy
*
lineScale
[
this
.
m_monkeyPoints
[
0
].
line
];
element
.
ref
.
x
=
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-0`
).
ref
.
x
element
.
ref
.
y
=
-
this
.
g_canvasHeight
*
this
.
g_mapScale
let
inY
=
this
.
g_cartoon
.
getOrigin
().
y
+
350
*
this
.
g_mapScale
-
(
241
*
this
.
g_mapScale
)
/
2
-
5
*
this
.
g_mapScale
element
.
handY
=
element
.
ref
.
y
-
100
*
element
.
ref
.
scaleY
element
.
in
=
()
=>
{
setTimeout
(()
=>
{
this
.
g_cartoon
.
getCartoonElement
(
"
cylinder-0
"
).
switchToHeighlight
()
},
900
)
tweenChange
(
element
.
ref
,
{
y
:
inY
},
1
)
}
element
.
reposition
=
(
starCallBack
?,
endCallBack
?)
=>
{
// element.ref.scaleX = sx * lineScale[this.m_monkeyPoints[this.m_currentMonkeyPointer].line];
// element.ref.scaleY = sy * lineScale[this.m_monkeyPoints[this.m_currentMonkeyPointer].line];
let
targetX
=
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
ref
.
x
let
targetY
=
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
ref
.
y
-
(
241
*
this
.
g_mapScale
*
lineScale
[
this
.
m_monkeyPoints
[
this
.
m_currentMonkeyPointer
].
line
])
/
2
-
height
*
this
.
g_mapScale
//*lineScale[this.m_monkeyPoints[this.m_currentMonkeyPointer].line]
element
.
handY
=
targetY
-
200
*
element
.
ref
.
scaleY
starCallBack
&&
starCallBack
()
tweenChange
(
element
.
ref
,
{
scaleX
:
sx
*
lineScale
[
this
.
m_monkeyPoints
[
this
.
m_currentMonkeyPointer
].
line
],
scaleY
:
sy
*
lineScale
[
this
.
m_monkeyPoints
[
this
.
m_currentMonkeyPointer
].
line
]
},
500
)
this
.
movePaoWuxian
(
element
.
ref
,
{
x
:
targetX
,
y
:
targetY
},
500
,
()
=>
{
element
.
ref
.
x
=
targetX
element
.
ref
.
y
=
targetY
endCallBack
&&
endCallBack
()
})
}
element
.
jumpNext
=
(
starCallBack
?,
endCallBack
?)
=>
{
this
.
g_cartoon
.
stopAllAudio
()
this
.
stopAllTimeout
()
if
(
this
.
m_gameOver
)
{
this
.
g_enableMapDown
=
true
;
return
;
}
let
lastIndex
=
this
.
m_currentMonkeyPointer
this
.
m_currentMonkeyPointer
++
;
if
(
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
ref
.
x
>
(
this
.
g_cartoon
.
getOrigin
().
x
+
1100
*
this
.
g_mapScale
))
{
this
.
stageMoveLeft
(
600
*
this
.
g_mapScale
,
()
=>
{
this
.
g_cartoon
.
playAudio
(
"
houzitiaodong
"
)
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
lastIndex
}
`
).
hideShadow
()
setTimeout
(()
=>
{
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
showShadow
()
},
400
)
element
.
reposition
(
starCallBack
,
endCallBack
)
})
}
else
{
this
.
g_cartoon
.
playAudio
(
"
houzitiaodong
"
)
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
lastIndex
}
`
).
hideShadow
()
setTimeout
(()
=>
{
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
showShadow
()
},
400
)
element
.
reposition
(
starCallBack
,
endCallBack
)
}
}
element
.
jumpCelebrate
=
(
times
)
=>
{
let
runTime
=
500
/
5
let
a
=
-
0.05
*
this
.
g_mapScale
let
count
=
0
;
let
vy0
=
-
0.5
*
a
*
runTime
let
baseX
=
element
.
ref
.
x
let
baseY
=
element
.
ref
.
y
let
leftShadow
=
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
getShadow
().
left
let
rightShadow
=
this
.
g_cartoon
.
getCartoonElement
(
`cylinder-
${
this
.
m_currentMonkeyPointer
}
`
).
getShadow
().
right
let
baseLeftSX
=
leftShadow
.
scaleX
let
baseLeftSY
=
leftShadow
.
scaleY
let
baseRightSX
=
rightShadow
.
scaleX
let
baseRightSY
=
rightShadow
.
scaleY
let
v
=
0
;
let
_sca
;
let
id
=
setInterval
(()
=>
{
count
++
v
=
vy0
+
a
*
count
_sca
=
Math
.
abs
(
v
/
vy0
)
element
.
ref
.
y
-=
v
leftShadow
.
alpha
=
rightShadow
.
alpha
=
0.8
*
(
Math
.
abs
(
v
)
/
vy0
)
leftShadow
.
scaleX
=
baseLeftSX
*
_sca
leftShadow
.
scaleY
=
baseLeftSY
*
_sca
rightShadow
.
scaleX
=
baseRightSX
*
_sca
rightShadow
.
scaleY
=
baseRightSY
*
_sca
if
(
count
>
runTime
)
{
times
--
if
(
times
<=
0
)
{
clearInterval
(
id
)
// element.ref.x = baseX
element
.
ref
.
y
=
baseY
}
else
{
// element.ref.x = baseX
element
.
ref
.
y
=
baseY
count
=
0
}
}
},
5
);
this
.
m_setIntervalIDs
.
push
(
id
)
}
this
.
subscribeMoveEvent
(
"
monkey
"
)
this
.
subscribeMapDownEvent
(
"
monkey
"
,
()
=>
{
let
_pointer
=
this
.
m_currentMonkeyPointer
element
.
jumpNext
(()
=>
{
this
.
g_cartoon
.
getCartoonElement
(
`card-
${
_pointer
}
`
).
dorpToCylinder
(
_pointer
)
},
()
=>
{
this
.
g_cartoon
.
getCartoonElement
(
`card-
${
this
.
m_currentMonkeyPointer
}
`
).
dorpToHand
(()
=>
{
this
.
g_enableMapDown
=
true
;
})
})
})
this
.
render
(
element
.
ref
,
zIndexMap
.
monkey
)
}
createCard
(
data
,
id
,
x
,
y
,
visible
)
{
createCard
(
data
,
id
,
x
,
y
,
visible
)
{
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
id
,
"
MySprite
"
)
let
element
=
this
.
g_cartoon
.
createCartoonElement
(
id
,
"
MySprite
"
)
...
@@ -1553,23 +1120,15 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1553,23 +1120,15 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
element
.
dorpToHand
=
(
callback
)
=>
{
element
.
dorpToHand
=
(
callback
)
=>
{
if
(
this
.
m_totalQuestions
==
this
.
m_currentMonkeyPointer
+
1
)
{
this
.
endGame
()
this
.
g_enableMapDown
=
true
;
return
;
}
this
.
g_cartoon
.
playAudio
(
"
tupiantanchu
"
)
this
.
g_cartoon
.
playAudio
(
"
tupiantanchu
"
)
this
.
m_setTimeoutIDs
.
push
(
setTimeout
(()
=>
{
this
.
m_setTimeoutIDs
.
push
(
setTimeout
(()
=>
{
element
.
playAudio
()
element
.
playAudio
()
},
1000
))
},
1000
))
let
handY
=
this
.
g_cartoon
.
getCartoonElement
(
"
monkey
"
).
handY
// 移动卡片到指定位置
tweenChange
(
element
.
ref
,
{
y
:
handY
-
(
250
*
this
.
g_mapScale
)
/
2
},
0.2
,
()
=>
{
tweenChange
(
element
.
ref
,
{
y
:
400
*
this
.
g_mapScale
},
0.2
,
()
=>
{
callback
()
callback
()
})
})
}
}
element
.
dorpToCylinder
=
(
index
)
=>
{
tweenChange
(
element
.
ref
,
{
y
:
this
.
m_monkeyPoints
[
index
].
foot
-
(
350
*
this
.
g_mapScale
)
/
2
},
0.2
)
}
element
.
playAudio
=
()
=>
{
element
.
playAudio
=
()
=>
{
this
.
g_cartoon
.
playAudio
(
data
.
audio_url
)
this
.
g_cartoon
.
playAudio
(
data
.
audio_url
)
}
}
...
...
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