Setting up groundwork for vehicle (car) and pathfinding implementation

This commit is contained in:
2026-04-26 16:53:46 +02:00
parent ae5e68e2a5
commit 533b6b1c00
8 changed files with 131 additions and 24 deletions

View File

@@ -9,7 +9,16 @@ import "common"
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
rl.ClearBackground(rl.LIGHTGRAY)
// draw roads
draw_roads(self)
draw_nodes(self)
draw_cars(self)
draw_temp_road(self, pos)
draw_ui(self)
}
@(private="file")
draw_roads :: proc(self: ^Simulator) {
for &road, index in self.roads {
start := road.nodes[0]
end := road.nodes[1]
@@ -21,24 +30,44 @@ draw :: proc(self: ^Simulator, pos: rl.Vector2) {
rl.DrawLineEx(self.nodes[start].pos, self.nodes[end].pos, common.ROAD_SIZE, road_colour)
}
// draw nodes
}
@(private="file")
draw_nodes :: proc(self: ^Simulator) {
for &node in self.nodes {
// draws the snapping radius if key is held down
if self.show_details do rl.DrawCircleV(node.pos, common.NODE_SNAP_RADIUS * common.NODE_RADIUS, common.NODE_SNAP_COLOUR)
// draws the node
rl.DrawCircleV(node.pos, common.NODE_RADIUS, common.NODE_DONE_COLOUR)
}
// draw temp road if exists
if val, ok := self.temp_node.?; ok {
rl.DrawLineEx(self.nodes[val].pos, pos, common.ROAD_SIZE, common.ROAD_COLOUR)
}
@(private="file")
draw_cars :: proc(self: ^Simulator) {
for &car in self.cars {
pos := self.nodes[car.origin].pos
rl.DrawCircleV(self.nodes[val].pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_CURSOR_COLOUR)
rect := rl.Rectangle {
x = pos.x,
y = pos.y,
width = common.CAR_WIDTH,
height = common.CAR_HEIGHT
}
rl.DrawRectangleRec(rect, common.CAR_COLOUR)
}
}
@(private="file")
draw_temp_road :: proc(self: ^Simulator, pos: rl.Vector2) {
// draw temp road if exists
val, ok := self.temp_node.?
if !ok do return
draw_ui(self)
rl.DrawLineEx(self.nodes[val].pos, pos, common.ROAD_SIZE, common.ROAD_COLOUR)
rl.DrawCircleV(self.nodes[val].pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_CURSOR_COLOUR)
}
// Drawing UI text, mostly for debugging purposes