From aeb8de234883eb8a4736f847523526b45de364bc Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sat, 26 Jul 2025 10:58:25 +0300 Subject: a --- src/main.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 9291ec1..1b465f5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,6 +60,10 @@ const Bug = struct { position: rl.Vector2, previous: rl.Vector2, // Center of prev target: rl.Vector2, // Center of next cell + animation_time: f32 = 0, + animation_state: f32 = 0, + const animation_switch_threshold = 0.3; // seconds + // TODO: bugs need to know their "previous" square, so they know their next pub fn init(kind: BugKind, position: rl.Vector2) Bug { @@ -460,13 +464,23 @@ const ScreenBattle = struct { } } + const half_cell = cell_size / 2; + if (self.wave.bugs.items.len == 0) { + self.wave.bugs.append(Bug.init(.stack_overflow, rl.Vector2.init(half_cell, 4 * cell_size + half_cell))) catch unreachable; + } + for (self.wave.bugs.items) |bug| { const texture = switch (bug.kind) { .nullptr_deref => game.texture_map.get(.bug_null).?, .stack_overflow => game.texture_map.get(.bug_stackoverflow).?, .infinite_loop => game.texture_map.get(.bug_while).?, }; - rl.drawTexture(texture, @intCast(bug.position.x), @intCast(bug.position.y), rl.Color.white); + rl.drawTextureRec( + texture, + .{ .x = bug.animation_state * cell_size, .y = 0, .width = cell_size, .height = cell_size }, + .{ .x = bug.position.x - half_cell, .y = bug.position.y - half_cell }, + rl.Color.white, + ); } } @@ -492,8 +506,9 @@ const ScreenBattle = struct { \\FPS: {} \\Screen: {}x{} \\World: {}x{} ({}) + \\Bugs: {} , - .{ rl.getFPS(), screenWidth, screenHeight, world_width, world_height, cell_size }, + .{ rl.getFPS(), screenWidth, screenHeight, world_width, world_height, cell_size, self.wave.bugs.items.len }, ) catch return; rl.drawText(debug_info, 20, 20, font_size, .black); -- cgit v1.3.1