2.9.32 • Published 8 months ago

@ancademy/vse-server v2.9.32

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
8 months ago

About

@ancademy/bespoke-xxx is a set of kit for multiplayer web game development based on NodeJS and TypeScript. It allows you to focus on your scene rendering and gameplay instead of bothering about networking or database.

Features

  • Multiplayer: Game state is kept synchronized in realtime
  • TypeSafe: Declare player actions and states with strict generics
  • Logs: Game logs with the ability to time travel
  • Non-intrusive: Use React, PixiJS or anything other for view-layer rendering
  • Availability: Resume the game state after restarting
  • Extendable: Build regular http service with express

Prepare

This project runs on NodeJS v10 and uses Mongodb and Redis as the persistence layer, so we need to install them first.

Tutorial

This tutorial walks through the demo Tic-Tac-Toe, we use React as the renderer in this demo.

Init

Init project according to the guide of bespoke-cli

Concepts

  • namespace : The game will be mounted at the route : /namespace
  • ICreateParams : We can configure some parameters when creating a game, but in this demo it could be ignored.
  • State: The state of the world is divided into two parts, GameState is visible to everyone, while each player has his own PlayerState, they are passed around everywhere and maintained on both client and server seamlessly.
  • Move : MoveType and IMoveParams declare what actions will the players make and what parameters would be sent to the server.
  • Push : PushType and IPushParams declare what messages would be sent to players, which is independent of the state, and they won't be persisted.

Define State

Players are divided into groups of 2, we record number of players and who is the turn in IGameGroupState, the piece player held in IPlayerState

export enum Piece {
    null,
    x,
    o,
}

export enum GameStatus {
    matching,
    play,
    result,
}

export interface IGameGroupState {
    playerNum: number
    status: GameStatus
    pieces: Array<Piece>
    pieceTurn: Piece
}

export interface IGameState {
    groups: Array<IGameGroupState>
}

export interface IPlayerState {
    groupIndex: number
    piece: Piece
}

Define Move

export enum MoveType {
    getGroup,
    move
}
export interface IMoveParams {
    index: number // piece index
}

Client

In Play.tsx, as a player we can read gameState and playerState, and emit moves by frameEmitter, what you're doing next is to render your chessboard with React.

Server

In Logic.ts, we can init gameState and playerState, and then handle the player moves, just modify the state objects, they would be sync to client automatically.

Demo

You can find the complete code here

2.9.32

8 months ago

2.9.31

9 months ago

2.9.30

9 months ago

2.9.29

11 months ago

2.9.28

11 months ago

2.9.27

11 months ago

2.9.26

1 year ago

2.9.25

1 year ago

2.9.23

2 years ago

2.9.24

2 years ago

2.9.22

2 years ago

2.9.19

2 years ago

2.9.20

2 years ago

2.9.21

2 years ago

2.9.17

2 years ago

2.9.9

2 years ago

2.9.12

2 years ago

2.9.13

2 years ago

2.9.10

2 years ago

2.9.11

2 years ago

2.9.16

2 years ago

2.9.14

2 years ago

2.9.15

2 years ago

2.8.4-patch1

2 years ago

2.9.2

2 years ago

2.9.1

2 years ago

2.9.4

2 years ago

2.9.3

2 years ago

2.9.6

2 years ago

2.9.5

2 years ago

2.9.8

2 years ago

2.9.7

2 years ago

2.8.4-patch1.1

2 years ago

2.9.0

2 years ago

2.8.1

3 years ago

2.8.0

3 years ago

2.8.2

3 years ago

2.8.5

3 years ago

2.8.4

3 years ago

2.8.7

2 years ago

2.8.6

2 years ago

2.8.9

2 years ago

2.8.8

2 years ago

2.8.19

2 years ago

2.8.18

2 years ago

2.8.17

2 years ago

2.8.12

2 years ago

2.8.11

2 years ago

2.8.10

2 years ago

2.8.16

2 years ago

2.8.15

2 years ago

2.8.14

2 years ago

2.8.13

2 years ago

2.8.20

2 years ago

2.7.60

3 years ago

2.7.59

3 years ago

2.7.58

3 years ago

2.7.49

3 years ago

2.7.48

3 years ago

2.7.47

3 years ago

2.7.46

3 years ago

2.7.45

3 years ago

2.7.51

3 years ago

2.7.50

3 years ago

2.7.55

3 years ago

2.7.54

3 years ago

2.7.53

3 years ago

2.7.52

3 years ago

2.7.57

3 years ago

2.7.56

3 years ago

2.7.38

3 years ago

2.7.40

3 years ago

2.7.44

3 years ago

2.7.43

3 years ago

2.7.42

3 years ago

2.7.41

3 years ago

2.7.29

3 years ago

2.7.28

3 years ago

2.7.27

3 years ago

2.7.26

3 years ago

2.7.33

3 years ago

2.7.32

3 years ago

2.7.31

3 years ago

2.7.30

3 years ago

2.7.36

3 years ago

2.7.35

3 years ago

2.7.25

3 years ago

2.7.24

3 years ago

2.7.19

3 years ago

2.7.18

3 years ago

2.7.17

3 years ago

2.7.16

3 years ago

2.7.15

3 years ago

2.7.14

3 years ago

2.7.13

3 years ago

2.7.12

3 years ago

2.7.11

3 years ago

2.7.9

3 years ago

2.7.10

3 years ago

2.7.8

3 years ago

2.7.8-alpha.1

3 years ago

2.7.8-alpha.2

3 years ago

2.7.8-alpha.0

3 years ago

2.7.7

3 years ago

2.7.6

3 years ago

2.7.5

3 years ago

2.7.0

3 years ago

2.7.2

3 years ago

2.7.1

3 years ago

2.7.4

3 years ago

2.7.3

3 years ago

2.6.7

4 years ago

2.6.8

4 years ago

2.6.4

4 years ago

2.6.3

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.6.2

4 years ago

2.5.14

4 years ago

2.5.15

4 years ago

2.5.16

4 years ago

2.5.17

4 years ago

2.5.10

4 years ago

2.5.11

4 years ago

2.5.12

4 years ago

2.5.13

4 years ago

2.5.9

4 years ago

2.5.6

4 years ago

2.5.7

4 years ago

2.5.4

4 years ago

2.5.5

4 years ago

2.5.2

4 years ago

2.5.1

4 years ago

2.5.0

4 years ago