Skip to content

Commit

Permalink
Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblockguy committed Nov 3, 2020
1 parent 14e9364 commit ac618b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@


bool detect_collision(physics_body_t *p1, physics_body_t *p2) {
return p1->position_x < p2->position_x + p2->width && p1->position_x + p1->width > p2->position_x &&
p1->position_y < p2->position_y + p2->height && p1->position_y + p1->height > p2->position_y;
return p1->position_x < p2->position_x + (int24_t)p2->width &&
p1->position_x + (int24_t)p1->width > p2->position_x &&
p1->position_y < p2->position_y + (int24_t)p2->height &&
p1->position_y + (int24_t)p1->height > p2->position_y;
}

bool center_distance_less_than(physics_body_t *p1, physics_body_t *p2, uint24_t dis) {
int24_t delta_x;
int24_t delta_y;

if(abs((int24_t) center_x(p1) - (int24_t) center_x(p2)) > dis) return false;
if(abs((int24_t) center_y(p1) - (int24_t) center_y(p2)) > dis) return false;
if((uint24_t)abs((int24_t) center_x(p1) - (int24_t) center_x(p2)) > dis) return false;
if((uint24_t)abs((int24_t) center_y(p1) - (int24_t) center_y(p2)) > dis) return false;

delta_x = (center_x(p1) - center_x(p2)) >> 8;
delta_y = (center_y(p1) - center_y(p2)) >> 8;

return delta_x * delta_x + delta_y * delta_y < (dis >> 8) * (dis >> 8);
return (uint24_t)(delta_x * delta_x + delta_y * delta_y) < (dis >> 8) * (dis >> 8);
}

//Check if a point is colliding with a tile
Expand Down Expand Up @@ -85,8 +87,10 @@ direction_t process_reflection(physics_body_t *p, bool respect_holes) {
return dir;
}

bool is_point_inside_body(physics_body_t *p, uint24_t x, uint24_t y) {
return p->position_x <= x && p->position_y <= y && p->position_x + p->width >= x && p->position_y + p->height >= y;
bool is_point_inside_body(physics_body_t *p, int24_t x, int24_t y) {
return p->position_x <= x && p->position_y <= y &&
p->position_x + (int24_t)p->width >= x &&
p->position_y + (int24_t)p->height >= y;
}

bool collide_and_push(physics_body_t *p1, physics_body_t *p2) {
Expand Down
2 changes: 1 addition & 1 deletion src/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline uint24_t center_y(const physics_body_t *p) { return p->position_y + p->he
bool detect_collision(physics_body_t *p1, physics_body_t *p2);

//Check if a point is inside a bounding box
bool is_point_inside_body(physics_body_t *p, uint24_t x, uint24_t y);
bool is_point_inside_body(physics_body_t *p, int24_t x, int24_t y);

//Determine if a collision occurs with the tilemap
direction_t process_reflection(physics_body_t *p, bool respect_holes);
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void handle_input() {

if(moving) {
int24_t diff = player->tread_rot - target_rot;
if(abs(diff) > DEGREES_TO_ANGLE(90)) {
if((uint24_t)abs(diff) > DEGREES_TO_ANGLE(90)) {
player->tread_rot += DEGREES_TO_ANGLE(180);
diff = (int24_t) (player->tread_rot - target_rot);
}
Expand All @@ -294,7 +294,7 @@ void handle_input() {
player->tread_rot = target_rot;
}

if(abs(diff) <= DEGREES_TO_ANGLE(45)) {
if((uint24_t)abs(diff) <= DEGREES_TO_ANGLE(45)) {
set_velocity(player, TANK_SPEED_NORMAL);
} else {
set_velocity(player, 0);
Expand Down

0 comments on commit ac618b1

Please sign in to comment.