refactoring, road implementation

This commit is contained in:
2025-07-21 12:32:21 +02:00
parent 4e5915acee
commit 3fc0687139
9 changed files with 194 additions and 20 deletions

47
src/area/spawn-area.zig Normal file
View File

@@ -0,0 +1,47 @@
const std = @import("std");
const rl = @import("raylib");
const structures = @import("../structures.zig");
const globals = @import("../globals.zig");
const car = @import("../car/car.zig");
pub const SpawnArea = struct {
area: structures.AreaLocation,
location: rl.Vector2,
width: i32,
height: i32,
pub fn init(area_loc: structures.AreaLocation) SpawnArea {
var new_spawn = SpawnArea{
.area = area_loc,
.location = undefined,
.width = 100,
.height = 50,
};
// need to do this outside the "constructor", as the function needs reference to self
new_spawn.setLocation();
return new_spawn;
}
// todo if window size changes this needs to be recalculated
pub fn setLocation(self: *SpawnArea) void {
self.location = switch (self.area) {
.top_left => rl.Vector2{ .x = 0, .y = 0 },
.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: *const SpawnArea) void {
const rect = rl.Rectangle{
.x = self.location.x,
.y = self.location.y,
.width = @as(f32, @floatFromInt(self.width)) * globals.getScale(),
.height = @as(f32, @floatFromInt(self.height)) * globals.getScale(),
};
rl.drawRectangleRec(rect, .dark_gray);
// todo draw cars
}
};