补充注释
This commit is contained in:
parent
f5e35ccd4a
commit
786d414843
@ -4,7 +4,7 @@ import { WsConnection, WsServer } from "tsrpc";
|
||||
import { Room } from './models/Room';
|
||||
import { serviceProto, ServiceType } from './shared/protocols/serviceProto';
|
||||
|
||||
// Create the Server
|
||||
// 创建 TSRPC WebSocket Server
|
||||
export const server = new WsServer(serviceProto, {
|
||||
port: 3000,
|
||||
json: true
|
||||
@ -22,15 +22,16 @@ server.flows.postDisconnectFlow.push(v => {
|
||||
|
||||
export const roomInstance = new Room(server);
|
||||
|
||||
// Initialize before server start
|
||||
// 初始化
|
||||
async function init() {
|
||||
// 挂载 API 接口
|
||||
await server.autoImplementApi(path.resolve(__dirname, 'api'));
|
||||
|
||||
// TODO
|
||||
// Prepare something... (e.g. connect the db)
|
||||
};
|
||||
|
||||
// Entry function
|
||||
// 启动入口点
|
||||
async function main() {
|
||||
await init();
|
||||
await server.start();
|
||||
|
@ -9,7 +9,7 @@ import { ServiceType } from "../shared/protocols/serviceProto";
|
||||
*/
|
||||
export class Room {
|
||||
|
||||
// 次数/秒
|
||||
// 帧同步频率,次数/秒
|
||||
syncRate = gameConfig.syncRate;
|
||||
nextPlayerId = 1;
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { gameConfig } from "./gameConfig";
|
||||
import { ArrowState } from "./state/ArrowState";
|
||||
import { PlayerState } from "./state/PlayerState";
|
||||
|
||||
// 状态定义
|
||||
export interface GameSystemState {
|
||||
// 当前的时间(游戏时间)
|
||||
now: number,
|
||||
@ -123,11 +124,12 @@ export interface PlayerLeave {
|
||||
type: 'PlayerLeave',
|
||||
playerId: number
|
||||
}
|
||||
// 时间流逝
|
||||
export interface TimePast {
|
||||
type: 'TimePast',
|
||||
dt: number
|
||||
}
|
||||
|
||||
// 输入定义
|
||||
export type GameSystemInput = PlayerMove
|
||||
| PlayerAttack
|
||||
| PlayerJoin
|
||||
|
@ -3,8 +3,12 @@ export const gameConfig = {
|
||||
|
||||
moveSpeed: 10,
|
||||
|
||||
// 箭矢飞行时间(毫秒)
|
||||
arrowFlyTime: 500,
|
||||
// 箭矢投掷距离
|
||||
arrowDistance: 8,
|
||||
// 箭矢落地命中判定半径
|
||||
arrowAttackRadius: 2,
|
||||
// 被箭矢几种后的晕眩时间(毫秒)
|
||||
arrowDizzyTime: 1000
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
import { GameSystemState } from "../game/GameSystem";
|
||||
|
||||
/** 加入房间 */
|
||||
export interface ReqJoin {
|
||||
|
||||
}
|
||||
|
||||
export interface ResJoin {
|
||||
/** 加入房间后,自己的 ID */
|
||||
playerId: number,
|
||||
/** 状态同步:一次性同步当前状态 */
|
||||
gameState: GameSystemState
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { PlayerAttack, PlayerMove } from "../../game/GameSystem";
|
||||
|
||||
/** 发送自己的输入 */
|
||||
export interface MsgClientInput {
|
||||
sn: number,
|
||||
inputs: ClientInput[]
|
||||
|
@ -1,6 +1,11 @@
|
||||
import { GameSystemInput } from "../../game/GameSystem";
|
||||
|
||||
/**
|
||||
* 服务端定期广播的同步帧
|
||||
* 包含了这一段期间所有输入
|
||||
*/
|
||||
export interface MsgFrame {
|
||||
inputs: GameSystemInput[],
|
||||
/** 当前用户提交的,经服务端确认的最后一条输入的 SN */
|
||||
lastSn?: number
|
||||
}
|
Loading…
Reference in New Issue
Block a user