Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
op_16
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
op_16
Commits
860b4b42
Commit
860b4b42
authored
Jun 08, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 单机可以玩了
parent
f62de039
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
281 additions
and
1412 deletions
+281
-1412
GOBE.d.ts
assets/op_16/GOBE/GOBE.d.ts
+247
-152
GOBE.js
assets/op_16/GOBE/GOBE.js
+2
-1218
package.json
assets/op_16/GOBE/package.json
+1
-1
op_16.ts
assets/op_16/scene/op_16.ts
+3
-2
NetworkHelper.ts
assets/op_16/script/NetworkHelper.ts
+24
-36
Server.ts
assets/op_16/script/Server.ts
+4
-3
No files found.
assets/op_16/GOBE/GOBE.d.ts
View file @
860b4b42
This diff is collapsed.
Click to expand it.
assets/op_16/GOBE/GOBE.js
View file @
860b4b42
This source diff could not be displayed because it is too large. You can
view the blob
instead.
assets/op_16/GOBE/package.json
View file @
860b4b42
...
@@ -2,6 +2,6 @@
...
@@ -2,6 +2,6 @@
"type"
:
"software"
,
"type"
:
"software"
,
"scope"
:
"game"
,
"scope"
:
"game"
,
"name"
:
"GameOBESDK"
,
"name"
:
"GameOBESDK"
,
"version"
:
"1.1.
4.301
"
,
"version"
:
"1.1.
5.300
"
,
"playbook"
:
""
"playbook"
:
""
}
}
\ No newline at end of file
assets/op_16/scene/op_16.ts
View file @
860b4b42
...
@@ -64,7 +64,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -64,7 +64,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
console
.
log
(
"
房主
"
);
console
.
log
(
"
房主
"
);
this
.
isRoomOwner
=
true
;
this
.
isRoomOwner
=
true
;
this
.
server
=
new
GameServer
(
2
,
this
.
networkHelper
);
this
.
server
=
new
GameServer
(
2
,
this
.
networkHelper
);
await
this
.
networkHelper
.
startFrameSync
();
this
.
server
.
addPlayer
({
this
.
server
.
addPlayer
({
uuid
:
this
.
playerId
,
uuid
:
this
.
playerId
,
isAI
:
false
,
isAI
:
false
,
...
@@ -647,8 +646,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -647,8 +646,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
dataList
.
push
(
frameData
);
dataList
.
push
(
frameData
);
}
}
dataList
.
forEach
(
async
(
item
)
=>
{
dataList
.
forEach
(
async
(
item
)
=>
{
if
(
!
item
.
data
)
{
return
;
}
console
.
log
(
item
);
console
.
log
(
item
);
return
;
if
(
this
.
server
)
{
if
(
this
.
server
)
{
this
.
server
.
onFrameEvent
(
item
.
data
);
this
.
server
.
onFrameEvent
(
item
.
data
);
...
...
assets/op_16/script/NetworkHelper.ts
View file @
860b4b42
...
@@ -33,7 +33,6 @@ export class NetworkHelper {
...
@@ -33,7 +33,6 @@ export class NetworkHelper {
appId
:
'
105879509
'
,
// 应用的ID
appId
:
'
105879509
'
,
// 应用的ID
openId
:
'
op_16
'
+
Math
.
random
(),
// 玩家ID
openId
:
'
op_16
'
+
Math
.
random
(),
// 玩家ID
});
});
console
.
log
(
this
.
client
);
await
this
.
client
.
init
();
await
this
.
client
.
init
();
}
}
...
@@ -41,41 +40,24 @@ export class NetworkHelper {
...
@@ -41,41 +40,24 @@ export class NetworkHelper {
async
joinRoom
(
roomType
:
string
,
maxPlayers
:
number
)
{
async
joinRoom
(
roomType
:
string
,
maxPlayers
:
number
)
{
const
matchRoomConfig
=
{
const
matchRoomConfig
=
{
matchParams
:
{
matchParams
:
{
matchRule
:
''
,
param1
:
'
param1
'
,
matchRule2
:
''
,
},
},
roomType
:
roomType
,
roomType
:
roomType
,
customRoomProperties
:
''
,
maxPlayers
:
maxPlayers
,
maxPlayers
:
maxPlayers
,
};
};
// 在线匹配参数
this
.
room
=
await
this
.
client
.
matchRoom
(
matchRoomConfig
);
const
matchPlayerConfig
=
{
playerInfo
:
{
playerId
:
'
xxxxxx
'
,
matchParams
:
{
test
:
1
,
// 匹配参数的属性需要与matchCode所属规则中配置的属性对应
},
},
matchCode
:
'
cc4dc617d3aa4f849824a12c3e8290c8
'
,
};
const
playerConfig
=
{
customPlayerStatus
:
0
,
customPlayerProperties
:
''
};
console
.
log
(
'
汪汪汪1
'
);
// this.room = await this.client.createRoom(matchRoomConfig, playerConfig);
this
.
room
=
await
this
.
client
.
matchPlayer
(
matchPlayerConfig
,
playerConfig
);
console
.
log
(
'
汪汪汪2
'
+
JSON
.
stringify
(
this
.
room
));
this
.
player
=
this
.
room
.
player
;
this
.
player
=
this
.
room
.
player
;
console
.
log
(
'
汪汪汪:
'
+
this
.
room
.
players
.
length
);
await
this
.
startFrameSync
();
console
.
log
(
'
汪汪汪2
'
);
this
.
room
.
onJoin
(
this
.
onJoinRoom
.
bind
(
this
));
this
.
room
.
onJoin
(
this
.
onJoinRoom
.
bind
(
this
));
this
.
room
.
onLeave
(
this
.
onLeaveRoom
.
bind
(
this
));
this
.
room
.
onLeave
(
this
.
onLeaveRoom
.
bind
(
this
));
this
.
room
.
onStartFrameSync
(
this
.
onStartFrameSync
.
bind
(
this
));
//
this.room.onStartFrameSync(this.onStartFrameSync.bind(this));
this
.
room
.
onStopFrameSync
(
this
.
onStopFrameSync
.
bind
(
this
));
this
.
room
.
onStopFrameSync
(
this
.
onStopFrameSync
.
bind
(
this
));
this
.
room
.
onRecvFrame
(
this
.
onRecvFrame
.
bind
(
this
));
this
.
room
.
onRecvFrame
(
this
.
onRecvFrame
.
bind
(
this
));
this
.
room
.
onDisconnect
(
this
.
onDisconnect
.
bind
(
this
));
this
.
room
.
onDisconnect
(
this
.
onDisconnect
.
bind
(
this
));
this
.
room
.
onDismiss
(
this
.
onDisconnect
.
bind
(
this
));
this
.
room
.
onDismiss
(
this
.
onDisconnect
.
bind
(
this
));
console
.
log
(
'
汪汪汪3
'
+
this
.
player
.
playerId
);
return
this
.
player
.
playerId
;
return
this
.
player
.
playerId
;
}
}
...
@@ -92,30 +74,32 @@ export class NetworkHelper {
...
@@ -92,30 +74,32 @@ export class NetworkHelper {
}
}
}
}
closeRoom
()
{
async
closeRoom
()
{
return
;
await
this
.
client
.
cancelMatch
();
}
async
startFrameSync
()
{
await
this
.
room
.
startFrameSync
();
// return new Promise((resolve, reject) => {
// return new Promise((resolve, reject) => {
// this.room.changeRoom({ isForbidJoin: true }, (event) => {
// this.room.onStartFrameSync(() => {
// console.log("关门");
// cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
// // console.log(JSON.stringify(event))
// resolve(null);
// resolve(null);
// });
// });
// });
// });
}
}
async
startFrameSync
()
{
await
this
.
room
.
startFrameSync
();
cc
.
log
(
"
开始帧同步成功,请到控制台查看具体帧同步信息
"
);
}
async
stopFrameSync
()
{
async
stopFrameSync
()
{
await
this
.
room
.
stopFrameSync
();
await
this
.
room
.
stopFrameSync
();
console
.
log
(
"
停止帧同步成功
"
);
console
.
log
(
"
停止帧同步成功
"
);
}
}
sendFrame
(
data
:
any
)
{
sendFrame
(
data
:
any
)
{
console
.
log
(
'
sendFrame:
'
+
JSON
.
stringify
(
data
));
console
.
warn
(
'
sendFrame:
'
+
JSON
.
stringify
(
data
));
this
.
room
.
sendFrame
(
JSON
.
stringify
(
data
));
if
(
this
.
room
.
_isSyncing
)
{
this
.
room
.
sendFrame
(
JSON
.
stringify
(
data
));
}
else
{
console
.
log
(
'
is syncing = false
'
);
this
.
onRecvFrame
({
data
});
}
}
}
onJoinRoom
(
event
)
{
onJoinRoom
(
event
)
{
...
@@ -123,6 +107,9 @@ export class NetworkHelper {
...
@@ -123,6 +107,9 @@ export class NetworkHelper {
this
.
_eventListeners
[
"
playerJoin
"
](
event
);
this
.
_eventListeners
[
"
playerJoin
"
](
event
);
}
}
console
.
log
(
"
新玩家加入
"
,
JSON
.
stringify
(
event
));
console
.
log
(
"
新玩家加入
"
,
JSON
.
stringify
(
event
));
this
.
room
.
players
.
forEach
(
player
=>
{
console
.
log
(
'
player.playerId =
'
,
player
.
playerId
);
});
}
}
onLeaveRoom
(
event
)
{
onLeaveRoom
(
event
)
{
console
.
log
(
"
onLeaveRoom
"
);
console
.
log
(
"
onLeaveRoom
"
);
...
@@ -146,6 +133,7 @@ export class NetworkHelper {
...
@@ -146,6 +133,7 @@ export class NetworkHelper {
}
}
}
}
onStartFrameSync
(
event
)
{
onStartFrameSync
(
event
)
{
console
.
log
(
'
onStartFrameSync
'
);
if
(
this
.
_eventListeners
[
"
gameStart
"
])
{
if
(
this
.
_eventListeners
[
"
gameStart
"
])
{
this
.
_eventListeners
[
"
gameStart
"
](
event
);
this
.
_eventListeners
[
"
gameStart
"
](
event
);
}
}
...
...
assets/op_16/script/Server.ts
View file @
860b4b42
...
@@ -37,11 +37,12 @@ export class GameServer {
...
@@ -37,11 +37,12 @@ export class GameServer {
this
.
headUrls
=
this
.
headUrls
.
sort
((
a
,
b
)
=>
RandomInt
(
2
)
-
1
);
this
.
headUrls
=
this
.
headUrls
.
sort
((
a
,
b
)
=>
RandomInt
(
2
)
-
1
);
this
.
nameList
=
this
.
nameList
.
sort
((
a
,
b
)
=>
RandomInt
(
2
)
-
1
);
this
.
nameList
=
this
.
nameList
.
sort
((
a
,
b
)
=>
RandomInt
(
2
)
-
1
);
this
.
networkHelper
.
startFrameSync
();
}
}
async
addPlayer
(
player
)
{
async
addPlayer
(
player
)
{
if
(
this
.
playerList
.
find
(
p
=>
p
.
uuid
==
player
.
uuid
))
{
return
;
}
console
.
log
(
"
addPlayer
"
);
console
.
log
(
"
addPlayer
"
);
this
.
playerList
.
push
({
this
.
playerList
.
push
({
name
:
this
.
nameList
.
splice
(
0
,
1
)[
0
],
name
:
this
.
nameList
.
splice
(
0
,
1
)[
0
],
...
@@ -206,7 +207,7 @@ export class GameServer {
...
@@ -206,7 +207,7 @@ export class GameServer {
startAI
()
{
startAI
()
{
this
.
playerList
this
.
playerList
.
filter
((
player
)
=>
player
.
isAI
==
true
)
.
filter
((
player
)
=>
player
.
isAI
==
true
)
.
forEach
((
player
)
=>
{});
.
forEach
((
player
)
=>
{
});
}
}
_timeoutIds
=
null
;
_timeoutIds
=
null
;
...
...
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