cub3d/src/render/render.c

68 lines
2.0 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* render.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */
/* Updated: 2025/05/07 11:38:34 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "render.h"
#include "MLX42.h"
int render_check_bounds(t_screen *screen, t_vec2 *point)
{
return (point->x >= 0
&& point->x < screen->width
&& point->y > 0
&& point->y < screen->height);
}
void render_tile(t_screen *screen, int x, int y, t_tile tile)
{
int i;
int xp;
int yp;
i = 0;
if (tile < 0)
return ;
while ((i++) < TILE_SIZE * TILE_SIZE)
{
xp = x + (i % TILE_SIZE);
yp = y + (i / TILE_SIZE);
if (xp < 0 || xp >= screen->width || yp < 0 || yp >= screen->height)
continue ;
if (tile == TILE_WALL)
mlx_put_pixel(screen->minimap, xp, yp, 0xA88132aa);
else if (tile == TILE_EMPTY || tile == TILE_PLAYER)
mlx_put_pixel(screen->minimap, xp, yp, 0xaaaaaa44);
}
}
void render_map(t_screen *screen, t_map *map)
{
int i;
int x;
int y;
i = 0;
while (i < map->width * map->height)
{
x = i % map->width;
y = i / map->width;
if (x < 0 || x >= map->width || y < 0 || y >= map->height)
continue ;
render_tile(screen, x * TILE_SIZE, y * TILE_SIZE, map->grid[y][x]);
i++;
}
}
void render_entities(t_game *game)
{
player_render(game->screen, game->player);
}