Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
new-kickball
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wildfirecode13
new-kickball
Commits
33ddc46a
Commit
33ddc46a
authored
Jun 13, 2019
by
任建锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--
parent
b8fc171e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
3795 additions
and
7 deletions
+3795
-7
ScenePlay_20190613174551.ts
.history/assets/scripts/scenes/ScenePlay_20190613174551.ts
+460
-0
ScenePlay_20190613193055.ts
.history/assets/scripts/scenes/ScenePlay_20190613193055.ts
+461
-0
ScenePlay_20190613193336.ts
.history/assets/scripts/scenes/ScenePlay_20190613193336.ts
+461
-0
ScenePlay_20190613194459.ts
.history/assets/scripts/scenes/ScenePlay_20190613194459.ts
+470
-0
ScenePlay_20190613194547.ts
.history/assets/scripts/scenes/ScenePlay_20190613194547.ts
+474
-0
ScenePlay_20190613200222.ts
.history/assets/scripts/scenes/ScenePlay_20190613200222.ts
+475
-0
ScenePlay_20190613200354.ts
.history/assets/scripts/scenes/ScenePlay_20190613200354.ts
+475
-0
ScenePlay_20190613201742.ts
.history/assets/scripts/scenes/ScenePlay_20190613201742.ts
+475
-0
main.scene
assets/scenes/main.scene
+24
-2
ScenePlay.ts
assets/scripts/scenes/ScenePlay.ts
+20
-5
No files found.
.history/assets/scripts/scenes/ScenePlay_20190613174551.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onError_ngameSubmit
()
{
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613193055.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onError_ngameSubmit
()
{
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613193336.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_ngameSubmit
()
{
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613194459.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613194547.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
};
this
.
broadcast
(
'callApi'
,
1
,
'orderStatus'
,
param
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613200222.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
};
this
.
broadcast
(
'callApi'
,
1
,
'orderStatus'
,
param
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
console
.
log
(
this
.
getNgameStartStatus
)
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613200354.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
};
this
.
broadcast
(
'callApi'
,
1
,
'orderStatus'
,
param
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
console
.
log
(
this
.
getOrderStatus
)
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
.history/assets/scripts/scenes/ScenePlay_20190613201742.ts
0 → 100644
View file @
33ddc46a
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
import
{
dynamic
,
engine
}
from
"scilla/src"
;
import
{
createSgin
}
from
"../net/webService"
;
import
{
Entity
,
Tween
}
from
"scilla/src"
;
import
{
Transform
}
from
'scilla-components/src'
;
import
{
createTween
,
ease
}
from
"scilla"
;
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
bg3
:
Entity
;
car
:
Entity
;
bridge
:
Entity
;
roadGroup
:
Entity
;
road_0
:
Entity
;
road_1
:
Entity
;
road_2
:
Entity
;
road_3
:
Entity
;
life_1
:
Entity
;
life_2
:
Entity
;
life_3
:
Entity
;
check_1
:
Entity
;
check_2
:
Entity
;
check_3
:
Entity
;
check_4
:
Entity
;
bottomGrass
:
Entity
;
carImage
:
Entity
;
score
:
number
;
firstGui
:
Entity
;
//关卡
checkpoint
=
0
//checkpointCounts=[3,8,18]
checkpointCounts
=
[
3
,
3
,
3
]
touchEnabled
=
true
;
onAwake
()
{
super
.
onAwake
();
this
.
bottomGrass
[
"Transform"
]
=
this
.
bottomGrass
.
getComponent
(
Transform
);
this
.
firstGui
[
"Transform"
]
=
this
.
firstGui
.
getComponent
(
Transform
);
this
.
car
[
"Transform"
]
=
this
.
car
.
getComponent
(
Transform
);
this
.
carImage
[
"Transform"
]
=
this
.
carImage
.
getComponent
(
Transform
);
this
.
bridge
[
"Transform"
]
=
this
.
bridge
.
getComponent
(
Transform
);
this
.
roadGroup
[
"Transform"
]
=
this
.
roadGroup
.
getComponent
(
Transform
);
this
.
road_0
[
"Transform"
]
=
this
.
road_0
.
getComponent
(
Transform
);
this
.
road_1
[
"Transform"
]
=
this
.
road_1
.
getComponent
(
Transform
);
this
.
road_2
[
"Transform"
]
=
this
.
road_2
.
getComponent
(
Transform
);
this
.
road_3
[
"Transform"
]
=
this
.
road_3
.
getComponent
(
Transform
);
this
.
bottomGrass
[
"Transform"
].
position
.
y
=
engine
.
renderContext
.
stageSize
.
height
;
this
.
check_1
[
"Transform"
]
=
this
.
check_1
.
getComponent
(
Transform
);
this
.
check_2
[
"Transform"
]
=
this
.
check_2
.
getComponent
(
Transform
);
this
.
check_3
[
"Transform"
]
=
this
.
check_3
.
getComponent
(
Transform
);
this
.
check_4
[
"Transform"
]
=
this
.
check_4
.
getComponent
(
Transform
);
this
.
bg1
[
"Transform"
]
=
this
.
bg1
.
getComponent
(
Transform
);
this
.
bg2
[
"Transform"
]
=
this
.
bg2
.
getComponent
(
Transform
);
this
.
bg3
[
"Transform"
]
=
this
.
bg3
.
getComponent
(
Transform
);
this
.
setFirstGui
()
this
.
setCarAnimation
()
this
.
bridgeInit
()
this
.
roadInit
()
this
.
bridgeFirst
=
true
;
this
.
check_1
[
"Transform"
].
alpha
=
0
;
this
.
check_2
[
"Transform"
].
alpha
=
0
;
this
.
check_3
[
"Transform"
].
alpha
=
0
;
this
.
check_4
[
"Transform"
].
alpha
=
0
;
this
.
carGoFirst
=
true
;
this
.
roadIndex
=
1
this
.
nowPos
=
null
;
this
.
lastPos
=
null
;
this
.
nextPos
=
null
;
this
.
nextWidth
=
null
;
this
.
lastIndex
=
1
this
.
touchEnabled
=
true
;
this
.
goCount
=
0
this
.
bgIndex
=
1
;
this
.
checkpoint
=
0
this
.
updataBgAndTop
()
this
.
bg1
[
"Transform"
].
position
.
x
=
0
;
this
.
bg2
[
"Transform"
].
position
.
x
=
0
;
this
.
bg3
[
"Transform"
].
position
.
x
=
0
;
this
.
road_0
[
"Transform"
].
position
.
x
=
0
;
this
.
road_1
[
"Transform"
].
position
.
x
=
518
;
this
.
road_2
[
"Transform"
].
position
.
x
=
1033
;
this
.
road_3
[
"Transform"
].
position
.
x
=
1526
;
this
.
roadGroup
[
"Transform"
].
position
.
x
=
0
;
this
.
car
[
"Transform"
].
position
.
x
=
105
;
}
onClick_firstGui
(){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
//引导页
setFirstGui
(){
if
(
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]){
this
.
setVisible
(
this
.
firstGui
,
false
)
}
else
{
localStorage
[
"firstGui"
+
window
[
"CFG"
].
actId
]
=
"1"
;
this
.
setVisible
(
this
.
firstGui
,
true
)
}
}
setCarAnimation
(){
createTween
(
this
,
this
.
carImage
[
"Transform"
],
true
,{
loop
:
-
1
})
.
set
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
0
,
y
:
0
}})
.
to
({
scale
:
{
x
:
.
98
,
y
:
.
98
},
position
:{
x
:.
5
,
y
:.
5
}},
50
)
.
to
({
scale
:
{
x
:
1
,
y
:
1
},
position
:{
x
:
-
.
5
,
y
:
-
.
5
}},
50
)
}
//是否隐藏对象
setVisible
(
obj
,
state
){
if
(
state
){
obj
[
"Transform"
].
alpha
=
1
;
obj
.
enabled
=
true
;
}
else
{
obj
[
"Transform"
].
alpha
=
0
;
obj
.
enabled
=
false
;
}
}
roadIndex
=
1
roadInit
(){
this
.
roadIndex
=
1
}
carInit
(){
this
.
car
[
"Transform"
].
position
.
x
=
105
this
.
car
[
"Transform"
].
position
.
y
=
807.5
}
carGoFirst
=
true
;
goCount
=
0
carGo
(){
var
distanceMin
=
0
var
distanceMax
=
0
if
(
this
.
roadIndex
==
1
){
console
.
log
(
"this.roadIndex"
)
console
.
log
(
this
.
roadIndex
)
if
(
this
.
carGoFirst
){
this
.
carGoFirst
=
false
;
distanceMin
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
distanceMax
=
518
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
+
this
[
"road_"
+
(
2
)][
"Transform"
].
width
console
.
log
(
"第一次"
)
}
else
{
distanceMin
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
1
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
distanceMin
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
distanceMax
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
-
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
width
-
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if
(
this
.
bridgeX
>
distanceMin
&&
this
.
bridgeX
<
distanceMax
){
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
100
}},
500
)
.
call
(()
=>
{
console
.
log
(
2233
)
this
.
roadGo
()
})
}
else
{
if
(
this
.
bridgeX
<
distanceMin
){
console
.
log
(
"长度不够"
)
}
if
(
this
.
bridgeX
>
distanceMax
){
console
.
log
(
"长度超出"
)
}
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
+
this
.
bridgeX
+
80
}},
500
)
.
call
(()
=>
{
this
.
onGameLose
()
})
}
}
nextLength
=
400
+
(
Math
.
random
()
*
100
)
nowPos
lastPos
nextPos
nextWidth
lastIndex
=
1
roadGo
(){
this
.
roadIndex
++
if
(
this
.
roadIndex
>
3
){
this
.
roadIndex
=
1
;
}
console
.
log
(
this
.
roadIndex
)
//缓存当前平台的位置
if
(
this
.
nowPos
){
this
.
lastPos
=
this
.
nowPos
;
}
else
{
this
.
lastPos
=
this
[
"road_1"
][
"Transform"
].
position
.
x
}
this
.
nextLength
=
400
+
(
Math
.
random
()
*
100
)
this
.
nowPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
this
.
nextPos
=
this
[
"road_"
+
(
this
.
roadIndex
)][
"Transform"
].
position
.
x
+
this
.
nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween
(
this
,
this
.
roadGroup
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
roadGroup
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
.
roadIndex
<
3
){
this
[
"road_"
+
(
this
.
roadIndex
+
1
)][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
else
{
console
.
log
()
this
[
"road_1"
][
"Transform"
].
position
.
x
=
this
.
nowPos
+
this
.
nextLength
}
})
//移动背景
createTween
(
this
,
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
if
(
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
<=-
750
){
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
position
.
x
+=
750
}
this
.
bridgeReset
()
setTimeout
(()
=>
{
this
.
touchEnabled
=
true
;
},
100
)
this
.
goCount
++
this
.
updataBgAndTop
()
})
//移动车辆
createTween
(
this
,
this
.
car
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
car
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
this
.
bridgeGo
()
}
bgIndex
=
1
;
updataBgAndTop
(){
this
.
bg1
[
"Transform"
].
alpha
=
0
;
this
.
bg2
[
"Transform"
].
alpha
=
0
;
this
.
bg3
[
"Transform"
].
alpha
=
0
;
if
(
this
.
goCount
>=
this
.
checkpointCounts
[
this
.
checkpoint
]){
this
.
goCount
=
0
;
this
.
checkpoint
++
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
onGameOver
()
}
}
if
(
this
.
checkpoint
<
3
){
this
.
bgIndex
=
this
.
checkpoint
+
1
}
if
(
this
.
checkpoint
>=
3
){
this
.
bgIndex
=
3
}
this
[
"bg"
+
(
this
.
bgIndex
)][
"Transform"
].
alpha
=
1
;
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
setTimeout
(()
=>
{
//this.bubbling('fuck', 'start');
//this.onGameOver();
},
3000
);
}
onGameOver
()
{
this
.
ngameSubmit
();
}
ngameSubmit
()
{
console
.
log
(
'createSgin'
,
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
sign
=
createSgin
(
this
.
doJoinData
,
this
.
score
,
'[]'
,
this
.
getNgameStartStatus
.
submitToken
);
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
score
:
this
.
score
,
gameData
:
'[]'
,
sgin
:
sign
,
dynamicData
:
'[]'
};
this
.
broadcast
(
'callApi'
,
1
,
'ngameSubmit'
,
param
);
}
onResponse_ngameSubmit
()
{
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
};
this
.
broadcast
(
'callApi'
,
1
,
'getOrderStatus'
,
param
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
console
.
log
(
this
.
getOrderStatus
)
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
bridgeState
=
false
onGlobalTouchBegin
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"begin"
)
this
.
bridgeState
=
true
this
.
bridgeReset
()
console
.
log
(
this
.
bridge
[
"Transform"
].
position
.
x
)
}
onGlobalTouchEnd
(
e
){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"end"
)
this
.
bridgeState
=
false
this
.
touchEnabled
=
false
;
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
rotation
:
0
},
400
)
.
call
(()
=>
{
this
.
carGo
()
})
}
onGlobalTouchMove
(){
if
(
!
this
.
touchEnabled
){
return
}
console
.
log
(
"move"
)
}
bridgeInit
(){
this
.
setBridgeX
(
1
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
;
}
bridgeReset
(){
this
.
bridgeX
=
0
;
this
.
bridge
[
"Transform"
].
scale
.
x
=
0
this
.
setBridgeX
(
2
)
this
.
bridge
[
"Transform"
].
position
.
y
=
892
;
}
//设置杆子的起始位置
bridgeFirst
=
true
;
setBridgeX
(
state
){
if
(
this
.
roadIndex
==
1
){
if
(
this
.
bridgeFirst
){
if
(
state
==
2
){
this
.
bridgeFirst
=
false
;
}
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
1
)][
"Transform"
].
width
-
26
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
4
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
4
)][
"Transform"
].
width
}
}
else
{
this
.
bridge
[
"Transform"
].
position
.
x
=
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
position
.
x
+
this
.
roadGroup
[
"Transform"
].
position
.
x
+
this
[
"road_"
+
(
this
.
roadIndex
-
1
)][
"Transform"
].
width
}
}
bridgeGo
(){
createTween
(
this
,
this
.
bridge
[
"Transform"
],
true
,{
loop
:
0
})
.
to
({
position
:
{
x
:
this
.
bridge
[
"Transform"
].
position
.
x
-
(
this
.
nowPos
-
this
.
lastPos
)}},
500
)
.
call
(()
=>
{
//this.carGo()
})
}
bridgeX
=
0
;
onEnterFrame
(){
if
(
this
.
bridge
[
"Transform"
]){
if
(
this
.
bridgeState
){
this
.
bridgeX
+=
40
this
.
bridge
[
"Transform"
].
scale
.
x
=
this
.
bridgeX
/
350
;
this
.
bridge
[
"Transform"
].
rotation
=-
90
;
}
}
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onUpdate
(
t
){
super
.
onUpdate
(
t
)
this
.
onEnterFrame
()
}
}
assets/scenes/main.scene
View file @
33ddc46a
...
...
@@ -319,7 +319,7 @@
"uuid": "4cf8cf2d-6adf-4f87-843b-617a35e35477"
}
],
"disabled":
tru
e
"disabled":
fals
e
},
{
"name": "ScenePlay",
...
...
@@ -364,7 +364,8 @@
"check_1": "entity|e4918819-07ed-4023-9cb5-7790865674c5",
"check_2": "entity|df4c7f2b-f693-43da-9b0b-bda88203620a",
"check_3": "entity|2e80cbfa-ef64-4383-acf9-6bd51183cadb",
"check_4": "entity|499f5470-a73f-46f4-bbcf-eff5192c9edf"
"check_4": "entity|499f5470-a73f-46f4-bbcf-eff5192c9edf",
"getOrderStatus": "dynamic|API|getOrderStatus"
}
},
{
...
...
@@ -387,6 +388,27 @@
}
]
}
},
{
"script": "./scripts/api/SamplePollingApi",
"properties": {
"name": "getOrderStatus",
"uri": "/hdtool/recon/getOrderStatus",
"onError": [
{
"entity": "entity|5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
"component": 1,
"method": "onError_orderStatus"
}
],
"onResponse": [
{
"entity": "entity|5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
"component": 1,
"method": "onResponse_orderStatus"
}
]
}
}
],
"uuid": "5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
...
...
assets/scripts/scenes/ScenePlay.ts
View file @
33ddc46a
...
...
@@ -13,6 +13,7 @@ import {createTween, ease} from "scilla";
export
default
class
ScenePlay
extends
InteractComponent
implements
INavigatorViewBase
{
doJoinData
:
dynamic
;
getNgameStartStatus
:
dynamic
;
getOrderStatus
:
dynamic
;
bg1
:
Entity
;
bg2
:
Entity
;
...
...
@@ -292,7 +293,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
this
[
"check_"
+
this
.
checkpoint
][
"Transform"
].
alpha
=
1
;
if
(
this
.
checkpoint
>=
3
){
this
[
"check_"
+
4
][
"Transform"
].
alpha
=
1
;
this
.
on
Response_ngameSubmit
()
this
.
on
GameOver
()
}
}
...
...
@@ -333,9 +334,27 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
onResponse_ngameSubmit
()
{
const
param
:
any
=
{
orderId
:
this
.
doJoinData
,
};
this
.
broadcast
(
'callApi'
,
1
,
'getOrderStatus'
,
param
);
}
onError_ngameSubmit
()
{
}
onResponse_orderStatus
()
{
//this.bubbling('showDialog', 'GameOver');
console
.
log
(
1
)
console
.
log
(
this
.
getOrderStatus
)
this
.
bubbling
(
'showDialog'
,
'GameOver'
);
}
onError_orderStatus
()
{
console
.
log
(
2
)
}
onGameLose
()
{
this
.
bubbling
(
'showDialog'
,
'GameLose'
);
}
...
...
@@ -430,10 +449,6 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
}
onError_ngameSubmit
()
{
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
...
...
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