Multiplayer racing game powered by PubNub.
Playing a game alone is not nearly as fun as playing with your friends and that's one reason why massively multiplayer online games (MMOs) are a huge revenue stream that continues to grow rapidly every year. In June 2018 consumers spent an estimated $9.1 billion digitally across all platforms [on MMOs], compared to $7.9 billion last June.
The design of online games can range from simple text-based environments to incredibly complex virtual worlds. A few other examples of popular online multiplayer games types include first-person shooters (FPS), real-time strategy games (RTS), and multiplayer online battle arena games (MOBA).
This project is intended to show how PubNub can be used to create a real-time multiplayer game. PubNub is perfect for powering multiplayer games because it makes it easier to build a fast and scalable multiplayer game. In this game PubNub is used to manage the players in the game lobby and to transmit game data. The game is built in Go using the PubNub Go SDK and is cross platform. You can learn more about how this game was built from the blog post.
The fastest way to get started is to download and run the appropriate binary for your OS. You don't need to install Go or any dependencies to run the game. See the 'How To Play' section below to get racing.
- Want to learn more about this project or build a clone from scratch? Check out the blog post.
-
You’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys from the PubNub Developer Portal.
-
You must enable the channel presence feature for your keys. Presence can be enabled per key in your account dashboard.
-
Install the latest version of Go and setup your $GOPATH.
-
Download the dependencies.
go get github.com/pubnub/go
go get github.com/gosuri/uiprogress
go get github.com/nsf/termbox-go
- Clone the Repo.
git clone https://github.com/chandler767/Space-Race
-
Get your unique PubNub keys from the PubNub Developer Portal. If you don't have a PubNub account, you can sign up for a PubNub account for free.
-
Enable the channel presence feature for your keys. Presence can be enabled per key in your account dashboard.
-
Open main.go and replace "pub-key" and "sub-key" with your keys.
-
Build and run the game.
make run
OR
make build
./space-race
-
The first player to enter a lobby becomes the host. The second player to enter becomes the guest.
-
Both players need to enter the same lobby name.
-
When both players have joined a lobby the game will start after a 3 second delay (get your fingers ready).
-
After the game starts, alternate pressing SPACE and the RIGHT ARROW KEY to advance your progress bar.
-
The first player to 100% wins the game.
-
You can leave the game while playing by pressing ESC. If you leave the game then the other player wins automatically.
-
If the terminal window is too small, or if the font is too big, the progress bars won't render correctly. Make the window bigger and then press command+k to refresh.
-
The lobby is kept simple by design so it can be used as a seed project. The lobby may not always be able to start a game in some edge cases. If you have problems starting a game try restarting the game for both players and use a new lobby name.
Have suggestions or questions about this project? Reach out at devrel@pubnub.com.