From 59dfb4a25705254d0d1aad0aceae69d5db0f6037 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sat, 26 Jul 2025 17:27:31 +0300 Subject: Added cpu image --- assets/img/cpu.png | Bin 439 -> 1260 bytes src/main.zig | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/assets/img/cpu.png b/assets/img/cpu.png index 2ca4095..e160e00 100644 Binary files a/assets/img/cpu.png and b/assets/img/cpu.png differ diff --git a/src/main.zig b/src/main.zig index 75f3782..996d081 100644 --- a/src/main.zig +++ b/src/main.zig @@ -158,11 +158,12 @@ const Bug = struct { }; } - fn damage(self: *Bug, dmg: f32) void { + fn damage(self: *Bug, dmg: f32) bool { self.health -= dmg; if (self.health <= 0) { self.dead = true; } + return self.dead; } fn memory(self: Bug) f32 { @@ -228,11 +229,17 @@ const Cpu = struct { fn cores(self: Cpu) u32 { return switch (self.debugs) { - 0...9 => 1, - 10...24 => 2, - 25...49 => 3, - 50...100 => 4, + // TODO: only for debug (change this once ready for play testing) + 0...2 => 1, + 3...4 => 2, + 5...6 => 3, + 7...8 => 4, else => 5, + // 0...9 => 1, + // 10...24 => 2, + // 25...49 => 3, + // 50...100 => 4, + // else => 5, }; } }; @@ -410,6 +417,13 @@ const Wave = struct { self.arena.deinit(); } + fn at(self: *Wave, x: usize, y: usize) ?*Cell { + if (x >= cells_width or y >= cells_height or x < 0 or y < 0) { + return null; + } + return &self.map[y][x]; + } + fn get(self: *Wave, x: usize, y: usize) Cell { if (x >= cells_width or y >= cells_height or x < 0 or y < 0) { return .none; @@ -712,6 +726,7 @@ const ScreenBattle = struct { if (self.wave.get(mx, my) == .socket and self.transistors >= cpu_transistor_cost) { self.wave.set(mx, my, .{ .cpu = .{} }); + // self.transistors -= cpu_transistor_cost; // TODO: uncomment when playtesting } } else if (rl.isMouseButtonPressed(rl.MouseButton.right) and edit) { self.wave.set(mx, my, .none); @@ -732,9 +747,11 @@ const ScreenBattle = struct { for (0..map.len) |y| { for (0..map[0].len) |x| { - const cell = self.wave.get(x, y); - switch (cell) { - .cpu => |cpu| { + const cell = self.wave.at(x, y).?; + switch (cell.*) { + .cpu => { + var cpu = &cell.cpu; + const cpu_center = rl.Vector2.init( @as(f32, @floatFromInt(x)) * cell_size + cell_size / 2, @as(f32, @floatFromInt(y)) * cell_size + cell_size / 2, @@ -755,7 +772,9 @@ const ScreenBattle = struct { continue; } - bug.damage(cpu.damage() * dt); + if (bug.damage(cpu.damage() * dt)) { + cpu.debugs += 1; + } count += 1; } }, -- cgit v1.3.1