readme.md

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
1zig build --release=fast

This will create a .zig-cache directory and a asteroids executable inside of the zig-out/bin directory.

Running

To run the game you can run:

sh
1./zig-out/bin/asteroids

Controls

  • W or Up - Move forward
  • A or Left - Rotate left
  • D or Right - Rotate right
  • Space - Fire

Configuration File

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

zig
1var WINDOW_SIZE = rl.Vector2.init(640 * 1.2, 480 * 1.2);
2var THICKNESS: f32 = 2.0;
3var SCALE: f32 = 25.0;
4var ROT_SPEED: f32 = 0.8; // rotations per second
5var ROT_DRAG: f32 = 0.09;
6var DRAG: f32 = 0.03;
7var SPEED: f32 = 0.25;
8var DEBUG: bool = false;
9var SHIP_COLLISION_SIZE: f32 = 0.4;
10var SPAWN_RADIUS: f32 = 3.0;
11var MAX_ASTEROIDS: u32 = 15;

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

env
1DEBUG=false
2SHIP_COLLISION_SIZE=0.4
3SPAWN_RADIUS=3.0
4MAX_ASTEROIDS=15
5WINDOW_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.

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
1zig build run # compiles and launches without optimizations
sh
1zig 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.