don't draw lines out of bounds
This commit is contained in:
parent
03223ca561
commit
5d19de8673
13
src/line.c
13
src/line.c
@ -6,13 +6,18 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 17:49:01 by qmennen #+# #+# */
|
||||
/* Updated: 2025/04/17 18:04:30 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/04/17 20:04:01 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "line.h"
|
||||
#include "MLX42.h"
|
||||
|
||||
static int check_bounds(t_screen *screen, t_vec2 *point)
|
||||
{
|
||||
return (point->x >= 0 && point->x < screen->width && point->y > 0 && point->y < screen->height);
|
||||
}
|
||||
|
||||
void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
||||
{
|
||||
int delta;
|
||||
@ -29,7 +34,8 @@ void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
||||
current = start;
|
||||
while (current.x <= end.x)
|
||||
{
|
||||
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||
if (check_bounds(screen, ¤t))
|
||||
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||
if (delta > 0)
|
||||
{
|
||||
current.y += yi;
|
||||
@ -56,7 +62,8 @@ void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
||||
current = start;
|
||||
while (current.y <= end.y)
|
||||
{
|
||||
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||
if (check_bounds(screen, ¤t))
|
||||
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||
if (delta > 0)
|
||||
{
|
||||
current.x += xi;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
|
||||
/* Updated: 2025/04/17 19:55:43 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/04/17 20:04:25 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,7 +24,7 @@ int player_create(t_game **game)
|
||||
player->pos.x = 20.f;
|
||||
player->pos.y = 20.f;
|
||||
player->angle = 0.f;
|
||||
player->speed = 35.f;
|
||||
player->speed = 80.f;
|
||||
player->fov = 90.f;
|
||||
(*game)->player = player;
|
||||
return (SUCCESS);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user