# readme.md · versecafe/asteroids

[View on GitCafe](https://git.cafe/versecafe/asteroids/blob/d9e27ce9a4c72e5c391c03b0699f6c0debdc66dd/readme.md)

Repository: [versecafe/asteroids](https://git.cafe/versecafe/asteroids)

Visibility: public

Requested revision: d9e27ce9a4c72e5c391c03b0699f6c0debdc66dd

Requested commit: d9e27ce9a4c72e5c391c03b0699f6c0debdc66dd

Commit: d9e27ce9a4c72e5c391c03b0699f6c0debdc66dd

Blob: d1df5dfe699887d737a61755e5df256a588edc9d

Size: 1753 bytes

[Immutable source](https://git.cafe/versecafe/asteroids/blob/d9e27ce9a4c72e5c391c03b0699f6c0debdc66dd/readme.md?format=markdown)

````
This is just a simple project for learning zig but it does provide a working
game of asteroids for any platform if anyone is bored and wants to give it a
try.

## Building

To build the game you need to have zig installed. You can get it from
https://ziglang.org/download/

Once you have zig installed you can build the game by running:

```sh
zig build --release=fast
```

This will create a `zig-cache` directory and a `asteroids` executable in the
current directory.

## Running

To run the game you can run:

```sh
./zig-out/bin/asteroids
```

## Controls

- W - Move forward
- A - Rotate left
- R - Rotate right
- Space - Fire

## Configuration File

The game can be configured by modifying the `config.txt` file, it can modify
the following fields:

```zig
var WINDOW_SIZE = rl.Vector2.init(640 * 1.2, 480 * 1.2);
var THICKNESS: f32 = 2.0;
var SCALE: f32 = 25.0;
var ROT_SPEED: f32 = 0.8; // rotations per second
var ROT_DRAG: f32 = 0.09;
var DRAG: f32 = 0.03;
var SPEED: f32 = 0.25;
var DEBUG: bool = false;
var SHIP_COLISION_SIZE: f32 = 0.4;
var SPAWN_RADIUS: f32 = 3.0;
var MAX_ASTEROIDS: u32 = 15;
```

declaring the variables works like so, note all fields are optional:

```env
DEBUG=false
SHIP_COLISION_SIZE=0.4
SPAWN_RADIUS=3.0
MAX_ASTEROIDS=15
WINDOW_SIZE=800,600
```

## Run Dev or Test

If you are actually working on this as a jumping off point to learn zig you can use the
following commands to run and test the game:

```sh
zig build run # compiles and launches without optimizations
```

```sh
zig build test # runs the base tests for init update and no mem leaks
```

Note that `config.txt` is still used when running the game in dev mode or runnint tests,
try setting `DEBUG=true` in `config.txt` to see the collision debug mode.

````
