resolve floating point exception when wliding through walls
This commit is contained in:
@@ -5,16 +5,23 @@ void plr_posx_decrement(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x - PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &pos);
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -26,16 +33,23 @@ void plr_posy_decrement(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y - PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -47,16 +61,23 @@ void plr_posx_increment(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x + PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -68,16 +89,23 @@ void plr_posy_increment(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y + PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
|
||||
@@ -73,3 +73,18 @@ void plr_turn_right(t_plr *plr)
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
void plr_turn(t_plr *plr, int deg)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
plr->rot = deg;
|
||||
// calculate trigo for rotations
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user