diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-07-26 17:27:31 +0300 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-07-26 17:27:31 +0300 |
| commit | 59dfb4a25705254d0d1aad0aceae69d5db0f6037 (patch) | |
| tree | aacbf1e2c0375271bf8fa6ed8e297efab5ef891d | |
| parent | 156f5e956b660d9a9d6194d5e12919494aaa20ab (diff) | |
Added cpu image
| -rw-r--r-- | assets/img/cpu.png | bin | 439 -> 1260 bytes | |||
| -rw-r--r-- | src/main.zig | 37 |
2 files changed, 28 insertions, 9 deletions
diff --git a/assets/img/cpu.png b/assets/img/cpu.png Binary files differindex 2ca4095..e160e00 100644 --- a/assets/img/cpu.png +++ b/assets/img/cpu.png 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; } }, |
