diff --git a/Makefile b/Makefile index 641d90f..16c284f 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ RM = rm -f NAME = cub3d.a INCLUDE = cub3d.h -SRCS = cub3d.c calcs.c calcs2.c keys.c inits.c draws.c sprite.c utils.c parse2.c get_next_line.c get_next_line_utils.c parse.c parse_map.c lst.c +SRCS = cub3d.c calcs.c calcs2.c keys.c inits.c draws.c sprite.c utils.c parse2.c get_next_line.c get_next_line_utils.c parse.c parse_map.c lst.c bmp.c all: $(CC) -Wall -Werror -Wextra -lmlx -lm -framework OpenGL -framework AppKit $(SRCS) diff --git a/a.out b/a.out new file mode 100755 index 0000000..060e157 Binary files /dev/null and b/a.out differ diff --git a/bmp.c b/bmp.c new file mode 100644 index 0000000..22f68b3 --- /dev/null +++ b/bmp.c @@ -0,0 +1,51 @@ +#include "cub3d.h" + +void set_int_in_char(unsigned char *start, int value) +{ + start[0] = (unsigned char)(value); + start[1] = (unsigned char)(value >> 8); + start[2] = (unsigned char)(value >> 16); + start[3] = (unsigned char)(value >> 24); +} + +int write_bmp_header(int fd, int filesize, t_game *game) +{ + int i; + int tmp; + unsigned char bmpfileheader[54]; + + i = 0; + while (i < 54) + bmpfileheader[i++] = (unsigned char)(0); + bmpfileheader[0] = (unsigned char)('B'); + bmpfileheader[1] = (unsigned char)('M'); + set_int_in_char(bmpfileheader + 2, filesize); + bmpfileheader[10] = (unsigned char)(54); + bmpfileheader[14] = (unsigned char)(40); + tmp = game->width_screen; + set_int_in_char(bmpfileheader + 18, tmp); + tmp = game->height_screen; + set_int_in_char(bmpfileheader + 22, tmp); + bmpfileheader[27] = (unsigned char)(1); + bmpfileheader[28] = (unsigned char)(24); + return (!(write(fd, bmpfileheader, 54) < 0)); +} + +int write_bmp_data(int file, t_game *game) +{ + int i; + int j; + draw_all(game); + i = game->height_screen - 1; + while (i >= 0) + { + j = 0; + while (j < game->width_screen) + { + write(file, &game->bmp_buf[i][j], 3); + j++; + } + i--; + } + return (1); +} diff --git a/calcs.c b/calcs.c index b047a84..4e43d83 100644 --- a/calcs.c +++ b/calcs.c @@ -66,31 +66,9 @@ void steps(t_wall *wall , t_game *game) wall->stepY = 1; wall->sideDistY = (wall->mapY + 1.0 - game->posY) * wall->deltaDistY; } - - while (wall->hit == 0) - { - if (wall->sideDistX < wall->sideDistY) - { - wall->sideDistX += wall->deltaDistX; - wall->mapX += wall->stepX; - if (wall->stepX == 1) - wall->side = 0; - else if (wall->stepX == -1) - wall->side = 1; - } - else - { - wall->sideDistY += wall->deltaDistY; - wall->mapY += wall->stepY; - if (wall->stepY == 1) - wall->side = 2; - else if (wall->stepY == -1) - wall->side = 3; - } - if (game->map[wall->mapX][wall->mapY] == '1') - wall->hit = 1; - } + hit_wall(game,wall); } + void perp_wall(t_game *game, t_wall *wall) { if (wall->side == 0 || wall->side == 1) diff --git a/calcs2.c b/calcs2.c index d1de17a..3a5dc5f 100644 --- a/calcs2.c +++ b/calcs2.c @@ -33,4 +33,31 @@ void draw_wall(t_game *game, t_textures *textures, t_wall *wall) textures->color = game->texture[3][texHeight * textures->texY + textures->texX]; game->buf[wall->y][wall->x] = textures->color; } +} + +void hit_wall(t_game *game, t_wall *wall) +{ + while (wall->hit == 0) + { + if (wall->sideDistX < wall->sideDistY) + { + wall->sideDistX += wall->deltaDistX; + wall->mapX += wall->stepX; + if (wall->stepX == 1) + wall->side = 0; + else if (wall->stepX == -1) + wall->side = 1; + } + else + { + wall->sideDistY += wall->deltaDistY; + wall->mapY += wall->stepY; + if (wall->stepY == 1) + wall->side = 2; + else if (wall->stepY == -1) + wall->side = 3; + } + if (game->map[wall->mapX][wall->mapY] == '1') + wall->hit = 1; + } } \ No newline at end of file diff --git a/cub3d.c b/cub3d.c index 89c62f8..a388ab7 100644 --- a/cub3d.c +++ b/cub3d.c @@ -1,54 +1,5 @@ #include "cub3d.h" -void set_int_in_char(unsigned char *start, int value) -{ - start[0] = (unsigned char)(value); - start[1] = (unsigned char)(value >> 8); - start[2] = (unsigned char)(value >> 16); - start[3] = (unsigned char)(value >> 24); -} - -int write_bmp_header(int fd, int filesize, t_game *game) -{ - int i; - int tmp; - unsigned char bmpfileheader[54]; - - i = 0; - while (i < 54) - bmpfileheader[i++] = (unsigned char)(0); - bmpfileheader[0] = (unsigned char)('B'); - bmpfileheader[1] = (unsigned char)('M'); - set_int_in_char(bmpfileheader + 2, filesize); - bmpfileheader[10] = (unsigned char)(54); - bmpfileheader[14] = (unsigned char)(40); - tmp = game->width_screen; - set_int_in_char(bmpfileheader + 18, tmp); - tmp = game->height_screen; - set_int_in_char(bmpfileheader + 22, tmp); - bmpfileheader[27] = (unsigned char)(1); - bmpfileheader[28] = (unsigned char)(24); - return (!(write(fd, bmpfileheader, 54) < 0)); -} - -int write_bmp_data(int file, t_game *game) -{ - int i; - int j; - draw_all(game); - i = game->height_screen - 1; - while (i >= 0) - { - j = 0; - while (j < game->width_screen) - { - write(file, &game->bmp_buf[i][j], 3); - j++; - } - i--; - } - return (1); -} void calc(t_game *game) { diff --git a/cub3d.h b/cub3d.h index b94abe3..d4c586d 100644 --- a/cub3d.h +++ b/cub3d.h @@ -219,5 +219,9 @@ void calc(t_game *game); int ft_strncmp(const char *str1, const char *str2, size_t n); void init_bpm_buf(t_game *game); void draw_all(t_game *game); +void hit_wall(t_game *game, t_wall *wall); +void set_int_in_char(unsigned char *start, int value); +int write_bmp_header(int fd, int filesize, t_game *game); +int write_bmp_data(int file, t_game *game); #endif \ No newline at end of file diff --git a/inits.cub b/inits.cub index 1a02f33..64f5a4f 100644 --- a/inits.cub +++ b/inits.cub @@ -15,10 +15,10 @@ C = 63,6,63 1111100000000000000020000011 100000000000000000000000111111111 100000000000000000000000000001 -100000000000000002000000000001 +100000000020000002000000000001 100000000000000000000000000001 1000000000000000000000000000001 -100000000000000000000000000001 +100000000020000200000200000001 1000000000000E0000000000000001 100000000000000000000000000001 11111111111111111111111111111 diff --git a/screenshot.bmp b/screenshot.bmp index 9b2c357..1444d34 100755 Binary files a/screenshot.bmp and b/screenshot.bmp differ