Skip to content

Boilerplate interface between the airconsole JS api and Ebiten Go game engine

Notifications You must be signed in to change notification settings

jacovanc/airconsole-ebiten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AirConsole + Ebiten Boilerplate

Overview

This boilerplate project provides a basic setup for developing games that integrate AirConsole for input handling and Ebiten for game logic. It demonstrates how to set up a web-based controller interface and a Go-based game engine that communicates with it.

Structure

The project is divided into two main parts:

  • web/ */: This directory contains the web frontend. It includes the HTML (controller.html, screen.html), JavaScript (script.js), and CSS (style.css) files necessary for both the controller interface and the html that will render the WASM
  • game/ */: This houses the Go codebase for the game. The Go code is compiled to WebAssembly, enabling it to run in the browser and interact with the web-based controller.

Hosting

This project can be hosted in various ways, but below are instructions for using PHP as a local server for development and testing.

General Hosting Guidelines

  • WebAssembly Compilation: Compile the Go code in the game/ directory into WebAssembly and place the compiled file in the web/build directory.
  • Static File Server: Any static file server can be used to serve the files in the web/ directory. This can range from a simple server in Python or Node.js to more robust servers like Apache or Nginx.

Hosting with PHP

For local development, PHP's built-in server is a convenient option. Follow these steps to use PHP:

  • Check PHP Installation: Ensure PHP is installed on your machine. Verify this by running php -v in your command line.
  • Start PHP Server: In the command line, navigate to the web/ directory and start the server:
php -S 0.0.0.0:8000
  • Access The Project: With the server running, you can access the game and controller interfaces at: Game interface: http://localhost:8000/screen.html Controller interface: http://localhost:8000/controller.html. Depending on how you are hosting, you may want to setup a redirect at the route of the web folder to the screen.html

  • The PHP server will serve your static files, and any changes will be reflected upon refreshing the browser.

Playing the game

Building the Go game web assembly

In order to actually play our Go game, we need to compile it to web assembly so that it is served up from our web directly. To compile it, we follow the instructions from [https://ebitengine.org/en/documents/webassembly.html](Option 2) Instructions for Windows below, it should be pretty clear from the above link how to do it on linux.

Windows (powershell)

This defines the build destination in the web/build directory. Be sure to put the same URL as defined in your go.mod. Execute this from within the game folder.

$Env:GOOS = 'js'
$Env:GOARCH = 'wasm'
go build -o ../web/build/game.wasm github.com/jacovanc/airconsole-ebiten/game
Remove-Item Env:GOOS
Remove-Item Env:GOARCH

We then need to create an executable that can be executed from our html

$goroot = go env GOROOT
cp $goroot\misc\wasm\wasm_exec.js ../web/build/wasm_exec.js

About

Boilerplate interface between the airconsole JS api and Ebiten Go game engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published