better struct and files organization, and still only half raycast on map but no view created
This commit is contained in:
@@ -4,9 +4,9 @@ int is_wall(t_game *game, int cell_x, int cell_y)
|
||||
{
|
||||
if (cell_x < 0 || cell_y < 0)
|
||||
return (1);
|
||||
if (cell_x > game->map_size_x || cell_y > game->map_size_y)
|
||||
if (cell_x > game->map.size_x || cell_y > game->map.size_y)
|
||||
return (1);
|
||||
if (game->map[cell_y][cell_x] != '0')
|
||||
if (game->map.content[cell_y][cell_x] != '0')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@@ -18,10 +18,10 @@ int plr_out_limits(t_game *game, int x, int y)
|
||||
int cell_x;
|
||||
int cell_y;
|
||||
|
||||
xmax = game->sizel / (game->bpp / 8);
|
||||
ymax = game->win_size_y;
|
||||
cell_x = x / game->cell;
|
||||
cell_y = y / game->cell;
|
||||
xmax = game->map_img.sizel / (game->map_img.bpp / 8);
|
||||
ymax = game->map_win.size_y;
|
||||
cell_x = x / CELL;
|
||||
cell_y = y / CELL;
|
||||
if (is_wall(game, cell_x, cell_y))
|
||||
return (1);
|
||||
if (x < 0 || y < 0 || x > xmax || y > ymax)
|
||||
|
||||
@@ -1,65 +1,61 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_posx_decrement(t_game *game)
|
||||
void plr_posx_decrement(t_game *game, t_plr *plr)
|
||||
{
|
||||
double pos_x;
|
||||
double pos_y;
|
||||
t_d_coord pos;
|
||||
|
||||
pos_x = game->plr_exact_x - 5;
|
||||
pos_y = game->plr_exact_y;
|
||||
rotate_double(game, &pos_x, &pos_y);
|
||||
if (plr_out_limits(game, pos_x, pos_y))
|
||||
pos.x = plr->exact.x - PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &pos);
|
||||
if (plr_out_limits(game, pos.x, pos.y))
|
||||
return ;
|
||||
game->plr_exact_x = pos_x;
|
||||
game->plr_exact_y = pos_y;
|
||||
(game->plr_x) = (int)pos_x;
|
||||
(game->plr_y) = (int)pos_y;
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
(plr->pos.y) = (int)(pos.y);
|
||||
}
|
||||
|
||||
void plr_posy_decrement(t_game *game)
|
||||
void plr_posy_decrement(t_game *game, t_plr *plr)
|
||||
{
|
||||
double pos_x;
|
||||
double pos_y;
|
||||
t_d_coord pos;
|
||||
|
||||
pos_x = game->plr_exact_x;
|
||||
pos_y = game->plr_exact_y - 5;
|
||||
rotate_double(game, &pos_x, &pos_y);
|
||||
if (plr_out_limits(game, pos_x, pos_y))
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y - PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
if (plr_out_limits(game, pos.x, pos.y))
|
||||
return ;
|
||||
game->plr_exact_x = pos_x;
|
||||
game->plr_exact_y = pos_y;
|
||||
(game->plr_x) = (int)pos_x;
|
||||
(game->plr_y) = (int)pos_y;
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
(plr->pos.y) = (int)(pos.y);
|
||||
}
|
||||
|
||||
void plr_posx_increment(t_game *game)
|
||||
void plr_posx_increment(t_game *game, t_plr *plr)
|
||||
{
|
||||
double pos_x;
|
||||
double pos_y;
|
||||
t_d_coord pos;
|
||||
|
||||
pos_x = game->plr_exact_x + 5;
|
||||
pos_y = game->plr_exact_y;
|
||||
rotate_double(game, &pos_x, &pos_y);
|
||||
if (plr_out_limits(game, pos_x, pos_y))
|
||||
pos.x = plr->exact.x + PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &(pos));
|
||||
if (plr_out_limits(game, pos.x, pos.y))
|
||||
return ;
|
||||
game->plr_exact_x = pos_x;
|
||||
game->plr_exact_y = pos_y;
|
||||
(game->plr_x) = (int)pos_x;
|
||||
(game->plr_y) = (int)pos_y;
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
(plr->pos.y) = (int)(pos.y);
|
||||
}
|
||||
|
||||
void plr_posy_increment(t_game *game)
|
||||
void plr_posy_increment(t_game *game, t_plr *plr)
|
||||
{
|
||||
double pos_x;
|
||||
double pos_y;
|
||||
t_d_coord pos;
|
||||
|
||||
pos_x = game->plr_exact_x;
|
||||
pos_y = game->plr_exact_y + 5;
|
||||
rotate_double(game, &pos_x, &pos_y);
|
||||
if (plr_out_limits(game, pos_x, pos_y))
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y + PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
if (plr_out_limits(game, pos.x, pos.y))
|
||||
return ;
|
||||
game->plr_exact_x = pos_x;
|
||||
game->plr_exact_y = pos_y;
|
||||
(game->plr_x) = (int)pos_x;
|
||||
(game->plr_y) = (int)pos_y;
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
(plr->pos.y) = (int)(pos.y);
|
||||
}
|
||||
|
||||
@@ -1,35 +1,75 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_turn_left(t_game *game)
|
||||
void rotate(t_plr *plr, t_coord *coord)
|
||||
{
|
||||
int old_x;
|
||||
t_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->pos.x;
|
||||
tmp.y = coord->y - plr->pos.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->pos.x;
|
||||
coord->y = tmp.y + plr->pos.y;
|
||||
}
|
||||
|
||||
void rotate_double(t_plr *plr, t_d_coord *coord)
|
||||
{
|
||||
double old_x;
|
||||
t_d_coord tmp;
|
||||
|
||||
// do nothing if not rotating
|
||||
if (plr->rot == 0)
|
||||
return ;
|
||||
// offset center
|
||||
tmp.x = coord->x - plr->exact.x;
|
||||
tmp.y = coord->y - plr->exact.y;
|
||||
// calculate new coordinates
|
||||
old_x = tmp.x;
|
||||
tmp.x = tmp.x * plr->cosi + tmp.y * plr->cosj;
|
||||
tmp.y = old_x * plr->sini + tmp.y * plr->sinj;
|
||||
// de-offset center
|
||||
coord->x = tmp.x + plr->exact.x;
|
||||
coord->y = tmp.y + plr->exact.y;
|
||||
}
|
||||
|
||||
void plr_turn_left(t_plr *plr)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
if (game->rot == -180)
|
||||
(game->rot) *= -1;
|
||||
(game->rot)--;
|
||||
if (plr->rot == -180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)--;
|
||||
// calculate trigo for rotations
|
||||
radi = game->rot * M_PI / 180;
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
game->cosi = cos(radi);
|
||||
game->sini = sin(radi);
|
||||
game->cosj = cos(radj);
|
||||
game->sinj = sin(radj);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
void plr_turn_right(t_game *game)
|
||||
void plr_turn_right(t_plr *plr)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
if (game->rot == 180)
|
||||
(game->rot) *= -1;
|
||||
(game->rot)++;
|
||||
if (plr->rot == 180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)++;
|
||||
// calculate trigo for rotations
|
||||
radi = game->rot * M_PI / 180;
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
game->cosi = cos(radi);
|
||||
game->sini = sin(radi);
|
||||
game->cosj = cos(radj);
|
||||
game->sinj = sin(radj);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user