:video_game: (WIP - phase 3) Multiplayer online game using Phaser + WebSocket (Socket.IO)
Multiplayer online game using Phaser + WebSocket (Socket.IO).
1. Mouse
- Left: move
- Right: fire
2. Keyboard
- Up: move
- Left / Right: rotate
- Spacebar: fire
npm install -g nodemon yarn bower pm2
yarn && bower install
Build client side
- dev: `yarn build.watch`
- prod: `yarn build`
Start server side
- dev: `nodemon app.js --watch app.js`
- prod: `pm2 start app.js`
1. Code guideline & Naming we use
1.1 Base javascript style: [Airbnb](https://github.com/airbnb/javascript)
1.2 Function should return only one type
e.g.
- getName: string, '' (default)
- getRandomInt: number, 0 (default)
- getPlayers: Array, [] (default)
- getPlayer: Object, {} (default)
except getIndex
e.g.
- getIndexOfPlayer: number, -1 (default)
2. Naming
- Function / scope variable: `camelCase`
- Global variable: `UPPERCASE`
- Class: `PascalCase`
3. Creature
- Monster
- Zombie
- Machine
- Bat
- Hero
- Player / Enemy
4. Socket
- Send to specific client: IO.sockets.connected[socketId].emit(EVENT_NAME, data);
- Send to all clients: IO.emit(EVENT_NAME, data);
- Send to all clients except newly created connection: socket.broadcast.emit(EVENT_NAME, data);
5. Event flow
Anything's related with `life` directly, is need to broadcast first then
take effect from subsequent request. (currently, there are only 2 events
(move / fire) that can execute on client before broadcasting)
6. CommonJs
const
and let
againeslint-disable-line
checkAlive
event: the player is already gone, but it's still in the game (cause from network issue)