aboutsummaryrefslogtreecommitdiff
path: root/src/engine/entity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/entity.c')
-rw-r--r--src/engine/entity.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/engine/entity.c b/src/engine/entity.c
index 535759d..58b62c9 100644
--- a/src/engine/entity.c
+++ b/src/engine/entity.c
@@ -45,18 +45,18 @@ void hh_solve_collision(vec2 pos_environment, hh_entity* entity){
}
hh_entity hh_background_collision (hh_entity temp_old_entity,hh_entity temp_new_entity){
- temp_old_entity.is_grounded = false;
+ temp_new_entity.is_grounded = false;
// solves x collision
if (temp_old_entity.vel.x <= 0) {
if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_old_entity.pos.y + 0})) ||
- hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_old_entity.pos.y + 15}))) {
+ hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_old_entity.pos.y + (temp_old_entity.size.y-1)}))) {
temp_new_entity.pos.x = (temp_new_entity.pos.x & ~15) + 16,
temp_new_entity.vel.x = 0;
}
} else {
- if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 16, .y=temp_old_entity.pos.y + 0})) ||
- hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 16, .y=temp_old_entity.pos.y + 15}))) {
+ if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + temp_old_entity.size.x, .y=temp_old_entity.pos.y + 0})) ||
+ hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + temp_old_entity.size.x, .y=temp_old_entity.pos.y + (temp_old_entity.size.y-1)}))) {
temp_new_entity.pos.x = temp_new_entity.pos.x & ~15, // <-- magic comma, NOT TOUCHY
temp_new_entity.vel.x = 0;
}
@@ -65,20 +65,22 @@ hh_entity hh_background_collision (hh_entity temp_old_entity,hh_entity temp_new_
//solves y collision
if (temp_old_entity.vel.y <= 0) {
if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_new_entity.pos.y + 0})) ||
- hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 15, .y=temp_new_entity.pos.y + 0}))) {
+ hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + (temp_new_entity.size.x-1), .y=temp_new_entity.pos.y + 0}))) {
temp_new_entity.pos.y = (temp_new_entity.pos.y & ~15) + 16,
temp_new_entity.vel.y = 0;
}
} else {
- if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_new_entity.pos.y + 15})) ||
- hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 15, .y=temp_new_entity.pos.y + 15}))) {
+ if (hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + 0, .y=temp_new_entity.pos.y + (temp_new_entity.size.y-1)})) ||
+ hh_colidable(hh_world_to_tile((vec2){.x=temp_new_entity.pos.x + (temp_new_entity.size.x-1), .y=temp_new_entity.pos.y + (temp_new_entity.size.y-1)}))) {
temp_new_entity.pos.y = temp_new_entity.pos.y & ~15,
temp_new_entity.vel.y = 0;
- temp_old_entity.is_grounded = true;
+ temp_new_entity.is_grounded = true;
}
}
- temp_old_entity.pos = temp_new_entity.pos;
- temp_old_entity.vel = temp_new_entity.vel;
+ temp_old_entity = temp_new_entity;
+ // temp_old_entity.is_grounded = temp_new_entity.is_grounded;
+ // temp_old_entity.pos = temp_new_entity.pos;
+ // temp_old_entity.vel = temp_new_entity.vel;
return temp_old_entity;
}