Skip to content

Commit

Permalink
norm
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerio Antunes de souza junior committed May 6, 2021
1 parent 7171f2f commit c89d4c8
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added a.out
Binary file not shown.
51 changes: 51 additions & 0 deletions bmp.c
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 2 additions & 24 deletions calcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions calcs2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
49 changes: 0 additions & 49 deletions cub3d.c
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions inits.cub
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ C = 63,6,63
1111100000000000000020000011
100000000000000000000000111111111
100000000000000000000000000001
100000000000000002000000000001
100000000020000002000000000001
100000000000000000000000000001
1000000000000000000000000000001
100000000000000000000000000001
100000000020000200000200000001
1000000000000E0000000000000001
100000000000000000000000000001
11111111111111111111111111111
Binary file modified screenshot.bmp
Binary file not shown.

0 comments on commit c89d4c8

Please sign in to comment.