diff --git a/.gitignore b/.gitignore index 499ec12..e901168 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /.zig-cache /zig-out -/.idea \ No newline at end of file diff --git a/src/areas.zig b/src/areas.zig index adda826..5c7264b 100644 --- a/src/areas.zig +++ b/src/areas.zig @@ -45,7 +45,7 @@ pub const Areas = struct { self.allocator.free(self.areas); } - pub fn draw(self: *Areas) void { + pub fn draw(self: *const Areas) void { for (self.areas) |area| { area.draw(); } diff --git a/src/globals.zig b/src/globals.zig index 1c4ec03..a4b3520 100644 --- a/src/globals.zig +++ b/src/globals.zig @@ -2,12 +2,20 @@ const rl = @import("raylib"); var screen_width: i32 = 1920; var screen_height: i32 = 1080; -const scale: i32 = 5; +const scale: f32 = 5.0; -pub fn getScale() i32 { +pub fn getScale() f32 { return scale; } +pub fn getScreenWidthF32() f32 { + return @floatFromInt(screen_width); +} + +pub fn getScreenHeightF32() f32 { + return @floatFromInt(screen_height); +} + pub fn getScreenWidth() i32 { return screen_width; } diff --git a/src/main.zig b/src/main.zig index f7eb32c..07241fb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -29,6 +29,7 @@ pub fn main() !void { const new_width = rl.getScreenWidth(); const new_height = rl.getScreenHeight(); + // todo fix spawn area locations when resizing if (globals.checkWindowSizeChanged(new_width, new_height)) { globals.setWindowSize(new_width, new_height); } @@ -36,5 +37,6 @@ pub fn main() !void { rl.clearBackground(.light_gray); // draw areas + spAreas.draw(); } } diff --git a/src/spawn-area.zig b/src/spawn-area.zig index 1dde63a..e0fd1d8 100644 --- a/src/spawn-area.zig +++ b/src/spawn-area.zig @@ -27,18 +27,18 @@ pub const SpawnArea = struct { fn setLocation(self: *SpawnArea) void { self.location = switch (self.area) { .top_left => rl.Vector2{ .x = 0, .y = 0 }, - .top_right => rl.Vector2{ .x = globals.getScreenWidth() - self.width * globals.getScale(), .y = 0 }, - .bottom_left => rl.Vector2{ .x = 0, .y = globals.getScreenHeight() - self.height * globals.getScale() }, - .bottom_right => rl.Vector2{ .x = globals.getScreenWidth() - self.width * globals.getScale(), .y = globals.getScreenHeight() - self.height * globals.getScale() }, + .top_right => rl.Vector2{ .x = globals.getScreenWidthF32() - @as(f32, @floatFromInt(self.width)) * globals.getScale(), .y = 0 }, + .bottom_left => rl.Vector2{ .x = 0, .y = globals.getScreenHeightF32() - @as(f32, @floatFromInt(self.height)) * globals.getScale() }, + .bottom_right => rl.Vector2{ .x = globals.getScreenWidthF32() - @as(f32, @floatFromInt(self.width)) * globals.getScale(), .y = globals.getScreenHeightF32() - @as(f32, @floatFromInt(self.height)) * globals.getScale() }, }; } - pub fn draw(self: *SpawnArea) void { + pub fn draw(self: *const SpawnArea) void { const rect = rl.Rectangle{ .x = self.location.x, .y = self.location.y, - .width = self.width * globals.getScale(), - .height = self.height * globals.getScale(), + .width = @as(f32, @floatFromInt(self.width)) * globals.getScale(), + .height = @as(f32, @floatFromInt(self.height)) * globals.getScale(), }; rl.drawRectangleRec(rect, .dark_gray); // todo draw cars