Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fireballoon
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
fireballoon
Commits
81e8df3c
Commit
81e8df3c
authored
May 18, 2022
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
热气球数据传输调整
parent
56532f95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
48 deletions
+40
-48
fireballoon.ts
assets/fireballoon/scene/fireballoon.ts
+30
-48
Game.ts
assets/fireballoon/scene/tool/Game.ts
+10
-0
No files found.
assets/fireballoon/scene/fireballoon.ts
View file @
81e8df3c
...
...
@@ -90,6 +90,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
initData
()
{
Game
.
getIns
().
init
(
this
.
data
);
Game
.
getIns
().
reset
();
this
.
tryData
=
[];
// 所有全局变量 默认都是null
this
.
_cantouch
=
true
;
}
...
...
@@ -118,13 +119,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
!
Game
.
getIns
().
isOver
)
return
pg
.
event
.
emit
(
"
game_start
"
);
//发送给上端最后的数据
// alert("game_finish")
let
player
=
{
right
:
Game
.
getIns
().
player
.
score
,
error
:
Game
.
getIns
().
player
.
error
}
let
robot
=
{
right
:
Game
.
getIns
().
robot
.
score
,
error
:
Game
.
getIns
().
robot
.
error
}
if
(
Game
.
getIns
().
singleGame
)
{
onHomeworkFinish
({
player
})
}
else
{
onHomeworkFinish
({
player
,
robot
})
}
// int total
// int right
// int[] scores
// let player = { right: Game.getIns().player.score, error: Game.getIns().player.error }
let
data
:
any
=
{};
data
.
total
=
Game
.
getIns
().
player
.
score
;
data
.
right
=
Game
.
getIns
().
player
.
right
;
data
.
scores
=
Game
.
getIns
().
player
.
voices
;
onHomeworkFinish
(
data
)
})
}
onTouchStart
()
{
...
...
@@ -154,6 +158,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
list
=
JSON
.
parse
(
JSON
.
stringify
(
list
));
list
.
sort
((
A
,
B
)
=>
{
return
Math
.
random
()
<
0.5
});
this
.
list
=
list
;
Game
.
getIns
().
player
.
addScore
(
this
.
list
.
length
);
this
.
count
=
0
;
this
.
lastCount
=
null
;
this
.
fishs
=
[];
...
...
@@ -210,7 +215,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
//左往右
item
.
x
=
-
1334
/
2
+
Math
.
random
()
*
1334
;
item
.
y
=
-
(
720
/
2
+
Math
.
random
()
*
400
);
//
cc
.
tween
(
item
).
to
(
10
+
Math
.
random
()
*
10
,
{
y
:
1500
}).
call
(()
=>
{
cc
.
tween
(
item
).
to
(
7
+
Math
.
random
()
*
6
,
{
y
:
1500
}).
call
(()
=>
{
data
.
fish
.
isOut
=
FISH_OUT
.
OUT
;
this
.
viewFishs
=
this
.
viewFishs
.
filter
(
v
=>
v
.
id
!=
data
.
id
);
}).
start
();
...
...
@@ -332,10 +337,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
fishingRight
(
item
,
layout
,
data
:
Option
,
wpos
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
if
(
wpos
.
x
>
cc
.
view
.
getCanvasSize
().
width
/
2
+
1
00
)
{
if
(
wpos
.
x
>
1334
/
2
+
2
00
)
{
//弹弓动画。
await
this
.
playGun
(
GUN_STATE
.
SHUT_RIGHT
);
}
else
if
(
wpos
.
x
<
cc
.
view
.
getCanvasSize
().
width
/
2
-
1
00
)
{
}
else
if
(
wpos
.
x
<
1334
/
2
-
2
00
)
{
//弹弓动画。
await
this
.
playGun
(
GUN_STATE
.
SHUT_LEFT
);
}
else
{
...
...
@@ -358,45 +363,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
// data.audioUrl && pg.audio.playAudioByUrl(data.audioUrl)
});
}
fishingError
(
item
,
layout
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
audio
.
playLocalAudio
(
pg
.
view
.
find
(
this
.
res
,
"
audio/error
"
))
if
(
data
.
fish
.
isLeft
)
{
//左往右
cc
.
tween
(
item
).
to
(
3
,
{
x
:
1500
}).
call
(()
=>
{
data
.
fish
.
isOut
=
FISH_OUT
.
OUT
;
item
.
active
=
false
;
setTimeout
(()
=>
{
item
.
parent
=
null
;
},
1000
);
if
(
this
.
touchFishs
.
every
(
fish
=>
fish
.
id
!=
data
.
id
))
{
resolve
(
''
);
}
}).
start
();
}
else
{
//右往左
cc
.
tween
(
item
).
to
(
3
,
{
x
:
-
1500
}).
call
(()
=>
{
data
.
fish
.
isOut
=
FISH_OUT
.
OUT
;
item
.
active
=
false
;
setTimeout
(()
=>
{
item
.
parent
=
null
;
},
1000
);
if
(
this
.
touchFishs
.
every
(
fish
=>
fish
.
id
!=
data
.
id
))
{
resolve
(
''
);
}
}).
start
();
}
setTimeout
(()
=>
{
this
.
touching
=
false
;
},
500
);
});
}
fishing
(
item
,
layout
,
wpos
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
let
data
=
item
.
data
;
//item停止动画并
cc
.
Tween
.
stopAllByTarget
(
item
);
await
this
.
fishingRight
(
item
,
layout
,
data
,
wpos
);
// if (data.right) {
// await this.fishingRight(item, layout, data);
// } else {
// await this.fishingError(item, layout, data);
// }
this
.
touchFishs
.
push
(
data
);
return
resolve
(
data
.
right
);
});
}
...
...
@@ -406,16 +378,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
this
.
touching
)
return
;
let
item
:
cc
.
Node
=
e
.
target
;
let
p
=
e
.
touch
.
getLocation
();
let
wpos
=
item
.
convertToWorldSpaceAR
(
p
);
let
wpos
=
p
;
// let wpos = item.convertToWorldSpaceAR(p);
let
data
=
item
.
data
;
if
(
this
.
touchFishs
.
some
(
fish
=>
fish
.
id
==
data
.
id
))
return
;
if
(
data
.
fish
.
isOut
!=
FISH_OUT
.
RUNNING
)
return
;
this
.
touching
=
true
;
this
.
touchData
=
data
;
data
.
fish
.
isOut
=
FISH_OUT
.
TOUCH
;
let
isRight
=
await
this
.
fishing
(
item
,
this
.
layout_player
,
wpos
);
isRight
&&
Game
.
getIns
().
player
.
addScore
();
!
isRight
&&
Game
.
getIns
().
player
.
addError
();
await
this
.
fishing
(
item
,
this
.
layout_player
,
wpos
);
}
//机器人随机钓鱼
...
...
@@ -539,14 +510,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
recrodEnd
(
data
);
});
//结束录音
}
private
tryData
:
Array
<
Option
>
;
async
recrodEnd
(
data
)
{
Game
.
getIns
().
player
.
addVoice
(
data
);
let
score
=
data
.
result
.
overall
;
if
(
score
>=
80
)
{
//提示成功
this
.
updateTips
(
TIPS_STATE
.
GOOD
);
Game
.
getIns
().
player
.
addRight
();
this
.
touchFishs
.
push
(
this
.
touchData
);
}
else
{
//提示失败
this
.
updateTips
(
TIPS_STATE
.
TRY
);
if
(
this
.
tryData
.
some
(
td
=>
td
.
id
==
this
.
touchData
.
id
))
{
this
.
updateTips
(
TIPS_STATE
.
COM
);
this
.
touchFishs
.
push
(
this
.
touchData
);
}
else
{
this
.
updateTips
(
TIPS_STATE
.
TRY
);
this
.
tryData
.
push
(
this
.
touchData
);
this
.
viewFishs
=
this
.
viewFishs
.
filter
(
v
=>
v
.
id
!=
this
.
touchData
.
id
);
}
}
await
pg
.
time
.
delay
(
3
);
this
.
updateTips
(
null
);
...
...
assets/fireballoon/scene/tool/Game.ts
View file @
81e8df3c
...
...
@@ -63,10 +63,14 @@ export class Item {
}
class
Role
{
public
score
:
number
;
public
right
:
number
;
public
error
:
number
;
public
voices
:
Array
<
any
>
;
constructor
()
{
this
.
score
=
0
;
this
.
error
=
0
;
this
.
right
=
0
;
this
.
voices
=
[];
}
addScore
(
score
:
number
=
1
)
{
this
.
score
+=
score
;
...
...
@@ -74,6 +78,12 @@ class Role {
addError
(
score
:
number
=
1
)
{
this
.
error
+=
score
;
}
addRight
()
{
this
.
right
+=
1
;
}
addVoice
(
obj
:
any
)
{
this
.
voices
.
push
(
obj
);
}
}
export
class
Player
extends
Role
{
constructor
()
{
...
...
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