Compare commits
10 commits
ab4e7e7034
...
4a706f938c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4a706f938c | ||
![]() |
258957059d | ||
![]() |
735a8b335c | ||
![]() |
101018f0c1 | ||
![]() |
b44f4717df | ||
![]() |
217a220705 | ||
![]() |
6cd5b54918 | ||
![]() |
4bd265e213 | ||
![]() |
fe699a3cb4 | ||
![]() |
45521211b0 |
8
MLX42/.gitattributes
vendored
Normal file
8
MLX42/.gitattributes
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# See https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
|
||||||
|
|
||||||
|
# Set the default behavior, in case people don't have core.autocrlf set
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Declare files that will always have a certain EOL
|
||||||
|
*.sh text eol=lf
|
||||||
|
shaders/** text eol=lf
|
65
MLX42/.gitignore
vendored
Normal file
65
MLX42/.gitignore
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Linker output
|
||||||
|
*.ilk
|
||||||
|
*.map
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.dSYM/
|
||||||
|
*.su
|
||||||
|
*.idb
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# Kernel Module Compile Results
|
||||||
|
*.mod*
|
||||||
|
*.cmd
|
||||||
|
.tmp_versions/
|
||||||
|
modules.order
|
||||||
|
Module.symvers
|
||||||
|
Mkfile.old
|
||||||
|
dkms.conf
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
main.c
|
||||||
|
temp/
|
||||||
|
.vscode/
|
||||||
|
lib/glfw/
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Special shader files
|
||||||
|
mlx_*_shader.c
|
||||||
|
build/
|
||||||
|
main.c
|
||||||
|
test
|
4
Makefile
4
Makefile
|
@ -1,4 +1,4 @@
|
||||||
SRCS_GAME := main.c game/game.c game/init.c game/manage.c \
|
SRCS_GAME := main.c game/game.c game/init.c \
|
||||||
game/manage_keys.c game/raycasting.c game/dda.c game/draw.c game/utils.c
|
game/manage_keys.c game/raycasting.c game/dda.c game/draw.c game/utils.c
|
||||||
SRCS_MAP := parsing.c parsing_header.c parsing_header2.c parsing_meta.c parsing_body.c map.c parsing_body2.c parsing_header3.c
|
SRCS_MAP := parsing.c parsing_header.c parsing_header2.c parsing_meta.c parsing_body.c map.c parsing_body2.c parsing_header3.c
|
||||||
SRCS_MAP := $(addprefix map/, $(SRCS_MAP))
|
SRCS_MAP := $(addprefix map/, $(SRCS_MAP))
|
||||||
|
@ -9,7 +9,7 @@ SRCS := ${SRCS_MAP} \
|
||||||
OBJS := ${SRCS:.c=.o}
|
OBJS := ${SRCS:.c=.o}
|
||||||
CC := gcc
|
CC := gcc
|
||||||
LIBS := libftx/libftx.a MLX42/build/libmlx42.a -ldl -lglfw -lm
|
LIBS := libftx/libftx.a MLX42/build/libmlx42.a -ldl -lglfw -lm
|
||||||
CFLAGS := -g -Wall -Wextra -Werror #-Wno-conversion -Ofast -fsanitize=leak
|
CFLAGS := -g -Wall -Wextra -Werror -Wno-conversion -Ofast -fsanitize=leak
|
||||||
NAME := cub3D
|
NAME := cub3D
|
||||||
|
|
||||||
all: ${NAME}
|
all: ${NAME}
|
||||||
|
|
3
cube3D.h
3
cube3D.h
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/26 12:34:04 by erey-bet #+# #+# */
|
/* Created: 2023/04/26 12:34:04 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/05 11:37:41 by cchauvet ### ########.fr */
|
/* Updated: 2023/06/12 14:31:28 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
/*INIT*/
|
/*INIT*/
|
||||||
int start_game(t_map map);
|
int start_game(t_map map);
|
||||||
|
|
||||||
|
|
14
game/draw.c
14
game/draw.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/05/11 14:41:48 by erey-bet #+# #+# */
|
/* Created: 2023/05/11 14:41:48 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/11 16:05:42 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/15 12:52:23 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ void draw(t_game *game, t_dda *dda, int x)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
y = -1;
|
y = 0;
|
||||||
while (++y < dda->draw_start)
|
while (y < dda->draw_start && y >= 0 && y < HEIGHT)
|
||||||
mlx_put_pixel(game->window, x, y, game->map.color_bot);
|
mlx_put_pixel(game->window, x, y++, game->map.color_bot);
|
||||||
draw_texture(game, dda, x);
|
draw_texture(game, dda, x);
|
||||||
y = dda->draw_end - 1;
|
y = dda->draw_end;
|
||||||
while (++y < HEIGHT && y > 0)
|
while (y < HEIGHT && y >= 0)
|
||||||
mlx_put_pixel(game->window, x, y, game->map.color_top);
|
mlx_put_pixel(game->window, x, y++, game->map.color_top);
|
||||||
}
|
}
|
||||||
|
|
27
game/game.c
27
game/game.c
|
@ -6,13 +6,13 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
|
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/19 17:49:02 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/15 12:40:32 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
int destroy(t_game *game)
|
static void destroy(t_game *game)
|
||||||
{
|
{
|
||||||
if (game->textures[0])
|
if (game->textures[0])
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,15 @@ int destroy(t_game *game)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (1);
|
}
|
||||||
|
|
||||||
|
static void hook(void *param)
|
||||||
|
{
|
||||||
|
t_game *game;
|
||||||
|
|
||||||
|
game = param;
|
||||||
|
if (manage_keys(game))
|
||||||
|
raycasting(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
int start_game(t_map map)
|
int start_game(t_map map)
|
||||||
|
@ -40,20 +48,25 @@ int start_game(t_map map)
|
||||||
t_game game;
|
t_game game;
|
||||||
|
|
||||||
if (init(map, &game))
|
if (init(map, &game))
|
||||||
return (destroy(&game));
|
{
|
||||||
|
destroy(&game);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
|
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
|
||||||
if (!game.window)
|
if (!game.window)
|
||||||
{
|
{
|
||||||
mlx_terminate(game.mlx);
|
mlx_terminate(game.mlx);
|
||||||
return (destroy(&game));
|
destroy(&game);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
|
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
|
||||||
{
|
{
|
||||||
mlx_terminate(game.mlx);
|
mlx_terminate(game.mlx);
|
||||||
return (destroy(&game));
|
destroy(&game);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
raycasting(&game);
|
raycasting(&game);
|
||||||
mlx_key_hook(game.mlx, manage, &game);
|
mlx_loop_hook(game.mlx, &hook, &game);
|
||||||
mlx_loop(game.mlx);
|
mlx_loop(game.mlx);
|
||||||
destroy(&game);
|
destroy(&game);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */
|
/* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/11 15:28:26 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/13 14:19:18 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -79,11 +79,8 @@ typedef struct s_game
|
||||||
/* INIT */
|
/* INIT */
|
||||||
int init(t_map map, t_game *game);
|
int init(t_map map, t_game *game);
|
||||||
|
|
||||||
/* MANAGE */
|
|
||||||
void manage(mlx_key_data_t keydata, void *param);
|
|
||||||
|
|
||||||
/* KEYS */
|
/* KEYS */
|
||||||
int manage_keys(mlx_key_data_t keydata, t_game *game);
|
int manage_keys(t_game *game);
|
||||||
|
|
||||||
/* RAYCASTING */
|
/* RAYCASTING */
|
||||||
int raycasting(t_game *game);
|
int raycasting(t_game *game);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
|
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/06/01 13:28:15 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/16 17:48:34 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ int init(t_map map, t_game *game)
|
||||||
{
|
{
|
||||||
if (init_textures(map, game->textures))
|
if (init_textures(map, game->textures))
|
||||||
return (2);
|
return (2);
|
||||||
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true);
|
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili meli", false);
|
||||||
if (!game->mlx)
|
if (!game->mlx)
|
||||||
return (1);
|
return (1);
|
||||||
game->map = map;
|
game->map = map;
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
|
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/05 15:00:40 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/15 13:00:31 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
void rotate(t_ply *ply, bool right)
|
static int rotate(t_ply *ply, bool right)
|
||||||
{
|
{
|
||||||
double old_dir_x;
|
double old_dir_x;
|
||||||
double old_dir_y;
|
double old_dir_y;
|
||||||
|
@ -31,50 +31,49 @@ void rotate(t_ply *ply, bool right)
|
||||||
ply->dir_y = old_dir_x * sin(speed) + old_dir_y * cos(speed);
|
ply->dir_y = old_dir_x * sin(speed) + old_dir_y * cos(speed);
|
||||||
ply->pla_x = old_plane_x * cos(speed) - old_plane_y * sin(speed);
|
ply->pla_x = old_plane_x * cos(speed) - old_plane_y * sin(speed);
|
||||||
ply->pla_y = old_plane_x * sin(speed) + old_plane_y * cos(speed);
|
ply->pla_y = old_plane_x * sin(speed) + old_plane_y * cos(speed);
|
||||||
}
|
|
||||||
|
|
||||||
void movement(t_ply *ply, double x, double y)
|
|
||||||
{
|
|
||||||
ply->pos_x += x;
|
|
||||||
ply->pos_y += y;
|
|
||||||
}
|
|
||||||
|
|
||||||
int manage_movement(t_game *game, int key)
|
|
||||||
{
|
|
||||||
t_ply *ply;
|
|
||||||
|
|
||||||
ply = &game->ply;
|
|
||||||
if (key == MLX_KEY_W)
|
|
||||||
movement(ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED));
|
|
||||||
else if (key == MLX_KEY_S)
|
|
||||||
movement(ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED));
|
|
||||||
else if (key == MLX_KEY_D)
|
|
||||||
movement(ply, (ply->pla_x * MOVESPEED), (ply->pla_y * MOVESPEED));
|
|
||||||
else if (key == MLX_KEY_A)
|
|
||||||
movement(ply, -(ply->pla_x * MOVESPEED), -(ply->pla_y * MOVESPEED));
|
|
||||||
else if (key == MLX_KEY_L)
|
|
||||||
rotate(ply, true);
|
|
||||||
else if (key == MLX_KEY_J)
|
|
||||||
rotate(ply, false);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int manage_keys(mlx_key_data_t keys, t_game *game)
|
static int movement(t_ply *ply, double x, double y)
|
||||||
{
|
{
|
||||||
int is_moving;
|
ply->pos_x += x;
|
||||||
|
ply->pos_y += y;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int manage_movement(t_game *game)
|
||||||
|
{
|
||||||
|
t_ply *ply;
|
||||||
|
int is_moving;
|
||||||
|
|
||||||
|
ply = &game->ply;
|
||||||
is_moving = 0;
|
is_moving = 0;
|
||||||
if (keys.key == MLX_KEY_Q)
|
if (mlx_is_key_down(game->mlx, MLX_KEY_W))
|
||||||
|
is_moving = movement(ply, (ply->dir_x * MOVESPEED),
|
||||||
|
(ply->dir_y * MOVESPEED));
|
||||||
|
if (mlx_is_key_down(game->mlx, MLX_KEY_S))
|
||||||
|
is_moving = movement(ply, -(ply->dir_x * MOVESPEED),
|
||||||
|
-(ply->dir_y * MOVESPEED));
|
||||||
|
if (mlx_is_key_down(game->mlx, MLX_KEY_D))
|
||||||
|
is_moving = movement(ply, (ply->pla_x * MOVESPEED),
|
||||||
|
(ply->pla_y * MOVESPEED));
|
||||||
|
if (mlx_is_key_down(game->mlx, MLX_KEY_A))
|
||||||
|
is_moving = movement(ply, -(ply->pla_x * MOVESPEED),
|
||||||
|
-(ply->pla_y * MOVESPEED));
|
||||||
|
if (mlx_is_key_down(game->mlx, MLX_KEY_RIGHT)
|
||||||
|
|| mlx_is_key_down(game->mlx, MLX_KEY_L))
|
||||||
|
is_moving = rotate(ply, true);
|
||||||
|
else if (mlx_is_key_down(game->mlx, MLX_KEY_LEFT)
|
||||||
|
|| mlx_is_key_down(game->mlx, MLX_KEY_J))
|
||||||
|
is_moving = rotate(ply, false);
|
||||||
|
return (is_moving);
|
||||||
|
}
|
||||||
|
|
||||||
|
int manage_keys(t_game *game)
|
||||||
|
{
|
||||||
|
if (mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE))
|
||||||
mlx_close_window(game->mlx);
|
mlx_close_window(game->mlx);
|
||||||
else if (keys.key == MLX_KEY_W
|
if (manage_movement(game))
|
||||||
|| keys.key == MLX_KEY_S
|
|
||||||
|| keys.key == MLX_KEY_D
|
|
||||||
|| keys.key == MLX_KEY_A
|
|
||||||
|| keys.key == MLX_KEY_ESCAPE
|
|
||||||
|| keys.key == MLX_KEY_L
|
|
||||||
|| keys.key == MLX_KEY_J)
|
|
||||||
is_moving = manage_movement(game, keys.key);
|
|
||||||
if (is_moving)
|
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/05/11 14:19:16 by erey-bet #+# #+# */
|
/* Created: 2023/05/11 14:19:16 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/05/11 14:19:19 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/16 17:45:58 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y)
|
||||||
int get_texture_side(t_dda *dda)
|
int get_texture_side(t_dda *dda)
|
||||||
{
|
{
|
||||||
if (dda->side == 0 && dda->step_x < 0)
|
if (dda->side == 0 && dda->step_x < 0)
|
||||||
return (0);
|
return (3);
|
||||||
if (dda->side == 0 && dda->step_x > 0)
|
if (dda->side == 0 && dda->step_x > 0)
|
||||||
return (1);
|
return (1);
|
||||||
if (dda->side == 1 && dda->step_y < 0)
|
if (dda->side == 1 && dda->step_y < 0)
|
||||||
return (2);
|
return (2);
|
||||||
if (dda->side == 1 && dda->step_y > 0)
|
if (dda->side == 1 && dda->step_y > 0)
|
||||||
return (3);
|
return (0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||||
# Updated: 2023/05/03 11:01:55 by cchauvet ### ########.fr #
|
# Updated: 2023/06/16 16:32:17 by cchauvet ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|
||||||
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c ft_atoul.c ft_atoul_check.c
|
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c ft_atoul.c ft_atoul_check.c ft_count.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/03 11:02:33 by cchauvet ### ########.fr */
|
/* Updated: 2023/06/16 16:31:33 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -14,11 +14,12 @@
|
||||||
# define EXTRA_H
|
# define EXTRA_H
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include "../libft/libft.h"
|
# include "../libft/libft.h"
|
||||||
|
|
||||||
|
size_t ft_count(const char *str, char c);
|
||||||
unsigned long ft_atoul(const char str[]);
|
unsigned long ft_atoul(const char str[]);
|
||||||
int ft_atoul_check(const char str[]);
|
int ft_atoul_check(const char str[]);
|
||||||
size_t ft_tablen(const void **tab);
|
size_t ft_tablen(const void **tab);
|
||||||
|
@ -31,7 +32,8 @@ char *ft_strgen(char c, size_t len);
|
||||||
char *ft_strfjoin(char *s1, char *s2);
|
char *ft_strfjoin(char *s1, char *s2);
|
||||||
char *ft_strmerger(size_t arg_len, ...);
|
char *ft_strmerger(size_t arg_len, ...);
|
||||||
int ft_is_in(const char *str, char c);
|
int ft_is_in(const char *str, char c);
|
||||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
|
char **ft_tabrealloc(char **tab, size_t current_size,
|
||||||
|
size_t new_size);
|
||||||
char *ft_strndup(const char *src, size_t n);
|
char *ft_strndup(const char *src, size_t n);
|
||||||
ssize_t ft_strchri(char *str, char c);
|
ssize_t ft_strchri(char *str, char c);
|
||||||
int ft_contain_only_str(const char *str, const char *to_find);
|
int ft_contain_only_str(const char *str, const char *to_find);
|
||||||
|
|
|
@ -1,22 +1,29 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* manage.c :+: :+: :+: */
|
/* ft_count.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 12:52:14 by erey-bet #+# #+# */
|
/* Created: 2023/06/16 18:27:16 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/03 14:53:14 by erey-bet ### ########.fr */
|
/* Updated: 2023/06/16 16:29:22 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "game.h"
|
#include "./extra.h"
|
||||||
|
|
||||||
void manage(mlx_key_data_t keydata, void *param)
|
size_t ft_count(const char *str, char c)
|
||||||
{
|
{
|
||||||
t_game *game;
|
size_t i;
|
||||||
|
size_t out;
|
||||||
|
|
||||||
game = param;
|
i = 0;
|
||||||
if (manage_keys(keydata, game))
|
out = 0;
|
||||||
raycasting(game);
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (str[i] == c)
|
||||||
|
out++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (out);
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/05/16 14:51:13 by cchauvet #+# #+# */
|
/* Created: 2023/05/16 14:51:13 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/16 16:34:23 by cchauvet ### ########.fr */
|
/* Updated: 2023/06/16 14:39:18 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -67,3 +67,19 @@ int get_spawn_position(const char **body, double *spawn_x, double *spawn_y)
|
||||||
return (2);
|
return (2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int map_is_in_one_part(const char **body)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
|
||||||
|
y = ft_tablen((const void **) body) - 1;
|
||||||
|
while (body[y][0] == '\0')
|
||||||
|
y--;
|
||||||
|
while (y > 0)
|
||||||
|
{
|
||||||
|
if (body[y][0] == '\0')
|
||||||
|
return (1);
|
||||||
|
y--;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
|
@ -6,32 +6,16 @@
|
||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/05/16 16:30:55 by cchauvet #+# #+# */
|
/* Created: 2023/05/16 16:30:55 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/16 18:59:38 by cchauvet ### ########.fr */
|
/* Updated: 2023/06/16 14:47:22 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "parsing_private.h"
|
#include "parsing_private.h"
|
||||||
|
|
||||||
int map_is_in_one_part(const char **body)
|
|
||||||
{
|
|
||||||
int y;
|
|
||||||
|
|
||||||
y = ft_tablen((const void **) body) - 1;
|
|
||||||
while (body[y][0] == '\0' || ft_contain_only(body[y], ' '))
|
|
||||||
y--;
|
|
||||||
while (y > 0)
|
|
||||||
{
|
|
||||||
if (body[y][0] == '\0' || ft_contain_only(body[y], ' '))
|
|
||||||
return (1);
|
|
||||||
y--;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int map_surround(const char **body)
|
static int map_surround(const char **body)
|
||||||
{
|
{
|
||||||
int y;
|
size_t y;
|
||||||
int x;
|
size_t x;
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
while (body[y] != NULL)
|
while (body[y] != NULL)
|
||||||
|
@ -43,8 +27,8 @@ static int map_surround(const char **body)
|
||||||
{
|
{
|
||||||
if (body[y + 1] == NULL || (y == 0)
|
if (body[y + 1] == NULL || (y == 0)
|
||||||
|| (body[y][x + 1] == '\0') || (x == 0)
|
|| (body[y][x + 1] == '\0') || (x == 0)
|
||||||
|| (body[y + 1][x] == ' ' || body[y + 1][x] == '\0')
|
|| (x >= ft_strlen(body[y - 1])) || (body[y - 1][x] == ' ')
|
||||||
|| (body[y - 1][x] == ' ' || body[y - 1][x] == '\0')
|
|| (x >= ft_strlen(body[y + 1])) || (body[y + 1][x] == ' ')
|
||||||
|| (body[y][x - 1] == ' ' || body[y][x - 1] == '\0')
|
|| (body[y][x - 1] == ' ' || body[y][x - 1] == '\0')
|
||||||
|| (body[y][x + 1] == ' ' || body[y][x + 1] == '\0'))
|
|| (body[y][x + 1] == ' ' || body[y][x + 1] == '\0'))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */
|
/* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/16 19:02:08 by cchauvet ### ########.fr */
|
/* Updated: 2023/06/16 16:31:06 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -65,15 +65,14 @@ int set_color(long long *color, const char *key, const char *value)
|
||||||
ft_eprintf("map: %s redefinition", key);
|
ft_eprintf("map: %s redefinition", key);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
tab = ft_split(value, ',');
|
if (ft_count(value, ',') != 2)
|
||||||
if (tab == NULL)
|
|
||||||
return (1);
|
|
||||||
if (ft_tablen((const void **) tab) != 3)
|
|
||||||
{
|
{
|
||||||
ft_freer_tab_ultimate(1, tab);
|
|
||||||
ft_eprintf("map: invalid format %s %s", key, value);
|
ft_eprintf("map: invalid format %s %s", key, value);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
tab = ft_split(value, ',');
|
||||||
|
if (tab == NULL)
|
||||||
|
return (1);
|
||||||
*color = get_color((const char **) tab);
|
*color = get_color((const char **) tab);
|
||||||
ft_freer_tab_ultimate(1, tab);
|
ft_freer_tab_ultimate(1, tab);
|
||||||
return (*color == -1);
|
return (*color == -1);
|
||||||
|
|
|
@ -12,7 +12,7 @@ C 225,30,0
|
||||||
101100000111000000000000001
|
101100000111000000000000001
|
||||||
101100000111000000000000001 1111
|
101100000111000000000000001 1111
|
||||||
1011000001110000000000000011111100001
|
1011000001110000000000000011111100001
|
||||||
101100000111000000000000000000000W001
|
101100000111000000000000000000000N001
|
||||||
1011000001110000000000000011111100001
|
1011000001110000000000000011111100001
|
||||||
101100000111000000000000001 10101
|
101100000111000000000000001 10101
|
||||||
101100000111000000000000001 11111
|
101100000111000000000000001 11111
|
||||||
|
|
Loading…
Reference in a new issue