벽 뚫기 방지
- 보너스 → 충돌 이펙트 구현과 같다고 봐도 된다.
- 따라서 이걸 잘하면 그냥 5점을 꿀꺽..
before
c
void backward_move(t_vec_f *pos, t_vec_f *dir)
{
float new_x;
float new_y;
new_x = pos->x - dir->x * VELOCITY;
new_y = pos->y - dir->y * VELOCITY;
if (new_x > 0 && new_x < WIDTH)
{
if (new_y > 0 && new_y < HEIGHT)
{
pos->x = new_x;
pos->y = new_y;
}
}
}
이렇게 해도 못 넘어가지는 않는다.
after
c
void backward_move(t_box *tools, t_vec_f *pos, t_vec_f *dir)
{
float new_x;
float new_y;
new_x = pos->x - dir->x * VELOCITY;
new_y = pos->y - dir->y * VELOCITY;
if (tools->total_map[(int)pos->y][(int)new_x] == 0)
pos->x = new_x;
if (tools->total_map[(int)new_y][(int)pos->x] == 0)
pos->y = new_y;
}
새로운 위치 (new)와 기존 위치 (pos)를 int로 변환한다.
이걸 맵에 넣어보며 뚫울 수 있는지 비교해 봐야 한다.