From 3e619979dafa64c6b2576420ff1ce59462256d5e Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 10 Aug 2021 02:08:41 -0400 Subject: char: Add collision detection/handling --- (limited to 'src/char/char.c') diff --git a/src/char/char.c b/src/char/char.c index 0ab7145..4a4a4e7 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -126,6 +126,24 @@ mf_char_update(struct mf_char *c) } int +mf_char_collision(struct mf_char *c1, struct mf_char *c2, int handle) +{ + if (c1->cur_x == c2->cur_x && c1->cur_y == c2->cur_y) goto hit; + if (c1->cur_x == c2->new_x && c1->cur_y == c2->new_y) goto hit; + if (c1->new_x == c2->cur_x && c1->new_y == c2->cur_y) goto hit; + if (c1->new_x == c2->new_x && c1->new_y == c2->new_y) goto hit; + + return 0; + + hit: + if (handle == SDL_TRUE) { + c1->collide(c1); + c2->collide(c2); + } + return 1; +} + +int mf_char_render(struct mf_char *c, SDL_Renderer *renderer) { int e = 0; -- cgit v0.9.1