Giter Club home page Giter Club logo

gowog's Introduction

GOWOG, Open source GOlang Web-based Online Game

GOWOG is a multiplayer web game written in Golang. Thanks to Golang, the server can handle a large number of players concurrently.

screenshot

Try the game

Southeast Asia region (Vietnam, Singapore, Malaysia ...)

http://game.giongto35.com

Due to the cost of hosting. The server is hosted only on SEA.

AI Experiment on the Agent

As the server, client and messages are decoupled, it is easy to communicate with backend. Below is my AI agent written in Python that learns to interact with environment. This experiment is to find a path in a maze using neuroevolution

https://www.youtube.com/watch?v=pWbb1m91mhU

The implementation is at gowog/ai

Local

You can try the game on local by running ./run_local.sh. It will build a docker environment and run the game on port 8080.

Open the browser "localhost:8080"

Development

screenshot

The game contains two part: Server and Client. Server uses Golang and Client uses Node.JS and Phaser game engine.

Server

Install Golang https://golang.org/doc/install

Install dependencies

  • go get github.com/gorilla/websocket
  • go get github.com/golang/protobuf/protoc-gen-go
  • go get github.com/pkg/profile

Run the server. The server will listen at port 8080.

Go to gowog folder

  • go run server/cmd/server/*

Client

Install NodeJS https://nodejs.org/en/download/

Go to gowog/client folder

Install dependencies

  • npm install

Run the client. The client will listen at port 3000. env.HOST_IP is the IP of gowog server which is localhost:8080 now.

  • npm run dev -- --env.HOST_IP=localhost:8080

Open the browser "localhost:3000"

Note:

In development we run client on port 3000 and server on port 8080 separately.

In production and docker environment, the client is built and golang server will return client page on the same port 8080. Therefore, if we run docker environment, the game will start at "localhost:8080" in browser.

Communication convention

Communication packages between server and client is based on protobuf. Install protoc for protobuf generate.

Everytime you change package singature in /sertver/message.proto. Run

  • go to gowog/server

  • /generate.sh

Document

Frontend

Backend

AI

FAQ

Why we need Golang for multiplayer game?

Building a massively multiplayer game is very difficult and it's currently overlooked. You have to ensure the latency is acceptable, handle shared states concurrently and allow it to scale vertically. Golang provides a very elegant concept to handle concurrency with goroutine and channel.

Why the gameplay is so simple and frontend codebase is so unorganized?

The gameplay is mainly for demonstration purpose. My goal is to keep the game simple as current and scale number of players vertically while maintaining good latency (< 100ms). I welcome all of your ideas to make the game more scalable.

However, I'm still open to Graphic improvement and client codebase refactor. I would love to see some particles burst or glow, motion effects. Remember that different people have different perspective on how the game should look, so we need full consensus before making ui change.

Why protobuf?

To optimize package size, we need to compress it into binary. Protobuf offers fast language-neutral serialization and deserilization, so Golang server can communicate with JS client in an optimal way.

We can consider faster serilization format like Cap'n Proto or FlatBuffers.

Why the multiplayer game is not room-based (less than 20 players per game)

In my opinion, room-based is less challenging because each room is totally separated from each other and we can scale the game easier by adding more instances. This repo is to illustrate how many players the game can serve on one multi-core single machine.

And of course my ultimate goal is to make the non room-based game scale vertically by adding more instances.

Contribution guidelines

I'm looking forward to have your contribution to GOWOG, which can help the game smoother and more scalable. If you have any ideas to improve game performance, please discuss in this issue Discussion.

I also welcome frontend improvement like codebase reorganization, performance enhancement. In the case you want to improve the UI, please create an issue to show the new design so we can make an agreement on that.

As my desire is to utilize Golang concurrency paradigm to achieve smooth gaming experience with massive number of players, I will keep the gameplay simple. Player can move around and shoot each other. Any gameplay changes are not accepted.

Credits

https://github.com/gorilla/websocke/blob/master/examples/chat

https://github.com/RenaudROHLINGER/phaser-es6-webpack

https://github.com/huytd/agar.io-clone (My inspiration)

LICENSE

MIT License

Contributor

Nguyen Huu Thanh
https://www.linkedin.com/in/huuthanhnguyen/

gowog's People

Contributors

giongto35 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gowog's Issues

Improve shoot collection detection on server

As server has higher latency. We cannot check if the current position of bullet hit player at every tick.
We should check if the line from old position -> new position cut the player.

[Eng] Build Docker dev environment

Currently, Docker environment is similar to prod environment (Client HTML is built and server returns Client)

As for Dev environment, we don't build client HTML. Run NPM in development mode in container (npm run dev)

[Frontend] Support mobile web

We need to support mobile web by adding 2 controller on left and right. Left is joystick for movement, Right is joystick for shoot direction (Follow PubG)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.