game image created but all wrong

This commit is contained in:
hugogogo
2022-04-24 21:18:36 +02:00
parent a11ea35ac1
commit 03f61d989b
6 changed files with 50 additions and 33 deletions

View File

@@ -22,19 +22,19 @@ void draw_pixel(t_img *img, int x, int y, int color)
*(unsigned int*)(img->data + position) = color;
}
void draw_line(t_img *img, t_vec vec, int color)
void draw_line(t_img *img, t_vec *vec, int color)
{
t_coord dist;
int i;
int j;
dist.x = vec.end.x - vec.start.x;
dist.y = vec.end.y - vec.start.y;
dist.x = (*vec).end.x - (*vec).start.x;
dist.y = (*vec).end.y - (*vec).start.y;
i = 0;
j = 0;
while (ft_abs(i) <= ft_abs(dist.x) && ft_abs(j) <= ft_abs(dist.y))
{
draw_pixel(img, vec.start.x + i, vec.start.y + j, color);
draw_pixel(img, (*vec).start.x + i, (*vec).start.y + j, color);
if (!ft_abs(dist.x) || ft_abs(j) < ft_abs(i * dist.y / dist.x))
j += ft_sign(dist.y);
else
@@ -113,14 +113,14 @@ void draw_line(t_img *img, t_vec vec, int color)
screen.end.x = rcast->screen_size.end.x + game->plr.pos.x;
screen.end.y = rcast->screen_size.end.y + game->plr.pos.y;
rotate(&(game->plr), &(screen.end));
draw_line(&game->map_img, screen, 0x00FFFFFF);
draw_line(&game->map_img, &screen, 0x00FFFFFF);
// draw screen dist
screen.start.x = rcast->screen_dist.start.x + game->plr.pos.x;
screen.start.y = rcast->screen_dist.start.y + game->plr.pos.y;
screen.end.x = rcast->screen_dist.end.x + game->plr.pos.x;
screen.end.y = rcast->screen_dist.end.y + game->plr.pos.y;
rotate(&(game->plr), &(screen.end));
draw_line(&game->map_img, screen, 0x00FFFFFF);
draw_line(&game->map_img, &screen, 0x00FFFFFF);
}
// tmp end
@@ -137,5 +137,5 @@ void draw(t_game *game)
mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
// tmp end
// mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
mlx_put_image_to_window(game->mlx_ptr, game->win.ptr, game->img.ptr, 0, 0);
}