Update main.zig
This commit is contained in:
parent
5b316ed1ba
commit
4e5915acee
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/.zig-cache
|
/.zig-cache
|
||||||
/zig-out
|
/zig-out
|
||||||
/.idea
|
|
@ -45,7 +45,7 @@ pub const Areas = struct {
|
|||||||
self.allocator.free(self.areas);
|
self.allocator.free(self.areas);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: *Areas) void {
|
pub fn draw(self: *const Areas) void {
|
||||||
for (self.areas) |area| {
|
for (self.areas) |area| {
|
||||||
area.draw();
|
area.draw();
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,20 @@ const rl = @import("raylib");
|
|||||||
|
|
||||||
var screen_width: i32 = 1920;
|
var screen_width: i32 = 1920;
|
||||||
var screen_height: i32 = 1080;
|
var screen_height: i32 = 1080;
|
||||||
const scale: i32 = 5;
|
const scale: f32 = 5.0;
|
||||||
|
|
||||||
pub fn getScale() i32 {
|
pub fn getScale() f32 {
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getScreenWidthF32() f32 {
|
||||||
|
return @floatFromInt(screen_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getScreenHeightF32() f32 {
|
||||||
|
return @floatFromInt(screen_height);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getScreenWidth() i32 {
|
pub fn getScreenWidth() i32 {
|
||||||
return screen_width;
|
return screen_width;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ pub fn main() !void {
|
|||||||
const new_width = rl.getScreenWidth();
|
const new_width = rl.getScreenWidth();
|
||||||
const new_height = rl.getScreenHeight();
|
const new_height = rl.getScreenHeight();
|
||||||
|
|
||||||
|
// todo fix spawn area locations when resizing
|
||||||
if (globals.checkWindowSizeChanged(new_width, new_height)) {
|
if (globals.checkWindowSizeChanged(new_width, new_height)) {
|
||||||
globals.setWindowSize(new_width, new_height);
|
globals.setWindowSize(new_width, new_height);
|
||||||
}
|
}
|
||||||
@ -36,5 +37,6 @@ pub fn main() !void {
|
|||||||
rl.clearBackground(.light_gray);
|
rl.clearBackground(.light_gray);
|
||||||
|
|
||||||
// draw areas
|
// draw areas
|
||||||
|
spAreas.draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ pub const SpawnArea = struct {
|
|||||||
fn setLocation(self: *SpawnArea) void {
|
fn setLocation(self: *SpawnArea) void {
|
||||||
self.location = switch (self.area) {
|
self.location = switch (self.area) {
|
||||||
.top_left => rl.Vector2{ .x = 0, .y = 0 },
|
.top_left => rl.Vector2{ .x = 0, .y = 0 },
|
||||||
.top_right => rl.Vector2{ .x = globals.getScreenWidth() - self.width * globals.getScale(), .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.getScreenHeight() - self.height * globals.getScale() },
|
.bottom_left => rl.Vector2{ .x = 0, .y = globals.getScreenHeightF32() - @as(f32, @floatFromInt(self.height)) * globals.getScale() },
|
||||||
.bottom_right => rl.Vector2{ .x = globals.getScreenWidth() - self.width * globals.getScale(), .y = globals.getScreenHeight() - 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{
|
const rect = rl.Rectangle{
|
||||||
.x = self.location.x,
|
.x = self.location.x,
|
||||||
.y = self.location.y,
|
.y = self.location.y,
|
||||||
.width = self.width * globals.getScale(),
|
.width = @as(f32, @floatFromInt(self.width)) * globals.getScale(),
|
||||||
.height = self.height * globals.getScale(),
|
.height = @as(f32, @floatFromInt(self.height)) * globals.getScale(),
|
||||||
};
|
};
|
||||||
rl.drawRectangleRec(rect, .dark_gray);
|
rl.drawRectangleRec(rect, .dark_gray);
|
||||||
// todo draw cars
|
// todo draw cars
|
||||||
|
Loading…
x
Reference in New Issue
Block a user