summaryrefslogtreecommitdiff
path: root/src/throwables.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 16:53:33 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 16:53:33 +0100
commit04024078984bbaf84f34352061da2a224ecdb0b0 (patch)
treee576cdd0451e06d96c71131c551b1bc32d633f0d /src/throwables.c
parent61c5fb1e253f31d2faa3a0fc970ce4e18f32b205 (diff)
fix throwable collision
Diffstat (limited to 'src/throwables.c')
-rw-r--r--src/throwables.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/throwables.c b/src/throwables.c
index cd8f8af..86a9734 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -33,27 +33,45 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size);
+ if (o.type == OBJECT_PLANTBOX1 && oldpos.x < o.position.x && newpos.x > o.position.x) {
+ log_infox("intersect {%.2f %.2f}{%.2f %.2f} {%.2f %.2f}{%.2f %.2f}",
+ oldpos.x, oldpos.y, newpos.x, newpos.y, o.position.x, o.position.y, o.position.x, o.position.y + o.size.y);
+
+ //if (lines_intersect((vec2f){15.99, 8.58}, (vec2f){16.05, 8.58}, (vec2f){16.00, 8.00}, (vec2f){16.00, 9.00})) {
+ // log_info("POOOp");
+ //}
+ }
+
+ // top
if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y})) {
- result = true;
+ result = true;
+ direction->y = -direction->y;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+
+ // bottom
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y + o.size.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.size.y})) {
- result = true;
+ result = true;
+ direction->y = -direction->y;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+
+ // left
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y}, (vec2f){.x = o.position.x, .y = o.position.y + o.size.y})) {
- result = true;
+ result = true;
+ direction->x = -direction->x;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
- (vec2f){.x = o.position.x + o.size.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.position.y})) {
- result = true;
+
+ // right
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+ (vec2f){.x = o.position.x + o.size.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.size.y})) {
+ result = true;
+ direction->x = -direction->x;
}
if (result) {
- b->position = oldpos;
- direction->x = -direction->x;
- direction->y = -direction->y;
+ b->position = oldpos;
return true;
}
}
@@ -91,6 +109,9 @@ void update_throwables_server() {
throwable b = throwables[i];
if (!b.active) continue;
+ throwables[i].rotation += SERVER_TICK_RATE*3.0f*throwables[i].bounces;
+
+
throwables[i].alive_time += SERVER_TICK_RATE;
if (throwables[i].alive_time >= 2.0f) {
@@ -164,6 +185,7 @@ void draw_throwables(platform_window* window) {
box box = get_render_box_of_square(window, explode_location, grenade_explosion_size);
sprite_frame frame = sprite_get_frame(&throwables[i].sprite);
+
renderer->render_image_quad_partial(img_grenade_explode,
box.tl_u.x, box.tl_u.y,
box.bl_d.x, box.bl_d.y,
@@ -172,9 +194,13 @@ void draw_throwables(platform_window* window) {
frame.tl, frame.tr, frame.bl, frame.br);
}
else if (t.state == THROWABLE_FLYING) {
+ renderer->render_set_rotation(t.rotation);
+
box full_box = get_render_box_of_square(window, t.position, (vec3f){0.2, 0.2, 0.2});
renderer->render_image(img_grenade, full_box.tl_u.x, full_box.tl_u.y,
full_box.br_d.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y);
+
+ renderer->render_set_rotation(0.0f);
}
}
} \ No newline at end of file