diff --git a/src/area/spawn-area.zig b/src/area/spawn-area.zig index 84094de..77002b6 100644 --- a/src/area/spawn-area.zig +++ b/src/area/spawn-area.zig @@ -48,5 +48,71 @@ pub const SpawnArea = struct { .height = @as(f32, @floatFromInt(self.height)) * globals.getScale(), }; rl.drawRectangleRec(rect, .dark_gray); + + // red line for hover + if (self.checkHover()) { + var start_pos: rl.Vector2 = undefined; + var end_pos: rl.Vector2 = undefined; + + // this should be precalculated shouldn't need do calculate this each time just for the sake of drawing it + switch (self.area) { + .top_left => { + start_pos = rl.Vector2 { + .x = self.location.x + intToFloat(self.width) * globals.getScale(), + .y = self.location.y, + }; + + end_pos = rl.Vector2 { + .x = start_pos.x, + .y = self.location.y + intToFloat(self.height) * globals.getScale(), + }; + }, + .top_right => { + start_pos = self.location; + end_pos = rl.Vector2 { + .x = start_pos.x, + .y = self.location.y + intToFloat(self.height) * globals.getScale(), + }; + }, + .bottom_left => { + start_pos = rl.Vector2 { + .x = self.location.x + intToFloat(self.width) * globals.getScale(), + .y = self.location.y, + }; + + end_pos = rl.Vector2 { + .x = start_pos.x, + .y = self.location.y + intToFloat(self.height) * globals.getScale(), + }; + }, + .bottom_right => { + start_pos = self.location; + end_pos = rl.Vector2 { + .x = start_pos.x, + .y = self.location.y + intToFloat(self.height) * globals.getScale(), + }; + } + } + + rl.drawLineEx(start_pos, end_pos, 5, .red); + } + } + + fn checkHover(self: *const SpawnArea) bool { + const pos = rl.getMousePosition(); + var x_ok = false; + var y_ok = false; + + if (pos.x >= self.location.x and pos.x <= self.location.x + @as(f32, @floatFromInt(self.width)) * globals.getScale()) + x_ok = true; + + if (pos.y >= self.location.y and pos.y <= self.location.y + @as(f32, @floatFromInt(self.height)) * globals.getScale()) + y_ok = true; + + return x_ok and y_ok; + } + + fn intToFloat(num: i32) f32 { + return @floatFromInt(num); } }; diff --git a/src/main.zig b/src/main.zig index cc64276..b279107 100644 --- a/src/main.zig +++ b/src/main.zig @@ -21,7 +21,7 @@ pub fn main() !void { rl.maximizeWindow(); rl.setTargetFPS(60); - var area_manager = try areas.Areas.init(allocator, 3); + var area_manager = try areas.Areas.init(allocator, 4); defer area_manager.deinit(); var road_manager = roadman_str.RoadManager.init(allocator);