Drawing wall splines
This commit is contained in:
parent
09cc69d38d
commit
b217a72e6d
4 changed files with 27 additions and 29 deletions
|
|
@ -40,11 +40,15 @@ bool kubo_context_add_wall(struct kubo_context *context,
|
|||
|
||||
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
||||
|
||||
if (context->num_walls > 0 &&
|
||||
(context->walls[context->num_walls - 1]->wall_state == KUBO_WALL_INIT ||
|
||||
context->walls[context->num_walls - 1]->wall_state ==
|
||||
KUBO_WALL_STARTED)) {
|
||||
return context->walls[context->num_walls - 1];
|
||||
if (context->num_walls > 0) {
|
||||
switch (context->walls[context->num_walls - 1]->state) {
|
||||
case KUBO_WALL_INIT:
|
||||
case KUBO_WALL_DRAWING:
|
||||
return context->walls[context->num_walls - 1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct kubo_wall *wall = kubo_wall_init();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ struct kubo_wall *kubo_wall_init() {
|
|||
|
||||
wall->num_vertices_alloc = KUBO_WALL_INIT_VERTICES;
|
||||
wall->vertices = malloc(sizeof(Vector2) * wall->num_vertices_alloc);
|
||||
wall->num_vertices = 0;
|
||||
wall->state = KUBO_WALL_INIT;
|
||||
|
||||
return wall;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
enum kubo_wall_state {
|
||||
KUBO_WALL_INIT,
|
||||
KUBO_WALL_STARTED,
|
||||
KUBO_WALL_DRAWING,
|
||||
KUBO_WALL_DONE
|
||||
};
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ struct kubo_wall {
|
|||
unsigned int num_vertices;
|
||||
unsigned int num_vertices_alloc;
|
||||
|
||||
enum kubo_wall_state wall_state;
|
||||
enum kubo_wall_state state;
|
||||
};
|
||||
|
||||
struct kubo_wall *kubo_wall_init();
|
||||
|
|
|
|||
|
|
@ -34,13 +34,15 @@ void kubo_window_render(struct kubo_context *context) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < context->num_walls; i++) {
|
||||
if (context->walls[i]->wall_state == KUBO_WALL_STARTED) {
|
||||
DrawSplineLinear(context->walls[i]->vertices,
|
||||
context->walls[i]->num_vertices, 10.f, BLACK);
|
||||
if (context->walls[i]->state == KUBO_WALL_STARTED) {
|
||||
Vector2 mouse_pos = GetMousePosition();
|
||||
Vector2 points[] = {context->walls[i]->vertices[0], mouse_pos};
|
||||
Vector2 points[] = {
|
||||
context->walls[i]
|
||||
->vertices[context->walls[i]->num_vertices - 1],
|
||||
mouse_pos};
|
||||
DrawSplineLinear(points, 2, 10.f, BLACK);
|
||||
} else if (context->walls[i]->wall_state == KUBO_WALL_DONE) {
|
||||
DrawSplineLinear(context->walls[i]->vertices,
|
||||
context->walls[i]->num_vertices, 10.f, BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,26 +51,16 @@ void kubo_window_render(struct kubo_context *context) {
|
|||
|
||||
void kubo_window_input(struct kubo_context *context) {
|
||||
if (IsKeyPressed(KEY_Q)) {
|
||||
printf("q\n");
|
||||
context->exit_pending = true;
|
||||
}
|
||||
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (current_wall->wall_state == KUBO_WALL_INIT) {
|
||||
printf("new wall\n");
|
||||
Vector2 start_pos = GetMousePosition();
|
||||
kubo_wall_append(current_wall, start_pos);
|
||||
current_wall->wall_state = KUBO_WALL_STARTED;
|
||||
} else if (current_wall->wall_state == KUBO_WALL_STARTED) {
|
||||
printf("started wall\n");
|
||||
Vector2 end_pos = GetMousePosition();
|
||||
kubo_wall_append(current_wall, end_pos);
|
||||
current_wall->wall_state = KUBO_WALL_DONE;
|
||||
} else {
|
||||
printf("neither?\n");
|
||||
}
|
||||
Vector2 new_pos = GetMousePosition();
|
||||
kubo_wall_append(current_wall, new_pos);
|
||||
current_wall->state = KUBO_WALL_STARTED;
|
||||
} else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||
current_wall->state = KUBO_WALL_DONE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue