summaryrefslogtreecommitdiffhomepage
path: root/src/wall.c
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-05-28 17:05:53 -0400
committerrealtradam <[email protected]>2023-05-28 17:05:53 -0400
commitf54e3249d5c8fff4f7a64381c6dd7210c81f569a (patch)
tree9143a584c40a7614ae43f94f7685810ef12c78b3 /src/wall.c
parent9bf228460712579f867fb506b1a84022fa302452 (diff)
downloadrodeo_sample_game-f54e3249d5c8fff4f7a64381c6dd7210c81f569a.tar.gz
rodeo_sample_game-f54e3249d5c8fff4f7a64381c6dd7210c81f569a.zip
fix a lot, make a lot work
Diffstat (limited to 'src/wall.c')
-rw-r--r--src/wall.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/wall.c b/src/wall.c
index 5a2d6df..1be1a78 100644
--- a/src/wall.c
+++ b/src/wall.c
@@ -1,4 +1,5 @@
#include "wall.h"
+#include "rodeo.h"
static rodeo_collision_2d_world_t collision_wall_world;
@@ -53,3 +54,51 @@ coords_inside_wall(
}
return false;
}
+
+void
+moving_wall_resolver(
+ rodeo_collision_2d_world_item_t *obj_collision,
+ rodeo_collision_2d_world_item_t *wall_collision
+)
+{
+ rodeo_collision_2d_world_item_t *p = obj_collision;
+ rodeo_collision_2d_world_item_t *w = wall_collision;
+ rodeo_rectangle_t step = (rodeo_rectangle_t){
+ .x = p->x + p->dx * rodeo_frame_time_get(),
+ .y = p->y + p->dy * rodeo_frame_time_get(),
+ .width = p->width,
+ .height = p->height
+ };
+ rodeo_rectangle_t intersection = rodeo_collision_2d_get_collision_rect(p, w);
+ if (intersection.width < intersection.height) {
+ if (intersection.x == step.x) {
+ p->x = w->x + w->width;
+ if (p->dx < 0) {
+ p->dx = 0;
+ }
+ } else {
+ p->x = w->x - p->width;
+ if (p->dx > 0) {
+ p->dx = 0;
+ }
+ }
+ }
+ else if (intersection.height < intersection.width) {
+ if (intersection.y == step.y) {
+ p->y = w->y + w->height;
+ if (p->dy < 0) {
+ p->dy = 0;
+ }
+ } else {
+ p->y = w->y - p->height;
+ if (p->dy > 0) {
+ p->dy = 0;
+ }
+ }
+ }
+ else if (p->width == w->width && p->height == w->height) {
+ p->dx = 0;
+ p->dy = 0;
+ }
+}
+