/* * Copyright Luka Jankovic 2025 * * This file is part of Kubo. * * Kubo is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * Kubo is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * Kubo. If not, see . */ #include "kubo_wall.h" void kubo_wall_init(struct kubo_wall *wall) { if (!wall) { return; } wall->state = KUBO_WALL_INIT; kubo_vector2_arr_init(&wall->vertices); } void kubo_wall_cleanup(struct kubo_wall *wall) { kubo_vector2_arr_free(&wall->vertices); free(wall); } bool kubo_wall_add_vertex(struct kubo_wall *wall, Vector2 vec) { return kubo_vector2_arr_add(&wall->vertices, vec); } Vector2 kubo_wall_get_vertex(struct kubo_wall *wall, size_t index) { return kubo_vector2_arr_get(&wall->vertices, index); } void kubo_wall_render(struct kubo_wall *wall, bool select, Camera2D *camera, Vector2 mouse) { (void)camera; Color wall_color = (select && wall->state == KUBO_WALL_SELECTED) ? BLUE : BLACK; Vector2 *points = malloc(sizeof(Vector2) * wall->vertices.count); for (size_t i = 0; i < wall->vertices.count; i++) { points[i] = kubo_vector2_arr_get(&wall->vertices, i); } DrawSplineLinear(points, wall->vertices.count, 10.f, wall_color); if (wall->state == KUBO_WALL_DRAWING) { // Vector2 mouse = GetScreenToWorld2D(mouse, *camera); Vector2 mouse_points[] = { points[wall->vertices.count - 1], mouse }; DrawSplineLinear(mouse_points, 2, 10.f, wall_color); } free(points); }