]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level/boxes.c
(#802) TODO
[nothing.git] / src / game / level / boxes.c
index ac1edd5fbe67df07dea9ea3a12b4779122a916b6..462475e9fb169996797fd6ec30107bddeac63eab 100644 (file)
@@ -113,7 +113,6 @@ void boxes_float_in_lava(Boxes *boxes, Lava *lava)
     }
 }
 
-static
 int boxes_add_box(Boxes *boxes, Rect rect, Color color)
 {
     trace_assert(boxes);
@@ -159,32 +158,32 @@ boxes_send(Boxes *boxes, Gc *gc, struct Scope *scope, struct Expr path)
             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;
 }