commit 8a7689e031500c1675b74eac30a4260cfe77af90
parent 24091625e1a39f6df615f44416749ba5e0cfa6d2
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 10 Jan 2023 09:38:29 +0900
add collision handler for list
Diffstat:
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/ex9/main.c b/ex9/main.c
@@ -5,9 +5,9 @@
#include <unistd.h>
#include <string.h>
+#include "list.h"
#include "object.h"
#include "draw.h"
-#include "list.h"
#include "world_map.h"
/*
@@ -71,7 +71,6 @@ void sort_list_dist(struct List *, struct Object *);
void draw_object(const struct Object *);
void draw_object_scroll(const struct Object *, int);
-
void
start_menu(void)
{
diff --git a/ex9/object.c b/ex9/object.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdint.h>
+#include "list.h"
#include "object.h"
static int test_collision_rr(struct Object *, struct Object *);
@@ -181,6 +182,20 @@ is_on_floor_before(struct Object *player, struct Object *floor)
return col;
}
-void handle_collision(struct Object *o0, struct Object *o1) {
+void
+handle_collision(struct Object *o0, struct Object *o1)
+{
(* col_func[o0->type][o1->type])(o0, o1);
}
+
+void
+lhandle_collision(struct List *o)
+{
+ struct List *p, *q;
+ for (p = o; p != NULL && p->next != NULL; p = p->next) {
+ for (q = p->next; q != NULL; q = q->next) {
+ handle_collision((struct Object *)p, (struct Object *)q);
+ }
+ }
+ return;
+}
diff --git a/ex9/object.h b/ex9/object.h
@@ -1,3 +1,5 @@
+// include list.h before this file
+
enum object_shape {
SRECTANGLE,
STRIANGLE,
@@ -61,3 +63,4 @@ struct Object *create_object(enum object_type, uint32_t,
int, int, int);
void free_object(struct Object *);
int is_on_floor_before(struct Object *, struct Object *);
+void lhandle_collision(struct List *);