Init, drawing walls semi-works
This commit is contained in:
parent
befe4a84c9
commit
09cc69d38d
8 changed files with 287 additions and 0 deletions
40
kubo_wall.c
Normal file
40
kubo_wall.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "kubo_wall.h"
|
||||
|
||||
struct kubo_wall *kubo_wall_init() {
|
||||
struct kubo_wall *wall = malloc(sizeof(struct kubo_wall));
|
||||
|
||||
if (!wall)
|
||||
return NULL;
|
||||
|
||||
wall->num_vertices_alloc = KUBO_WALL_INIT_VERTICES;
|
||||
wall->vertices = malloc(sizeof(Vector2) * wall->num_vertices_alloc);
|
||||
|
||||
return wall;
|
||||
}
|
||||
|
||||
void kubo_wall_cleanup(struct kubo_wall *wall) {
|
||||
free(wall->vertices);
|
||||
free(wall);
|
||||
}
|
||||
|
||||
bool kubo_wall_append(struct kubo_wall *wall, Vector2 vertex) {
|
||||
|
||||
Vector2 *new_vertices;
|
||||
|
||||
if (wall->num_vertices == wall->num_vertices_alloc - 1) {
|
||||
|
||||
wall->num_vertices_alloc *= 2;
|
||||
|
||||
new_vertices =
|
||||
realloc(wall->vertices, sizeof(Vector2) * wall->num_vertices_alloc);
|
||||
|
||||
if (!new_vertices)
|
||||
return false;
|
||||
|
||||
wall->vertices = new_vertices;
|
||||
}
|
||||
|
||||
wall->vertices[wall->num_vertices++] = vertex;
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue