Commit 860b4b42 authored by 范雪寒's avatar 范雪寒

feat: 单机可以玩了

parent f62de039
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,6 +2,6 @@
"type": "software",
"scope": "game",
"name": "GameOBESDK",
"version": "1.1.4.301",
"version": "1.1.5.300",
"playbook": ""
}
\ No newline at end of file
......@@ -64,7 +64,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("房主");
this.isRoomOwner = true;
this.server = new GameServer(2, this.networkHelper);
await this.networkHelper.startFrameSync();
this.server.addPlayer({
uuid: this.playerId,
isAI: false,
......@@ -647,8 +646,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
dataList.push(frameData);
}
dataList.forEach(async (item) => {
if (!item.data) {
return;
}
console.log(item);
return;
if (this.server) {
this.server.onFrameEvent(item.data);
......
......@@ -33,7 +33,6 @@ export class NetworkHelper {
appId: '105879509',// 应用的ID
openId: 'op_16' + Math.random(),// 玩家ID
});
console.log(this.client);
await this.client.init();
}
......@@ -41,41 +40,24 @@ export class NetworkHelper {
async joinRoom(roomType: string, maxPlayers: number) {
const matchRoomConfig = {
matchParams: {
matchRule: '',
matchRule2: '',
param1: 'param1',
},
roomType: roomType,
customRoomProperties: '',
maxPlayers: maxPlayers,
};
// 在线匹配参数
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.room = await this.client.matchRoom(matchRoomConfig);
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.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.onRecvFrame(this.onRecvFrame.bind(this));
this.room.onDisconnect(this.onDisconnect.bind(this));
this.room.onDismiss(this.onDisconnect.bind(this));
console.log('汪汪汪3' + this.player.playerId);
return this.player.playerId;
}
......@@ -92,30 +74,32 @@ export class NetworkHelper {
}
}
closeRoom() {
return;
async closeRoom() {
await this.client.cancelMatch();
}
async startFrameSync() {
await this.room.startFrameSync();
// return new Promise((resolve, reject) => {
// this.room.changeRoom({ isForbidJoin: true }, (event) => {
// console.log("关门");
// // console.log(JSON.stringify(event))
// this.room.onStartFrameSync(() => {
// cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
// resolve(null);
// });
// });
}
async startFrameSync() {
await this.room.startFrameSync();
cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
}
async stopFrameSync() {
await this.room.stopFrameSync();
console.log("停止帧同步成功");
}
sendFrame(data: any) {
console.log('sendFrame: ' + JSON.stringify(data));
this.room.sendFrame(JSON.stringify(data));
console.warn('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) {
......@@ -123,6 +107,9 @@ export class NetworkHelper {
this._eventListeners["playerJoin"](event);
}
console.log("新玩家加入", JSON.stringify(event));
this.room.players.forEach(player => {
console.log('player.playerId = ', player.playerId);
});
}
onLeaveRoom(event) {
console.log("onLeaveRoom");
......@@ -146,6 +133,7 @@ export class NetworkHelper {
}
}
onStartFrameSync(event) {
console.log('onStartFrameSync');
if (this._eventListeners["gameStart"]) {
this._eventListeners["gameStart"](event);
}
......
......@@ -37,11 +37,12 @@ export class GameServer {
this.headUrls = this.headUrls.sort((a, b) => RandomInt(2) - 1);
this.nameList = this.nameList.sort((a, b) => RandomInt(2) - 1);
this.networkHelper.startFrameSync();
}
async addPlayer(player) {
if (this.playerList.find(p => p.uuid == player.uuid)) {
return;
}
console.log("addPlayer");
this.playerList.push({
name: this.nameList.splice(0, 1)[0],
......@@ -206,7 +207,7 @@ export class GameServer {
startAI() {
this.playerList
.filter((player) => player.isAI == true)
.forEach((player) => {});
.forEach((player) => { });
}
_timeoutIds = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment