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.
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:
| 1 | zig build --release=fast |
This will create a .zig-cache directory and a asteroids executable inside
of the zig-out/bin directory.
To run the game you can run:
| 1 | ./zig-out/bin/asteroids |
The game can be configured by modifying the config.txt file, it can modify
the following fields:
| 1 | var WINDOW_SIZE = rl.Vector2.init(640 * 1.2, 480 * 1.2); |
| 2 | var THICKNESS: f32 = 2.0; |
| 3 | var SCALE: f32 = 25.0; |
| 4 | var ROT_SPEED: f32 = 0.8; // rotations per second |
| 5 | var ROT_DRAG: f32 = 0.09; |
| 6 | var DRAG: f32 = 0.03; |
| 7 | var SPEED: f32 = 0.25; |
| 8 | var DEBUG: bool = false; |
| 9 | var SHIP_COLLISION_SIZE: f32 = 0.4; |
| 10 | var SPAWN_RADIUS: f32 = 3.0; |
| 11 | var MAX_ASTEROIDS: u32 = 15; |
declaring the variables works like so, note all fields are optional:
| 1 | DEBUG=false |
| 2 | SHIP_COLLISION_SIZE=0.4 |
| 3 | SPAWN_RADIUS=3.0 |
| 4 | MAX_ASTEROIDS=15 |
| 5 | WINDOW_SIZE=800,600 |
Note that if SEED is not set it will use the current timestamp as the seed providing a different game every time.
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:
| 1 | zig build run # compiles and launches without optimizations |
| 1 | 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 running tests, try setting DEBUG=true in config.txt to see the collision debug mode.