补充注释

This commit is contained in:
King Wang 2021-12-06 23:51:54 +08:00
parent f5e35ccd4a
commit 786d414843
7 changed files with 21 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import { WsConnection, WsServer } from "tsrpc";
import { Room } from './models/Room'; import { Room } from './models/Room';
import { serviceProto, ServiceType } from './shared/protocols/serviceProto'; import { serviceProto, ServiceType } from './shared/protocols/serviceProto';
// Create the Server // 创建 TSRPC WebSocket Server
export const server = new WsServer(serviceProto, { export const server = new WsServer(serviceProto, {
port: 3000, port: 3000,
json: true json: true
@ -22,15 +22,16 @@ server.flows.postDisconnectFlow.push(v => {
export const roomInstance = new Room(server); export const roomInstance = new Room(server);
// Initialize before server start // 初始化
async function init() { async function init() {
// 挂载 API 接口
await server.autoImplementApi(path.resolve(__dirname, 'api')); await server.autoImplementApi(path.resolve(__dirname, 'api'));
// TODO // TODO
// Prepare something... (e.g. connect the db) // Prepare something... (e.g. connect the db)
}; };
// Entry function // 启动入口点
async function main() { async function main() {
await init(); await init();
await server.start(); await server.start();

View File

@ -9,7 +9,7 @@ import { ServiceType } from "../shared/protocols/serviceProto";
*/ */
export class Room { export class Room {
// 次数/秒 // 帧同步频率,次数/秒
syncRate = gameConfig.syncRate; syncRate = gameConfig.syncRate;
nextPlayerId = 1; nextPlayerId = 1;

View File

@ -2,6 +2,7 @@ import { gameConfig } from "./gameConfig";
import { ArrowState } from "./state/ArrowState"; import { ArrowState } from "./state/ArrowState";
import { PlayerState } from "./state/PlayerState"; import { PlayerState } from "./state/PlayerState";
// 状态定义
export interface GameSystemState { export interface GameSystemState {
// 当前的时间(游戏时间) // 当前的时间(游戏时间)
now: number, now: number,
@ -123,11 +124,12 @@ export interface PlayerLeave {
type: 'PlayerLeave', type: 'PlayerLeave',
playerId: number playerId: number
} }
// 时间流逝
export interface TimePast { export interface TimePast {
type: 'TimePast', type: 'TimePast',
dt: number dt: number
} }
// 输入定义
export type GameSystemInput = PlayerMove export type GameSystemInput = PlayerMove
| PlayerAttack | PlayerAttack
| PlayerJoin | PlayerJoin

View File

@ -3,8 +3,12 @@ export const gameConfig = {
moveSpeed: 10, moveSpeed: 10,
// 箭矢飞行时间(毫秒)
arrowFlyTime: 500, arrowFlyTime: 500,
// 箭矢投掷距离
arrowDistance: 8, arrowDistance: 8,
// 箭矢落地命中判定半径
arrowAttackRadius: 2, arrowAttackRadius: 2,
// 被箭矢几种后的晕眩时间(毫秒)
arrowDizzyTime: 1000 arrowDizzyTime: 1000
} }

View File

@ -1,11 +1,14 @@
import { GameSystemState } from "../game/GameSystem"; import { GameSystemState } from "../game/GameSystem";
/** 加入房间 */
export interface ReqJoin { export interface ReqJoin {
} }
export interface ResJoin { export interface ResJoin {
/** 加入房间后,自己的 ID */
playerId: number, playerId: number,
/** 状态同步:一次性同步当前状态 */
gameState: GameSystemState gameState: GameSystemState
} }

View File

@ -1,5 +1,6 @@
import { PlayerAttack, PlayerMove } from "../../game/GameSystem"; import { PlayerAttack, PlayerMove } from "../../game/GameSystem";
/** 发送自己的输入 */
export interface MsgClientInput { export interface MsgClientInput {
sn: number, sn: number,
inputs: ClientInput[] inputs: ClientInput[]

View File

@ -1,6 +1,11 @@
import { GameSystemInput } from "../../game/GameSystem"; import { GameSystemInput } from "../../game/GameSystem";
/**
* 广
*
*/
export interface MsgFrame { export interface MsgFrame {
inputs: GameSystemInput[], inputs: GameSystemInput[],
/** 当前用户提交的,经服务端确认的最后一条输入的 SN */
lastSn?: number lastSn?: number
} }