Skip to content

Commit

Permalink
Add WebAssembly support (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokiat committed Jun 19, 2022
1 parent 90114f4 commit 47ed9bf
Show file tree
Hide file tree
Showing 55 changed files with 1,188 additions and 669 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Go

on:
push:
tags: [ '*' ]

jobs:
compile:
name: Compile
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
include:
- os: windows-latest
ext: '.exe'
- os: ubuntu-latest
ext: ''
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2.1.3
with:
go-version: 1.18

- name: Install Linux Packages
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y libgl1-mesa-dev xorg-dev

- name: Compile
run: |
mkdir -p "./dist/${{ matrix.os }}"
go build -o "./dist/${{ matrix.os }}/rally-mka${{ matrix.ext }}" ./cmd/rallymka/
- name: Archive Distribution
uses: actions/upload-artifact@v3
with:
name: Distribution
path: ./dist
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

# Assets
/assets

# VSCode
.vscode/

# Distribution
/dist
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

102 changes: 77 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,99 @@
# Rally MKA [![Go Report Card](https://goreportcard.com/badge/github.com/mokiat/rally-mka)](https://goreportcard.com/report/github.com/mokiat/rally-mka) [![Go Reference](https://pkg.go.dev/badge/github.com/mokiat/rally-mka@master.svg)](https://pkg.go.dev/github.com/mokiat/rally-mka@master)

Rally MKA is a really old game of mine ported to Go for fun and as a way to try new concepts out.
Rally MKA is a really old game/demo of mine ported to Go for fun and as a way to experiment with new concepts.

![Game Screenshot](preview.png)
[![Game Screenshot](preview.png)](http://mokiat.com/rally-mka/)

## User's Guide

Check the [Releases](https://github.com/mokiat/rally-mka/releases) section for ready-to-use binaries.
### Browser

Use the following link to try the game in the browser:
http://mokiat.com/rally-mka/

The preferred browser is [Chrome](https://www.google.com/chrome/), which at the time of writing appears to best support WebGL2, WebAssembly and Game Controllers.

### Desktop

Check the [Releases](https://github.com/mokiat/rally-mka/releases) section for ready-to-use binaries that you can use on your computer.

The requirement is that your OS supports `OpenGL 4.6`.

### Controls

Use the following keyboard keys when playing:

- `Left Arrow` - Steer left
- `Right Arrow` - Steer right
- `Up Arrow` - Accelerate
- `Down Arrow` - Decelerate
- `a`, `s`, `d`, `w` - Rotate camera
- `q`, `e` - Zoom in/out camera
- `Enter` - Flip car

In addition, the game supports using a Game Controller.

## Developer's Guide

This section describes how to setup the project on your machine and compile it yourself.

### Prerequisites

* You need [Go 1.16](https://golang.org/dl/) or newer.
* You need the [Git LFS](https://git-lfs.github.com/) plugin. As the project contains large images and models, this is the official way on how not to clog a repository.
* Follow the instructions on the [GLFW for Go](https://github.com/go-gl/glfw) repository and make sure you can run the [GLFW examples](https://github.com/go-gl/example) on your platform.
- You need [Go 1.18](https://golang.org/dl/) or newer.
- You need the [Git LFS](https://git-lfs.github.com/) plugin. As the project contains large images and models, this is the official way on how not to clog a repository.
- Follow the instructions on the [GLFW for Go](https://github.com/go-gl/glfw) repository and make sure you can run the [GLFW examples](https://github.com/go-gl/example) on your platform.
- Make sure you have [Task](https://taskfile.dev/) installed, as this project uses Taskfiles.

### Setting Up

1. Clone the repository

```sh
git clone https://github.com/mokiat/rally-mka
cd rally-mka
```
```sh
git clone https://github.com/mokiat/rally-mka
cd rally-mka
```

1. Download Go dependencies

```sh
go mod download
```
```sh
go mod download
```

1. Generate game assets

```sh
make assets
```
```sh
task pack
```

#### Desktop

1. Run the game

```sh
make play
```
```sh
task run
```

#### Browser

1. Generate web content

```sh
task webpack
```

1. Build web assembly executable

```sh
task wasm
```

1. Run HTTP server

```sh
task web
```

1. Open http://localhost:8080

## Licensing

Expand All @@ -53,14 +103,16 @@ All source code in this project is licensed under [Apache License v2](LICENSE).

### Assets

Assets (images, models, textures, etc.), are distributed under the [Creative Commons Attribution 4.0 International](http://creativecommons.org/licenses/by/4.0/) license.
Assets (images, models, textures, etc.) are distributed under the [Creative Commons Attribution 4.0 International](http://creativecommons.org/licenses/by/4.0/) license.

## Special Thanks

The following projects and individuals have contributed significantly to the project:

* **[GLFW for Go](https://github.com/go-gl/glfw)** for making it possible to use GLFW and OpenGL in Go.
* **[LearnOpenGL](https://learnopengl.com/)** for the amazing tutorials.
* **[TextureHeaven](https://texturehaven.com/)** for the excellent free images.
* **[Erin Catto](https://github.com/erincatto)** for all the presentations and articles that were used as reference.
* **[Bo0mer](https://github.com/Bo0mer)** for the panoramic image that was used to generate the original `city` skybox images.
- **[The Go Team](https://go.dev/)** for making Go programming language.
- **[GLFW for Go](https://github.com/go-gl/glfw)** for making it possible to use GLFW and OpenGL in Go.
- **[LearnOpenGL](https://learnopengl.com/)** for the amazing tutorials.
- **[Poly Haven](https://polyhaven.com/)** for the excellent free images.
- **[Erin Catto](https://github.com/erincatto)** for all the presentations and articles that were used as reference for the physics engine.
- **[Bo0mer](https://github.com/Bo0mer)** for the panoramic image that was used to generate the original `city` skybox images.
- And everyone else whose repository has been used as a dependency.
38 changes: 38 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

tasks:

webpack:
cmds:
- mkdir -p 'assets/web'
- cp 'resources/icon.png' 'assets/web/favicon.png'
- cp 'resources/web/main.css' 'assets/web/main.css'
- cp 'resources/web/main.js' 'assets/web/main.js'
- cp 'resources/web/index.html' 'assets/index.html'
- cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" 'assets/web'

pack:
cmds:
- go run './cmd/rallypack'

assets:
deps: [webpack, pack]

run:
cmds:
- go run './cmd/rallymka'

debug:
cmds:
- go run -tags debug './cmd/rallymka'

wasm:
env:
GOOS: js
GOARCH: wasm
cmds:
- go build -o './assets/web/main.wasm' './cmd/rallywasm'

web:
cmds:
- go run 'github.com/mokiat/httpserv@master' -dir './assets' -host '127.0.0.1'
53 changes: 0 additions & 53 deletions cmd/rallymka/internal/application.go

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/rallymka/internal/global/context.go

This file was deleted.

39 changes: 0 additions & 39 deletions cmd/rallymka/internal/scene/data.go

This file was deleted.

42 changes: 0 additions & 42 deletions cmd/rallymka/internal/store/application.go

This file was deleted.

Loading

0 comments on commit 47ed9bf

Please sign in to comment.