Skip to content

Commit

Permalink
back in time to fix my own shit and working
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAlabar committed Jan 26, 2025
1 parent 91b20cf commit ef3498b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
Binary file removed cub3D
Binary file not shown.
58 changes: 41 additions & 17 deletions srcs/engine/draw/scanline_rendering.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/11 19:10:01 by hluiz-ma #+# #+# */
/* Updated: 2025/01/22 21:44:40 by hluiz-ma ### ########.fr */
/* Updated: 2025/01/26 14:00:07 by hluiz-ma ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,20 +40,44 @@ void init_wall_drawing(t_wall *wall)
* wall->step;
}

void set_wall_tex_coords(t_wall *wall)
void set_wall_tex_coords(t_wall *wall)
{
if (wall->ray->side == 0)
wall->pos.x = wall->game->p1.pos.y + wall->ray->perp_wall_dist
* wall->ray->dir.y;
else
wall->pos.x = wall->game->p1.pos.x + wall->ray->perp_wall_dist
* wall->ray->dir.x;
wall->pos.x -= floor(wall->pos.x);
wall->tex.x = (int)(wall->pos.x * wall->texture->width);
if (wall->ray->side == 0 && wall->ray->dir.x < 0)
wall->tex.x = wall->texture->width - wall->tex.x - 1;
if (wall->ray->side == 1 && wall->ray->dir.y > 0)
wall->tex.x = wall->texture->width - wall->tex.x - 1;
if (wall->ray->side == 0)
wall->pos.x = wall->game->p1.pos.y + wall->ray->perp_wall_dist
* wall->ray->dir.y;
else
wall->pos.x = wall->game->p1.pos.x + wall->ray->perp_wall_dist
* wall->ray->dir.x;
wall->pos.x -= floor(wall->pos.x);
wall->tex.x = (int)(wall->pos.x * wall->texture->width);

// Adiciona a lógica de animação da porta
if (wall->ray->is_door)
{
t_door *door = find_door(wall->game, wall->ray->map_x, wall->ray->map_y);
if (door && door->state != DOOR_OPEN)
{
if (door->state == DOOR_OPENING)
{
double animation_progress = door->animation;
int offset = (int)(wall->texture->width * animation_progress);
wall->tex.x = (int)((wall->tex.x - offset) + wall->texture->width)
% wall->texture->width;
}
else if (door->state == DOOR_CLOSING)
{
double animation_progress = 1.0 - door->animation;
int offset = (int)(wall->texture->width * animation_progress);
wall->tex.x = (int)((wall->tex.x + offset) + wall->texture->width)
% wall->texture->width;
}
}
}

if (wall->ray->side == 0 && wall->ray->dir.x < 0)
wall->tex.x = wall->texture->width - wall->tex.x - 1;
if (wall->ray->side == 1 && wall->ray->dir.y > 0)
wall->tex.x = wall->texture->width - wall->tex.x - 1;
}

static void put_wall_pixel(t_wall *wall, t_vector_i pos)
Expand All @@ -74,19 +98,19 @@ void draw_wall_scanline(t_game *game, t_ray *ray, int x, t_scanline *buffer)
{
t_wall wall;
t_vector_i pos;
t_door *door;
// t_door *door;

wall.game = game;
wall.ray = ray;
wall.x = x;
wall.buffer = buffer;
init_wall_drawing(&wall);
if (ray->is_door)
/*if (ray->is_door)
{
door = find_door(game, ray->map_x, ray->map_y);
if (door && door->state != DOOR_OPEN)
process_door_texture(&wall, door, game);
}
}*/
pos.x = x;
pos.y = wall.start - 1;
while (++pos.y <= wall.end)
Expand Down
6 changes: 3 additions & 3 deletions srcs/engine/texture/texture_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/04 21:00:00 by hluiz-ma #+# #+# */
/* Updated: 2025/01/22 21:44:55 by hluiz-ma ### ########.fr */
/* Updated: 2025/01/26 13:59:39 by hluiz-ma ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -50,7 +50,7 @@ void update_weapon_animation(t_game *game)
else
game->p1.current_frame = 0;
}

/*
void process_door_texture(t_wall *wall, t_door *door, t_game *game)
{
double wallx;
Expand Down Expand Up @@ -78,4 +78,4 @@ void process_door_texture(t_wall *wall, t_door *door, t_game *game)
wall->tex.x = (int)((wall->tex.x + offset) + wall->texture->width)
% wall->texture->width;
}
}
}*/
16 changes: 15 additions & 1 deletion srcs/engine/texture/texture_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hluiz-ma <hluiz-ma@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 21:45:06 by hluiz-ma #+# #+# */
/* Updated: 2025/01/22 21:45:08 by hluiz-ma ### ########.fr */
/* Updated: 2025/01/26 14:02:27 by hluiz-ma ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,6 +37,20 @@ t_texture *texture_create(t_game *game, char *texture_path)

t_texture *get_wall_texture(t_ray *ray, t_game *game)
{
char tile = game->map.grid[ray->map_x][ray->map_y];

if (tile == '1')
{
// Verifica se tem parede adjacente
if ((ray->map_x > 0 && game->map.grid[ray->map_x - 1][ray->map_y] == 'D') ||
(ray->map_x < game->map.height - 1 && game->map.grid[ray->map_x + 1][ray->map_y] == 'D') ||
(ray->map_y > 0 && game->map.grid[ray->map_x][ray->map_y - 1] == 'D') ||
(ray->map_y < game->map.width - 1 && game->map.grid[ray->map_x][ray->map_y + 1] == 'D'))
{
return (&game->door_system->doorwall_texture);
}
}

if (ray->is_door)
return (&game->door_system->door_texture);
if (ray->side == 0)
Expand Down

0 comments on commit ef3498b

Please # to comment.