commit 263def7734ce19f24df9469a82c7362a6c394ef3
parent a18fd4bbabfd2c9d47c300afd9abf1b6f1a83cb3
Author: brookjeynes <me@brookjeynes.dev>
Date: Thu, 30 Jul 2026 14:41:06 +1000
feat: add draft difficulty implementation
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/enemy.zig b/src/enemy.zig
@@ -4,20 +4,19 @@ const raymath = @import("raymath");
const bullet = @import("./bullet.zig");
const max_spawned_bullets = 2000;
-const bullet_speed: f16 = 100.0;
-const bullet_spawn_cooldown: f16 = 2.0;
pub const bullet_damage: f16 = 50.0;
pub const Enemy = @This();
movement_speed: f16 = 40.0,
+bullet_speed: f16 = 100.0,
size: raylib.Vector2 = .{ .x = 40, .y = 40 },
direction: raylib.Vector2 = .{},
position: raylib.Vector2 = .{},
bullet_pool: bullet.Pool(max_spawned_bullets) = .{
.fire_timer = .{
- .duration = bullet_spawn_cooldown,
+ .duration = 2.0,
},
},
@@ -45,8 +44,8 @@ pub fn shoot(self: *Enemy) void {
.y = self.position.y + (self.size.y / 2),
},
.{
- .x = self.direction.x * bullet_speed,
- .y = self.direction.y * bullet_speed,
+ .x = self.direction.x * self.bullet_speed,
+ .y = self.direction.y * self.bullet_speed,
},
raylib.RED,
);
diff --git a/src/main.zig b/src/main.zig
@@ -36,6 +36,7 @@ pub fn main() !void {
var enemy_spawn_time: Timer = .{ .duration = 0.7 };
var enemies: [255]Enemy = undefined;
var enemy_count: u8 = 0;
+ var game_time: f32 = 0;
const button_size: raylib.Vector2 = .{ .x = 100, .y = 70 };
const button_position: raylib.Vector2 = .{
@@ -75,6 +76,10 @@ pub fn main() !void {
if (raylib.CheckCollisionPointRec(mouse_point, button_bounds)) {
if (raylib.IsMouseButtonReleased(raylib.MOUSE_BUTTON_LEFT)) {
current_screen = .gameplay;
+ game_time = 0;
+ enemy_count = 0;
+ enemy_spawn_time = .{ .duration = 0.7 };
+ player.health = Player.max_health;
}
}
},
@@ -82,6 +87,11 @@ pub fn main() !void {
.gameplay => {
const delta = raylib.GetFrameTime();
+ game_time += delta;
+
+ const difficulty: f32 = @min(5.0, 1.0 + game_time * 0.02);
+ enemy_spawn_time.duration = @max(0.15, 0.7 / difficulty);
+
player.tick();
player.handleMovement();
@@ -89,13 +99,14 @@ pub fn main() !void {
enemies[i].handleMovement(player.position);
}
- if (enemy_spawn_time.tick(delta)) {
+ if (enemy_spawn_time.tick(delta) and enemy_count < enemies.len) {
enemies[enemy_count] = spawnEnemy(
.{
.x = screen_width,
.y = screen_height,
},
player,
+ difficulty,
);
enemy_count += 1;
}
@@ -183,7 +194,7 @@ pub fn main() !void {
}
}
-fn spawnEnemy(screen: raylib.Vector2, player: Player) Enemy {
+fn spawnEnemy(screen: raylib.Vector2, player: Player, difficulty: f32) Enemy {
const min_dist: f32 = 200.0;
const player_cx = player.position.x + player.size.x / 2;
const player_cy = player.position.y + player.size.y / 2;
@@ -209,5 +220,10 @@ fn spawnEnemy(screen: raylib.Vector2, player: Player) Enemy {
}
}
+ const diff_f16: f16 = @floatCast(difficulty);
+ enemy.movement_speed = @min(@as(f16, 160), @as(f16, 40) * diff_f16);
+ enemy.bullet_speed = @min(@as(f16, 300), @as(f16, 100) * diff_f16);
+ enemy.bullet_pool.fire_timer.duration = @max(0.3, 2.0 / difficulty);
+
return enemy;
}