node implementation on spawn areas
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
const std = @import("std");
 | 
			
		||||
const rl = @import("raylib");
 | 
			
		||||
const str_node = @import("../road/node.zig");
 | 
			
		||||
const spawn_area = @import("spawn-area.zig");
 | 
			
		||||
const structures = @import("../structures.zig");
 | 
			
		||||
 | 
			
		||||
@@ -75,4 +76,15 @@ pub const Areas = struct {
 | 
			
		||||
 | 
			
		||||
        return valuesToRandomise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn getNodes(self: *Areas) ![]str_node.Node {
 | 
			
		||||
        var nodes = try self.allocator.alloc(str_node.Node, self.areas.len);
 | 
			
		||||
 | 
			
		||||
        for (0..self.areas.len) |i| {
 | 
			
		||||
            const node_location = self.areas[i].getNodeLocation();
 | 
			
		||||
            nodes[i] = str_node.Node.init(node_location);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return nodes;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,13 @@ pub const SpawnArea = struct {
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn getNodeLocation(self: *const SpawnArea) rl.Vector2 {
 | 
			
		||||
        return rl.Vector2{
 | 
			
		||||
            .x = self.location.x + @as(f32, @floatFromInt(self.width)) * globals.getScale() / 2.0,
 | 
			
		||||
            .y = self.location.y + @as(f32, @floatFromInt(self.height)) * globals.getScale() / 2.0,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn draw(self: *const SpawnArea) void {
 | 
			
		||||
        const rect = rl.Rectangle{
 | 
			
		||||
            .x = self.location.x,
 | 
			
		||||
@@ -42,6 +49,5 @@ pub const SpawnArea = struct {
 | 
			
		||||
            .height = @as(f32, @floatFromInt(self.height)) * globals.getScale(),
 | 
			
		||||
        };
 | 
			
		||||
        rl.drawRectangleRec(rect, .dark_gray);
 | 
			
		||||
        // todo draw cars
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ pub fn main() !void {
 | 
			
		||||
        rl.clearBackground(.light_gray);
 | 
			
		||||
 | 
			
		||||
        try road_manager.inputHandler();
 | 
			
		||||
        area_manager.draw();
 | 
			
		||||
        road_manager.draw();
 | 
			
		||||
        area_manager.draw();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
const std = @import("std");
 | 
			
		||||
const rl = @import("raylib");
 | 
			
		||||
const area_str = @import("../area/areas.zig");
 | 
			
		||||
const road_str = @import("road.zig");
 | 
			
		||||
const road_data = @import("road-data.zig");
 | 
			
		||||
const node_str = @import("node.zig");
 | 
			
		||||
@@ -226,4 +227,11 @@ pub const RoadManager = struct {
 | 
			
		||||
        self.setDefaultColour();
 | 
			
		||||
        self.selected_road = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn getAreaNodes(self: *RoadManager, areas: area_str.Areas) !void {
 | 
			
		||||
        const nodes = try areas.getNodes();
 | 
			
		||||
        defer self.allocator.free(nodes);
 | 
			
		||||
 | 
			
		||||
        try self.nodes.appendSlice(nodes);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user