[bugfix] camera and scale related code, now work properly regardless of scale

You can now experience scrolling in your fancy CG50 :D
This commit is contained in:
KikooDX 2020-09-21 19:04:27 +02:00
parent ee723cc151
commit bc5273ed77
3 changed files with 18 additions and 15 deletions

View File

@ -13,7 +13,9 @@ void camera_step(Camera *camera)
Vec * const offset = &camera->offset; /* DRY */
vec_cpy(offset, camera->pos);
vec_div(offset, VEC_PRECISION);
vec_sub(offset, VEC_DCENTER);
Vec scaled_dcenter = VEC_DCENTER;
vec_div(&scaled_dcenter, 2);
vec_sub(offset, scaled_dcenter);
}
void camera_draw_debug(Camera *camera)

View File

@ -34,8 +34,9 @@ void layer_draw(const Level *level, Camera *camera, uint layer_id)
vec_mul(&tl, VEC_PRECISION * TILE_SIZE);
vec_div(&tl, VEC_PRECISION);
vec_sub(&tl, camera->offset);
vec_mul(&tl, SCALE);
vec_cpy(&br, tl);
vec_add(&br, (Vec){TILE_SIZE - 1, TILE_SIZE - 1});
vec_add(&br, (Vec){TILE_SIZE * SCALE - 1, TILE_SIZE * SCALE - 1});
vec_drect(tl, br, color);
}
}

View File

@ -17,19 +17,19 @@ void player_step(Player *player, Input *input)
void player_draw(Player *player, Camera *camera)
{
Vec draw_pos_tl;
Vec draw_pos_br;
vec_cpy(&draw_pos_tl, player->pos);
vec_sub(&draw_pos_tl, player->origin);
vec_cpy(&draw_pos_br, draw_pos_tl);
vec_div(&draw_pos_tl, VEC_PRECISION);
vec_div(&draw_pos_br, VEC_PRECISION);
vec_mul(&draw_pos_tl, SCALE);
vec_mul(&draw_pos_br, SCALE);
vec_sub(&draw_pos_tl, camera->offset);
vec_sub(&draw_pos_br, camera->offset);
vec_add(&draw_pos_br, player->vbox);
vec_drect(draw_pos_tl, draw_pos_br, C_BLACK);
Vec tl;
Vec br;
vec_cpy(&tl, player->pos);
vec_sub(&tl, player->origin);
vec_cpy(&br, tl);
vec_div(&tl, VEC_PRECISION);
vec_div(&br, VEC_PRECISION);
vec_add(&br, player->vbox);
vec_sub(&tl, camera->offset);
vec_sub(&br, camera->offset);
vec_mul(&tl, SCALE);
vec_mul(&br, SCALE);
vec_drect(tl, br, C_BLACK);
}
void player_draw_debug(Player *player, uint step)