/planetoid

Planetoid is a toy project to demonstrate and learn several technologies. The goal is to create a little multiplayer asteriod game clone.

Primary LanguageRustApache License 2.0Apache-2.0

Planetoid

Planetoid

Planetoid is a toy project to demonstrate and learn several technologies. The goal is to create a little multiplayer asteriod game clone.

  • Server-side is composed of 2 parts:
    • A server based on a Quarkus application. The goal of this application will be to:
      • Show games in progress and terminated with participants and winner.
      • Allow users to authenticate and add comments to a specific game.
      • Launch workers to allow several games in parallel, each with individual players.
    • A worker based on a Quarkus application using websockets derived from the chat example. The goal of this application is currently to:
      • Pass game messages between clients.
  • Client-side is a Rust application using macroquad framework. It was also derived from the asteroid example but refactored in a more object-oriented code. It can be compiled as:
    • A native application that will use websockets (tungstenite) to share game data. Only Linux has been fully tested so far, but it should run on Windows/MacOs as well.
    • A wasm32 application that can be run in a browser. Currently, websockets are not implemented, but the game can be played in solo mode.
  • Deployment on Kubernetes for the server and the required infrastructure to capture metrics (Prometheus / Grafana) as well as authentication (Keycloak) and persistance (Postgres).

This project is in an early stage, so many features are missing and need to be implemented. However, as stated initially, the goal is not to propose a real game but a demo to explain and share these technologies.

Targeted infra overview

infra

Project current status

  • Clients (native and wasm) can be built and run. Wasm can only run solo mode.
  • Worker allows playing a multiplayer game:
    • Native client can share the game with a spectator. A spectator is another native client started in the spectator mode.
    • Multiplayer game. A native client can be run as host, and several guests can connect to destroy asteroids together.
  • Server is a WIP. It is currently just exposing two tables with hibernate/panache and a couple of API routes.

Authors

Game controls

  • Right and left arrow keys to turn the ship right and left.
  • Space key to shoot.
  • F key to display fps.
  • Esc key to quit the game.

Demo

An online demo can be played here.

Note:

  • only solo mode is available online.
  • loading the game can take time.

Screenshots

Native application: App native screenshot

Running the wasm application into Firefox: App wasm32 screenshot

Multiplayer game: multiplayer game screenshot

Binaries

Binaries are available here: Binary releases

Run Locally (mainly for development purposes)

  1. Clone the project
  git clone https://github.com/uggla/planetoid
  1. Go to the project directory
  cd planetoid

Worker

  1. Install OpenJDK 11 following the instructions here or install it using your distribution package manager. Ex on Fedora
  dnf install java-11-openjdk-devel
  1. Install maven > 3.6 following the instructions here or install it using your distribution package manager. Ex on Fedora:
  dnf install maven
  1. Go to the worker directory and run the worker in dev mode
cd worker
mvn compile quarkus:dev

Note: Maven will download a lot of dependencies from the internet

Client

Native client

  1. Install Rust following the instructions here.

    Tips: the rustup method is the simplest one.

  2. Install required library for macroquad

  • Ubuntu system dependencies
apt install pkg-config libx11-dev libxi-dev libgl1-mesa-dev libasound2-dev
  • Fedora system dependencies
dnf install libX11-devel libXi-devel mesa-libGL-devel alsa-lib-devel
  • Windows system
No dependencies are required for Windows or MacOS
  1. Go to the client directory and run the native client
cd client
cargo run

Wasm32 client

  1. Follow the above instruction of the native client.

  2. Install basic-http-server

cargo install basic-http-server
  1. Add the wasm32 compilation target
rustup target add wasm32-unknown-unknown
  1. Go to the client directory and run the native client
cd client
cargo build --target wasm32-unknown-unknown
  1. Serve the files and open the browser
basic-http-server
xdg-open http://127.0.0.1:4000

Native client usage

Planetoid 0.1.0
Planetoid is an asteroid clone.

USAGE:
    planetoid [FLAGS] [OPTIONS]

FLAGS:
    -d, --debug      Debug mode (_ (error), -d (info), -dd (debug), -ddd (trace))
    -g, --god        God mode
        --help       Prints help information
    -s, --solo       Solo mode, do not connect to network
    -V, --version    Prints version information

OPTIONS:
    -h, --host <host>    Host [default: localhost]
    -m, --mode <mode>    Network mode [default: host]  [possible values: host, guest, spectator]
    -n, --name <name>    Player name [default: planetoid]
    -p, --port <port>    Port [default: 8080]

Examples

Running in solo mode

cargo run -- -s

Running in network mode with a spectator

On the first terminal: cargo run -- -m host -n Planetoid

On the second terminal: cargo run -- -m spectator -n "Planetoid spectator"

Running in network mode, debug and as god

-dd: debug, allows to see messages sent to the web socket.

-g: god mode, player ship cannot be destroyed.

-n: player name (default: planetoid)

cargo run -- -m host -dd -g -n Planetoid

Running in network mode with host and guest

On the first terminal: cargo run -- -m host -n Planetoid

On the second terminal: cargo run -- -m guest -n "Planetoid guest"