}
}
-static
int boxes_add_box(Boxes *boxes, Rect rect, Color color)
{
trace_assert(boxes);
boxes_add_box(boxes, rect((float) x, (float) y, (float) w, (float) h), color);
return eval_success(NIL(gc));
- } else if (strcmp(action, "new-here") == 0) {
- struct Expr optional_args = void_expr();
- long int w, h;
- res = match_list(gc, "dd*", rest, &w, &h, &optional_args);
- if (res.is_error) {
- return res;
- }
+ }
- Color color = rgba(rand_float(1.0f), rand_float(1.0f), rand_float(1.0f), 1.0f);
- if (!nil_p(optional_args)) {
- const char *color_hex = NULL;
- res = match_list(gc, "s*", optional_args, &color_hex, NULL);
- color = hexstr(color_hex);
- }
+ return unknown_target(gc, "box", action);
+ }
- // TODO: it's impossible to get the position of the player from here
- long int x = 0;
- long int y = 0;
+ return wrong_argument_type(gc, "string-or-symbol-p", target);
+}
- boxes_add_box(boxes, rect((float) x, (float) y, (float) w, (float) h), color);
- return eval_success(NIL(gc));
- }
+int boxes_delete_at(Boxes *boxes, Vec position)
+{
+ trace_assert(boxes);
- return unknown_target(gc, "box", action);
+ for (size_t i = 0; i < boxes->count; ++i) {
+ const Rect hitbox = rigid_bodies_hitbox(
+ boxes->rigid_bodies,
+ boxes->body_ids[i]);
+ if (rect_contains_point(hitbox, position)) {
+ rigid_bodies_remove(boxes->rigid_bodies, boxes->body_ids[i]);
+ for (size_t j = i; j < boxes->count - 1; ++j) {
+ boxes->body_ids[j] = boxes->body_ids[j + 1];
+ }
+ boxes->count--;
+ return 0;
+ }
}
- return wrong_argument_type(gc, "string-or-symbol-p", target);
+ return 0;
}