|
1 | | -This is a basic example cart in Nelua for the [null0](https://notnull.games/null0) game-engine. |
| 1 | +# mygame |
2 | 2 |
|
3 | | -## usage |
| 3 | +A starter [null0](https://notnull.games/null0) cart, in Nelua. |
4 | 4 |
|
5 | | -Carts run natively, and on the web. This repo will auto-publish to github-pages on push, so users can check out your cart without installing anything. |
| 5 | +Press **Use this template** to make your own, then search the project for `mygame` and rename it to whatever your game is called. |
6 | 6 |
|
7 | | -They can also install [the native runtime](https://github.com/notnullgames/null0/releases) and use it to run your cart. |
| 7 | +## building |
8 | 8 |
|
9 | | -## github |
| 9 | +Everything is built inside docker, so you never install nelua + wasi-sdk clang yourself. All you need is [docker](https://docs.docker.com/get-started/get-docker/), plus [node](https://nodejs.org/) for the shortcuts below. |
10 | 10 |
|
11 | | -There are 2 actions: |
12 | | - |
13 | | -- Publish demo to github-pages - this happens on any push |
14 | | -- Attach current version of your cart to any releases that are created (like [here](https://github.com/notnullgames/cart_nelua/releases/)) |
15 | | - |
16 | | -## developing |
17 | | - |
18 | | -Make sure you have [wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases) installed and `WASI_SDK_PATH` set to it's location (eg `/opt/wasi-sdk`.) |
| 11 | +```sh |
| 12 | +npm start |
| 13 | +``` |
19 | 14 |
|
20 | | -Then you can do this: |
| 15 | +That builds `webroot/mygame.null0`, serves `webroot/`, and rebuilds whenever you edit something in `cart/`. To build once, without the server: |
21 | 16 |
|
22 | 17 | ```sh |
23 | | -nelua --cflags="-I ." -L . "src/main.nelua" -r --cc "$WASI_SDK_PATH/bin/clang" -o src/main.wasm |
24 | | -cd src |
25 | | -zip -r ../webroot/mygame.null0 . -x '*.nelua' '.DS_Store' |
| 18 | +npm run build |
26 | 19 | ``` |
27 | 20 |
|
28 | | -You can also use cmake (recommended) to build a complete cart: |
| 21 | +Or call docker yourself: |
29 | 22 |
|
30 | 23 | ```sh |
31 | | -cmake -B build -DCMAKE_TOOLCHAIN_FILE="${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake" -DCMAKE_BUILD_TYPE=Release |
32 | | -cmake --build build |
| 24 | +rm -f webroot/mygame.null0 |
| 25 | +docker run --rm --user $(id -u):$(id -g) -v ./cart:/src -v ./webroot:/out ghcr.io/notnullgames/null0-cart-nelua:latest mygame |
33 | 26 | ``` |
34 | 27 |
|
35 | | -You will find your cart in `webroot/mygame.null0` |
| 28 | +## writing your game |
36 | 29 |
|
37 | | -If you have node installed, you can also get a nice watching-webseerver, locally: |
| 30 | +Your code is in `cart/main.nelua`. A cart implements the callbacks it cares about and the host skips the rest: |
38 | 31 |
|
| 32 | +```lua |
| 33 | +local function load() <cexport'load'> end |
39 | 34 | ``` |
40 | | -npm start |
41 | | -``` |
42 | 35 |
|
43 | | -After this, create a github-release, and your cart will show up on releases (like [here](https://github.com/notnullgames/cart_nelua/releases/)). |
| 36 | +### Nelua notes |
| 37 | + |
| 38 | +- `require 'null0'`. Nelua compiles to C, so it needs null0.h alongside null0.nelua. |
| 39 | + |
| 40 | +You do not need to copy any null0 bindings into this project - the docker image bakes the current [`carts/nelua/null0.nelua`](https://raw.githubusercontent.com/notnullgames/null0/main/carts/nelua/null0.nelua) in for you. |
| 41 | + |
| 42 | +## docs |
| 43 | + |
| 44 | +- [Nelua carts](https://notnull.games/null0/languages/nelua) - the whole API, in Nelua |
| 45 | +- [Anatomy of a cart](https://notnull.games/null0/cart) - callbacks, input, distribution |
| 46 | +- [API reference](https://notnull.games/null0/api) |
| 47 | + |
| 48 | +## publishing |
| 49 | + |
| 50 | +Two workflows come with this template: |
| 51 | + |
| 52 | +- **Publish** builds the cart and deploys `webroot/` to github-pages on every push to `main`, so anyone can play your game in a browser without installing anything. |
| 53 | +- **Release** attaches `mygame.null0` to any github release you create. |
44 | 54 |
|
| 55 | +Players who want it natively can grab [the runtime](https://github.com/notnullgames/null0/releases) and run `null0 mygame.null0`. |
0 commit comments