Compare commits
No commits in common. "master" and "etienne" have entirely different histories.
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
*.o
|
||||
cub3D
|
||||
*.swp
|
8
MLX42/.gitattributes
vendored
8
MLX42/.gitattributes
vendored
@ -1,8 +0,0 @@
|
||||
# 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
65
MLX42/.gitignore
vendored
@ -1,65 +0,0 @@
|
||||
# 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
|
23
Makefile
23
Makefile
@ -1,22 +1,17 @@
|
||||
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
|
||||
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 := ${SRCS_MAP} \
|
||||
${SRCS_GAME}
|
||||
|
||||
OBJS := ${SRCS:.c=.o}
|
||||
CC := gcc
|
||||
LIBS := libftx/libftx.a MLX42/build/libmlx42.a -ldl -lglfw -lm
|
||||
CFLAGS := -g -Wall -Wextra -Werror -Wno-conversion -Ofast -fsanitize=leak
|
||||
NAME := cub3D
|
||||
SRCS_GAME = main.c game/game.c game/init.c game/manage.c \
|
||||
game/manage_keys.c game/raycasting.c
|
||||
SRCS_PARSING =
|
||||
OBJS = ${SRCS_GAME:.c=.o} ${SRCS_PARSING:.c=.o}
|
||||
CC = clang
|
||||
LIBS = libftx/libftx.a MLX42/build/libmlx42.a -ldl -lglfw -lm
|
||||
CFLAGS = -g -Wall -Wextra -Werror
|
||||
NAME = cub3D
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
make -C libftx all
|
||||
${CC} -o ${NAME} ${OBJS} ${LIBS}
|
||||
${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${LIBS}
|
||||
|
||||
clean:
|
||||
make -C libftx clean
|
||||
|
@ -1,6 +0,0 @@
|
||||
# cub3D
|
||||
A raycasting game
|
||||
|
||||
## Screenshots
|
||||
|
||||
![](https://media.discordapp.net/attachments/501841539161522176/1158797264186245150/image.png?ex=651d8d8d&is=651c3c0d&hm=086a4b0f4e9071996776f71261f1a1031623051bae79756068c9a1fc3335a037&=&width=1185&height=612)
|
BIN
assets/blue.png
BIN
assets/blue.png
Binary file not shown.
Before Width: | Height: | Size: 640 B |
BIN
assets/green.png
BIN
assets/green.png
Binary file not shown.
Before Width: | Height: | Size: 631 B |
Binary file not shown.
Before Width: | Height: | Size: 642 B |
BIN
assets/red.png
BIN
assets/red.png
Binary file not shown.
Before Width: | Height: | Size: 631 B |
21
cube3D.h
21
cube3D.h
@ -6,15 +6,13 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 12:34:04 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/12 14:31:28 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/04/27 14:41:37 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CUBE3D_H
|
||||
# define CUBE3D_H
|
||||
|
||||
# include "map/parsing.h"
|
||||
# include "map/map.h"
|
||||
# include "libftx/libftx.h"
|
||||
# include <sys/types.h>
|
||||
# include "MLX42/include/MLX42/MLX42.h"
|
||||
@ -24,7 +22,22 @@
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
|
||||
// img: 0=Nord, 1=WEST, 2=SUD, 3=EAST;
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
char **map;
|
||||
size_t size_x;
|
||||
size_t size_y;
|
||||
void *img[4];
|
||||
long color_bot;
|
||||
long color_top;
|
||||
double ply_x;
|
||||
double ply_y;
|
||||
} t_map;
|
||||
|
||||
/*INIT*/
|
||||
int start_game(t_map map);
|
||||
t_map *map_parsing(char *path);
|
||||
int start_game(t_map *map);
|
||||
|
||||
#endif
|
||||
|
105
game/dda.c
105
game/dda.c
@ -1,105 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dda.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/02 15:49:00 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/05/11 16:22:58 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void init_dda(t_dda *dda, t_ply *ply, t_ray *ray)
|
||||
{
|
||||
dda->map_x = (int)ply->pos_x;
|
||||
dda->map_y = (int)ply->pos_y;
|
||||
if (ray->dir_x == 0)
|
||||
dda->delta_dist_x = 1e30;
|
||||
else
|
||||
dda->delta_dist_x = ft_abs(1 / ray->dir_x);
|
||||
if (ray->dir_y == 0)
|
||||
dda->delta_dist_y = 1e30;
|
||||
else
|
||||
dda->delta_dist_y = ft_abs(1 / ray->dir_y);
|
||||
dda->step_x = 1;
|
||||
dda->step_y = 1;
|
||||
if (ray->dir_x < 0)
|
||||
dda->step_x = -1;
|
||||
if (ray->dir_y < 0)
|
||||
dda->step_y = -1;
|
||||
if (ray->dir_x < 0)
|
||||
dda->side_dist_x = (ply->pos_x - dda->map_x) * dda->delta_dist_x;
|
||||
else
|
||||
dda->side_dist_x = (dda->map_x + 1.0 - ply->pos_x) * dda->delta_dist_x;
|
||||
if (ray->dir_y < 0)
|
||||
dda->side_dist_y = (ply->pos_y - dda->map_y) * dda->delta_dist_y;
|
||||
else
|
||||
dda->side_dist_y = (dda->map_y + 1.0 - ply->pos_y) * dda->delta_dist_y;
|
||||
dda->hit = 0;
|
||||
}
|
||||
|
||||
void loop_dda(t_game *game, t_dda *dda)
|
||||
{
|
||||
while (dda->hit == 0)
|
||||
{
|
||||
if (dda->side_dist_x < dda->side_dist_y)
|
||||
{
|
||||
dda->side_dist_x += dda->delta_dist_x;
|
||||
dda->map_x += dda->step_x;
|
||||
dda->side = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dda->side_dist_y += dda->delta_dist_y;
|
||||
dda->map_y += dda->step_y;
|
||||
dda->side = 1;
|
||||
}
|
||||
if (dda->map_x < 0 || dda->map_y < 0 || dda->map_y >= game->map.size_y
|
||||
|| dda->map_x >= (int)ft_strlen(game->map.map[dda->map_y]))
|
||||
{
|
||||
dda->perp_wall_dist = 1e30;
|
||||
return ;
|
||||
}
|
||||
else
|
||||
dda->perp_wall_dist = 0;
|
||||
if (game->map.map[dda->map_y][dda->map_x] == '1')
|
||||
dda->hit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ray_dda(t_dda *dda)
|
||||
{
|
||||
if (dda->perp_wall_dist != 1e30)
|
||||
{
|
||||
if (dda->side == 0)
|
||||
dda->perp_wall_dist = dda->side_dist_x - dda->delta_dist_x;
|
||||
else
|
||||
dda->perp_wall_dist = dda->side_dist_y - dda->delta_dist_y;
|
||||
if (dda->perp_wall_dist == 0)
|
||||
dda->perp_wall_dist = 1e30;
|
||||
}
|
||||
dda->line_height = (int)(HEIGHT / dda->perp_wall_dist);
|
||||
dda->draw_start = -(dda->line_height) / 2 + HEIGHT / 2;
|
||||
if (dda->draw_start < 0)
|
||||
dda->draw_start = 0;
|
||||
dda->draw_end = dda->line_height / 2 + HEIGHT / 2;
|
||||
if (dda->draw_end >= HEIGHT)
|
||||
dda->draw_end = HEIGHT - 1;
|
||||
}
|
||||
|
||||
void dda(t_game *game, int x)
|
||||
{
|
||||
t_dda dda;
|
||||
t_ray *ray;
|
||||
t_ply *ply;
|
||||
|
||||
ray = &game->ray;
|
||||
ply = &game->ply;
|
||||
init_dda(&dda, ply, ray);
|
||||
loop_dda(game, &dda);
|
||||
ray_dda(&dda);
|
||||
draw(game, &dda, x);
|
||||
}
|
54
game/draw.c
54
game/draw.c
@ -1,54 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 14:41:48 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/15 12:52:23 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void draw_texture(t_game *game, t_dda *dda, int x)
|
||||
{
|
||||
t_texture_draw tex;
|
||||
int y;
|
||||
|
||||
tex.texture = game->textures[get_texture_side(dda)];
|
||||
if (dda->side == 0)
|
||||
tex.wall_x = game->ply.pos_y + dda->perp_wall_dist * game->ray.dir_y;
|
||||
else
|
||||
tex.wall_x = game->ply.pos_x + dda->perp_wall_dist * game->ray.dir_x;
|
||||
tex.wall_x -= floor(tex.wall_x);
|
||||
tex.x = (int)(tex.wall_x * (double)tex.texture->width);
|
||||
if ((dda->side == 0 && game->ray.dir_x > 0)
|
||||
|| (dda->side == 1 && game->ray.dir_y < 0))
|
||||
tex.x = tex.texture->width - tex.x - 1;
|
||||
tex.step = 1.0 * tex.texture->height / dda->line_height;
|
||||
tex.pos = (dda->draw_start - game->window->height
|
||||
/ 2 + dda->line_height / 2) * tex.step;
|
||||
y = dda->draw_start;
|
||||
while (y < dda->draw_end && y < HEIGHT)
|
||||
{
|
||||
tex.y = (int)tex.pos & (tex.texture->height - 1);
|
||||
tex.pos += tex.step;
|
||||
mlx_put_pixel(game->window, x, y++,
|
||||
get_pixel_color(tex.texture, tex.x, tex.y));
|
||||
}
|
||||
}
|
||||
|
||||
void draw(t_game *game, t_dda *dda, int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
y = 0;
|
||||
while (y < dda->draw_start && y >= 0 && y < HEIGHT)
|
||||
mlx_put_pixel(game->window, x, y++, game->map.color_bot);
|
||||
draw_texture(game, dda, x);
|
||||
y = dda->draw_end;
|
||||
while (y < HEIGHT && y >= 0)
|
||||
mlx_put_pixel(game->window, x, y++, game->map.color_top);
|
||||
}
|
55
game/game.c
55
game/game.c
@ -6,68 +6,33 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/15 12:40:32 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/28 16:23:57 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
static void destroy(t_game *game)
|
||||
{
|
||||
if (game->textures[0])
|
||||
{
|
||||
mlx_delete_texture(game->textures[0]);
|
||||
if (game->textures[1])
|
||||
{
|
||||
mlx_delete_texture(game->textures[1]);
|
||||
if (game->textures[2])
|
||||
{
|
||||
mlx_delete_texture(game->textures[2]);
|
||||
if (game->textures[3])
|
||||
{
|
||||
mlx_delete_texture(game->textures[3]);
|
||||
if (game->mlx)
|
||||
mlx_terminate(game->mlx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
t_game game;
|
||||
|
||||
if (init(map, &game))
|
||||
{
|
||||
destroy(&game);
|
||||
return (1);
|
||||
}
|
||||
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
|
||||
if (!game.window)
|
||||
{
|
||||
mlx_terminate(game.mlx);
|
||||
destroy(&game);
|
||||
return (1);
|
||||
mlx_close_window(game.mlx);
|
||||
return(1);
|
||||
}
|
||||
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
|
||||
{
|
||||
mlx_terminate(game.mlx);
|
||||
destroy(&game);
|
||||
return (1);
|
||||
mlx_close_window(game.mlx);
|
||||
return(1);
|
||||
}
|
||||
raycasting(&game);
|
||||
mlx_loop_hook(game.mlx, &hook, &game);
|
||||
|
||||
mlx_key_hook(game.mlx, manage, &game);
|
||||
mlx_loop(game.mlx);
|
||||
destroy(&game);
|
||||
mlx_terminate(game.mlx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
68
game/game.h
68
game/game.h
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/13 14:19:18 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/05/02 15:32:43 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,12 +15,9 @@
|
||||
|
||||
# include "../cube3D.h"
|
||||
# include <math.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
# define WIDTH 1920
|
||||
# define HEIGHT 1080
|
||||
# define MOVESPEED 0.10
|
||||
# define ROTATIONSPEED 60
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
@ -34,66 +31,29 @@ typedef struct s_player
|
||||
|
||||
typedef struct s_raycast
|
||||
{
|
||||
double dir_x;
|
||||
double dir_y;
|
||||
double x;
|
||||
double y;
|
||||
} t_ray;
|
||||
|
||||
typedef struct s_dda
|
||||
{
|
||||
int map_x;
|
||||
int map_y;
|
||||
double side_dist_x;
|
||||
double side_dist_y;
|
||||
double delta_dist_x;
|
||||
double delta_dist_y;
|
||||
double perp_wall_dist;
|
||||
int step_x;
|
||||
int step_y;
|
||||
int hit;
|
||||
int side;
|
||||
int line_height;
|
||||
int draw_start;
|
||||
int draw_end;
|
||||
} t_dda;
|
||||
|
||||
typedef struct s_texture_draw
|
||||
{
|
||||
mlx_texture_t *texture;
|
||||
double wall_x;
|
||||
int x;
|
||||
int y;
|
||||
double pos;
|
||||
double step;
|
||||
} t_texture_draw;
|
||||
|
||||
typedef struct s_game
|
||||
{
|
||||
mlx_t *mlx;
|
||||
mlx_image_t *window;
|
||||
mlx_texture_t *textures[4];
|
||||
t_ply ply;
|
||||
t_map map;
|
||||
t_ray ray;
|
||||
mlx_t *mlx;
|
||||
mlx_image_t *window;
|
||||
t_ply *ply;
|
||||
t_map *map;
|
||||
t_ray *ray;
|
||||
} t_game;
|
||||
|
||||
/* INIT */
|
||||
int init(t_map map, t_game *game);
|
||||
t_game *init(t_map *map);
|
||||
|
||||
/* MANAGE */
|
||||
void manage(mlx_key_data_t keydata, void *param);
|
||||
|
||||
/* KEYS */
|
||||
int manage_keys(t_game *game);
|
||||
int manage_keys(mlx_key_data_t keydata, t_game *game);
|
||||
|
||||
/* RAYCASTING */
|
||||
int raycasting(t_game *game);
|
||||
int raycasting(t_game *game);
|
||||
|
||||
/* DDA ALGO */
|
||||
void dda(t_game *game, int x);
|
||||
|
||||
/* UTILS */
|
||||
double ft_abs(double nb);
|
||||
unsigned int get_rgba(int r, int g, int b, int a);
|
||||
uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y);
|
||||
int get_texture_side(t_dda *dda);
|
||||
|
||||
/* DRAW */
|
||||
void draw(t_game *game, t_dda *dda, int x);
|
||||
#endif
|
||||
|
58
game/init.c
58
game/init.c
@ -6,62 +6,32 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/16 17:48:34 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/05/02 15:18:05 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void init_ply(t_map map, t_ply *ply)
|
||||
void init_ply(t_map *map, t_ply *ply)
|
||||
{
|
||||
ply->pos_x = map.ply_x + 0.5;
|
||||
ply->pos_y = map.ply_y + 0.5;
|
||||
ply->dir_x = 0.0;
|
||||
ply->dir_y = 0.0;
|
||||
if (map.direction == 'N')
|
||||
ply->dir_y = -1.0;
|
||||
if (map.direction == 'S')
|
||||
ply->dir_y = 1.0;
|
||||
if (map.direction == 'E')
|
||||
ply->dir_x = 1.0;
|
||||
if (map.direction == 'W')
|
||||
ply->dir_x = -1.0;
|
||||
ply->pla_x = -(ply->dir_y) * 0.66;
|
||||
ply->pla_y = (ply->dir_x) * 0.66;
|
||||
ply->pos_x = map->ply_x;
|
||||
ply->pos_y = map->ply_y;
|
||||
}
|
||||
|
||||
void init_ray(t_ray *ray)
|
||||
{
|
||||
ray->dir_x = 0;
|
||||
ray->dir_y = 0;
|
||||
ray->x = 0;
|
||||
ray->y = 0;
|
||||
}
|
||||
|
||||
int init_textures(t_map map, mlx_texture_t *textures[4])
|
||||
void init(t_map *map, t_game &game)
|
||||
{
|
||||
textures[0] = mlx_load_png(map.img_path[0]);
|
||||
if (!textures[0])
|
||||
return (1);
|
||||
textures[1] = mlx_load_png(map.img_path[1]);
|
||||
if (!textures[1])
|
||||
return (1);
|
||||
textures[2] = mlx_load_png(map.img_path[2]);
|
||||
if (!textures[2])
|
||||
return (1);
|
||||
textures[3] = mlx_load_png(map.img_path[3]);
|
||||
if (!textures[3])
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
t_ply ply;
|
||||
t_ray ray;
|
||||
|
||||
int init(t_map map, t_game *game)
|
||||
{
|
||||
if (init_textures(map, game->textures))
|
||||
return (2);
|
||||
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili meli", false);
|
||||
if (!game->mlx)
|
||||
return (1);
|
||||
game->map = map;
|
||||
init_ply(map, &game->ply);
|
||||
init_ray(&game->ray);
|
||||
return (0);
|
||||
game.mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true);
|
||||
if (!game.mlx)
|
||||
return (NULL);
|
||||
game.map = map;
|
||||
init_ply(map, &ply);
|
||||
}
|
||||
|
@ -1,23 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tablen.c :+: :+: :+: */
|
||||
/* manage.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 12:12:19 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/28 12:58:24 by cchauvet ### ########.fr */
|
||||
/* Created: 2023/04/27 12:52:14 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/04/27 14:31:50 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./extra.h"
|
||||
#include "game.h"
|
||||
|
||||
size_t ft_tablen(const void **tab)
|
||||
void manage(mlx_key_data_t keydata, void *param)
|
||||
{
|
||||
size_t i;
|
||||
t_game *game;
|
||||
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
i++;
|
||||
return (i);
|
||||
game = param;
|
||||
if (manage_keys(keydata, game))
|
||||
raycasting(game);
|
||||
}
|
@ -6,74 +6,42 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/15 13:00:31 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/28 12:50:21 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
static int rotate(t_ply *ply, bool right)
|
||||
int movement(t_ply *ply, int key)
|
||||
{
|
||||
double old_dir_x;
|
||||
double old_dir_y;
|
||||
double old_plane_x;
|
||||
double old_plane_y;
|
||||
double speed;
|
||||
|
||||
old_dir_x = ply->dir_x;
|
||||
old_dir_y = ply->dir_y;
|
||||
old_plane_x = ply->pla_x;
|
||||
old_plane_y = ply->pla_y;
|
||||
speed = ROTATIONSPEED * (M_1_PI / 180.0);
|
||||
if (!right)
|
||||
speed = -speed;
|
||||
ply->dir_x = old_dir_x * cos(speed) - old_dir_y * sin(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_y = old_plane_x * sin(speed) + old_plane_y * cos(speed);
|
||||
else if (key == MLX_KEY_W)
|
||||
ply->pos_y -= 0.1;
|
||||
else if (key == MLX_KEY_S)
|
||||
ply->pos_y += 0.1;
|
||||
else if (key == MLX_KEY_D)
|
||||
ply->pos_x += 0.1;
|
||||
else if (key == MLX_KEY_A)
|
||||
ply->pos_x -= 0.1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int movement(t_ply *ply, double x, double y)
|
||||
int manage_keys(mlx_key_data_t keys, t_game *game)
|
||||
{
|
||||
ply->pos_x += x;
|
||||
ply->pos_y += y;
|
||||
return (1);
|
||||
}
|
||||
int is_moving;
|
||||
|
||||
int manage_movement(t_game *game)
|
||||
{
|
||||
t_ply *ply;
|
||||
int is_moving;
|
||||
|
||||
ply = &game->ply;
|
||||
is_moving = 0;
|
||||
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))
|
||||
if (keys.key == MLX_KEY_ESCAPE)
|
||||
mlx_close_window(game->mlx);
|
||||
if (manage_movement(game))
|
||||
else if (keys.key == MLX_KEY_W
|
||||
|| keys.key == MLX_KEY_S
|
||||
|| keys.key == MLX_KEY_D
|
||||
|| keys.key == MLX_KEY_A)
|
||||
is_moving = movement(game->ply, keys.key);
|
||||
/*else if (key.key == MLX_KEY_RIGHT)
|
||||
game->ply->direc += 0.1;
|
||||
else if (key.key == MLX_KEY_LEFT)
|
||||
game->ply->direc -= 0.1;*/
|
||||
if (is_moving)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
@ -6,29 +6,34 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/27 14:30:29 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/05/05 13:59:57 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/05/02 13:12:15 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
int raycasting(t_game *game)
|
||||
int ray(t_game *game)
|
||||
{
|
||||
t_ply *p;
|
||||
t_ray *ray;
|
||||
double camera;
|
||||
int x;
|
||||
int i;
|
||||
|
||||
x = 0;
|
||||
p = &game->ply;
|
||||
ray = &game->ray;
|
||||
while (x < WIDTH)
|
||||
i = 0;
|
||||
p = game->ply;
|
||||
ray = game->ray;
|
||||
while (i <= WIDTH)
|
||||
{
|
||||
camera = 2 * x / (double)WIDTH - 1;
|
||||
ray->dir_x = p->dir_x + p->pla_x * camera;
|
||||
ray->dir_y = p->dir_y + p->pla_y * camera;
|
||||
dda(game, x);
|
||||
x++;
|
||||
camera = 2 * i / (double)WIDTH - 1; //x-coordinate in camera space
|
||||
ray->x = p->dir_x + p->pla_x * camera;
|
||||
ray->y = p->dir_y + p->pla_y * camera;
|
||||
}
|
||||
}
|
||||
|
||||
int raycasting(t_game *game)
|
||||
{
|
||||
(void)game;
|
||||
ray(game)
|
||||
write(1, "raycasting...\n", 14);
|
||||
return (0);
|
||||
}
|
||||
|
50
game/utils.c
50
game/utils.c
@ -1,50 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 14:19:16 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/16 17:45:58 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
double ft_abs(double nb)
|
||||
{
|
||||
if (nb < 0)
|
||||
return (-nb);
|
||||
return (nb);
|
||||
}
|
||||
|
||||
unsigned int get_rgba(int r, int g, int b, int a)
|
||||
{
|
||||
return (r << 24 | g << 16 | b << 8 | a);
|
||||
}
|
||||
|
||||
static uint32_t switch_color_bytes(uint32_t color)
|
||||
{
|
||||
return (((color & 0xff) << 24) | (((color >> 8) & 0xff) << 16)
|
||||
| (((color >> 16) & 0xff) << 8) | color >> 24);
|
||||
}
|
||||
|
||||
uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y)
|
||||
{
|
||||
return (switch_color_bytes(*(uint32_t *)(texture->pixels
|
||||
+ (y * texture->width + x) * texture->bytes_per_pixel)));
|
||||
}
|
||||
|
||||
int get_texture_side(t_dda *dda)
|
||||
{
|
||||
if (dda->side == 0 && dda->step_x < 0)
|
||||
return (3);
|
||||
if (dda->side == 0 && dda->step_x > 0)
|
||||
return (1);
|
||||
if (dda->side == 1 && dda->step_y < 0)
|
||||
return (2);
|
||||
if (dda->side == 1 && dda->step_y > 0)
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
@ -6,13 +6,13 @@
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/06/16 16:32:17 by cchauvet ### ########.fr #
|
||||
# Updated: 2023/01/19 12:55:43 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
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 ft_count.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
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/06/16 16:31:33 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/19 17:35:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,33 +14,27 @@
|
||||
# define EXTRA_H
|
||||
# include <stdarg.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include "../libft/libft.h"
|
||||
|
||||
size_t ft_count(const char *str, char c);
|
||||
unsigned long ft_atoul(const char str[]);
|
||||
int ft_atoul_check(const char str[]);
|
||||
size_t ft_tablen(const void **tab);
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
char *get_next_line(int fd);
|
||||
size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_is_in(const char *str, char c);
|
||||
char **ft_tabrealloc(char **tab, size_t current_size,
|
||||
size_t new_size);
|
||||
char *ft_strndup(const char *src, size_t n);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
int ft_contain_only_str(const char *str, const char *to_find);
|
||||
int ft_contain_only(const char *str, char c);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
void ft_swap(void *a, void *b);
|
||||
void ft_swap_int(int *a, int *b);
|
||||
void ft_swap_char(char *a, char *b);
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
char *get_next_line(int fd);
|
||||
size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_is_in(char *str, char c);
|
||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
|
||||
char *ft_strndup(const char *src, size_t n);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
int ft_contain_only_str(char *str, char *to_find);
|
||||
int ft_contain_only(char *str, char c);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
void ft_swap(void *a, void *b);
|
||||
void ft_swap_int(int *a, int *b);
|
||||
void ft_swap_char(char *a, char *b);
|
||||
|
||||
#endif
|
||||
|
@ -1,38 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoul.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/03 11:03:04 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
unsigned long ft_atoul(const char *str)
|
||||
{
|
||||
unsigned long out;
|
||||
char sign;
|
||||
size_t i;
|
||||
|
||||
sign = 1;
|
||||
i = 0;
|
||||
while (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
sign = -1;
|
||||
if (str[i] == '+')
|
||||
sign = 1;
|
||||
i++;
|
||||
}
|
||||
out = 0;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
out = out * 10 + str[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (out * sign);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoul_check.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/02 13:15:12 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./extra.h"
|
||||
|
||||
int ft_atoul_check(const char str[])
|
||||
{
|
||||
size_t i;
|
||||
unsigned long num;
|
||||
|
||||
num = 0;
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] > '9' || str[i] < '0')
|
||||
return (0);
|
||||
if (num > num * 10 + str[i] - '0')
|
||||
return (0);
|
||||
num = num * 10 + str[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/12 16:28:20 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/26 13:07:06 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/12 16:31:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_contain_only(const char *str, char c)
|
||||
int ft_contain_only(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -26,7 +26,7 @@ int ft_contain_only(const char *str, char c)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_contain_only_str(const char *str, const char *to_find)
|
||||
int ft_contain_only_str(char *str, char *to_find)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_count.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/16 18:27:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/06/16 16:29:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./extra.h"
|
||||
|
||||
size_t ft_count(const char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
size_t out;
|
||||
|
||||
i = 0;
|
||||
out = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == c)
|
||||
out++;
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 20:29:53 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/26 13:07:30 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/08 12:15:08 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_is_in(const char *str, char c)
|
||||
int ft_is_in(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 19:20:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/26 12:23:52 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 13:20:20 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/12/14 15:49:18 by cchauvet #+# #+# #
|
||||
# Updated: 2023/06/01 13:23:51 by erey-bet ### ########.fr #
|
||||
# Updated: 2023/01/05 19:22:40 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -16,7 +16,7 @@ OBJS = ${SRCS:.c=.o}
|
||||
|
||||
NAME = get_next_line.a
|
||||
|
||||
CFLAGS = -fPIE -Wall -Werror -Wextra -g
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
CC = clang
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/02 13:17:30 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 13:28:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,9 +16,7 @@
|
||||
# include <unistd.h>
|
||||
# include <stdarg.h>
|
||||
# include "./libft/libft.h"
|
||||
# include "./extra/extra.h"
|
||||
|
||||
size_t ft_tablen(const void **tab);
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_eprintf(const char *format, ...);
|
||||
@ -29,17 +27,54 @@ size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
int ft_is_in(const char *str, char c);
|
||||
int ft_is_in(char *str, char c);
|
||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
|
||||
int ft_contain_only_str(const char *str, const char *to_find);
|
||||
int ft_contain_only(const char *str, char c);
|
||||
int ft_contain_only_str(char *str, char *to_find);
|
||||
int ft_contain_only(char *str, char c);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
char *ft_strndup(const char *src, size_t n);
|
||||
void ft_swap(void *a, void *b);
|
||||
void ft_swap_int(int *a, int *b);
|
||||
void ft_swap_char(char *a, char *b);
|
||||
|
||||
/* void *ft_cancel(void **tab, size_t len); */
|
||||
/* int ft_atoi(const char *nptr); */
|
||||
/* void ft_bzero(void *s, size_t n); */
|
||||
/* void *ft_calloc(size_t nmemb, size_t size); */
|
||||
/* int ft_isalnum(int c); */
|
||||
/* int ft_isalpha(int c); */
|
||||
/* int ft_isascii(int c); */
|
||||
/* int ft_isdigit(int c); */
|
||||
/* int ft_isprint(int c); */
|
||||
/* void *ft_memchr(const void *s, int c, size_t n); */
|
||||
/* int ft_memcmp(const void *s1, const void *s2, size_t n); */
|
||||
/* void *ft_memcpy(void *dest, const void *src, size_t n); */
|
||||
/* void *ft_memmove(void *dest, const void *src, size_t n); */
|
||||
/* void *ft_memset(void *s, int c, size_t n); */
|
||||
/* char *ft_strchr(const char *s, int c); */
|
||||
/* char *ft_strdup(const char *s); */
|
||||
/* size_t ft_strlcat(char *dst, const char *src, size_t size); */
|
||||
/* size_t ft_strlcpy(char *dst, const char *src, size_t size); */
|
||||
/* size_t ft_strlen(const char *s); */
|
||||
/* int ft_strncmp(const char *s1, const char *s2, size_t n); */
|
||||
/* char *ft_strnstr(const char *big, const char *little, size_t len); */
|
||||
/* char *ft_strrchr(const char *s, int c); */
|
||||
/* int ft_tolower(int c); */
|
||||
/* int ft_toupper(int c); */
|
||||
|
||||
/* char *ft_substr(char const *s, unsigned int start, size_t len); */
|
||||
/* char *ft_strjoin(char const *s1, char const *s2); */
|
||||
/* char *ft_strtrim(char const *s1, char const *set); */
|
||||
/* char **ft_split(char const *s, char c); */
|
||||
/* char *ft_itoa(int n); */
|
||||
/* char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); */
|
||||
/* void ft_striteri(char *s, void (*f)(unsigned int, char*)); */
|
||||
/* void ft_putchar_fd(char c, int fd); */
|
||||
/* void ft_putstr_fd(char *s, int fd); */
|
||||
/* void ft_putendl_fd(char *s, int fd); */
|
||||
/* void ft_putnbr_fd(int n, int fd); */
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/06/01 13:24:02 by erey-bet ### ########.fr #
|
||||
# Updated: 2023/02/01 16:19:19 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -18,7 +18,7 @@ OBJS = ${SRCS:.c=.o}
|
||||
|
||||
NAME = ft_printf.a
|
||||
|
||||
CFLAG = -fPIE -Wall -Werror -Wextra -g
|
||||
CFLAG = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c
|
||||
${CC} ${CFLAG} -c -o $@ $<
|
||||
|
29
main.c
29
main.c
@ -6,28 +6,41 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 12:44:55 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/05/19 17:03:29 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/27 14:43:10 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cube3D.h"
|
||||
#include "map/map.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_map map;
|
||||
t_map *map;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
ft_eprintf("No argument");
|
||||
printf("No argument");
|
||||
return (1);
|
||||
}
|
||||
if (map_parsing(argv[1], &map)
|
||||
|| start_game(map))
|
||||
/*map = map_parsing(argv[1]);
|
||||
if (!map)
|
||||
{
|
||||
map_freer(&map);
|
||||
return (2);
|
||||
}*/
|
||||
(void)argv;
|
||||
map = malloc(sizeof(t_map));
|
||||
map->map = malloc(sizeof(char *) * 5);
|
||||
map->map[0] = "11111";
|
||||
map->map[1] = "10001";
|
||||
map->map[2] = "10S01";
|
||||
map->map[3] = "10101";
|
||||
map->map[4] = "11111";
|
||||
map->size_x = 5;
|
||||
map->size_y = 5;
|
||||
map->ply_x = 3;
|
||||
map->ply_y = 3;
|
||||
if (start_game(map))
|
||||
{
|
||||
return (3);
|
||||
}
|
||||
map_freer(&map);
|
||||
return (0);
|
||||
}
|
||||
|
28
map/map.c
28
map/map.c
@ -1,28 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:50:15 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 14:50:16 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "map.h"
|
||||
#include "./parsing_private.h"
|
||||
|
||||
void map_freer(t_map *map)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
ft_freer_tab_ultimate(1, map->map);
|
||||
i = 0;
|
||||
while (i < 4)
|
||||
{
|
||||
if (map->img_path[i] != NULL)
|
||||
free(map->img_path[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
34
map/map.h
34
map/map.h
@ -1,34 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:50:41 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 14:50:42 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MAP_H
|
||||
# define MAP_H
|
||||
# include<sys/types.h>
|
||||
|
||||
// img: 0=Nord, 1=WEST, 2=SOUTH, 3=EAST;
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
char **map;
|
||||
char *img_path[4];
|
||||
long long color_bot;
|
||||
long long color_top;
|
||||
int size_x;
|
||||
int size_y;
|
||||
double ply_x;
|
||||
double ply_y;
|
||||
char direction;
|
||||
} t_map;
|
||||
|
||||
void map_freer(t_map *map);
|
||||
|
||||
#endif
|
110
map/parsing.c
110
map/parsing.c
@ -1,110 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:53:00 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 14:54:02 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parsing_private.h"
|
||||
#include "map.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static ssize_t get_nb_line(const char *path)
|
||||
{
|
||||
int fd;
|
||||
char readed[1];
|
||||
size_t i;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (-1);
|
||||
i = 1;
|
||||
while (read(fd, readed, 1))
|
||||
{
|
||||
if (readed[0] == '\n')
|
||||
i++;
|
||||
}
|
||||
close(fd);
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char **read_map(const char *path)
|
||||
{
|
||||
int fd;
|
||||
size_t i;
|
||||
char **map;
|
||||
|
||||
map = malloc(sizeof(char *) * (get_nb_line(path) + 1));
|
||||
if (map == NULL)
|
||||
return (NULL);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
free(map);
|
||||
return (NULL);
|
||||
}
|
||||
i = 0;
|
||||
map[i] = get_next_line(fd);
|
||||
while (map[i] != NULL)
|
||||
{
|
||||
map[i][ft_strlen(map[i]) - 1] = '\0';
|
||||
i++;
|
||||
map[i] = get_next_line(fd);
|
||||
}
|
||||
close(fd);
|
||||
return (map);
|
||||
}
|
||||
|
||||
void header_freer(char ***header)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
while (header[i] != NULL)
|
||||
{
|
||||
j = 0;
|
||||
while (header[i][j] != NULL)
|
||||
{
|
||||
free(header[i][j]);
|
||||
j++;
|
||||
}
|
||||
free(header[i]);
|
||||
i++;
|
||||
}
|
||||
free(header);
|
||||
}
|
||||
|
||||
int map_parsing(const char *path, t_map *map)
|
||||
{
|
||||
char **file_content;
|
||||
char ***header;
|
||||
size_t header_size;
|
||||
|
||||
ft_bzero(map, sizeof(t_map));
|
||||
if (parsing_meta(path))
|
||||
return (1);
|
||||
file_content = read_map(path);
|
||||
if (file_content == NULL)
|
||||
{
|
||||
ft_eprintf("map: file error");
|
||||
return (1);
|
||||
}
|
||||
header = get_header((const char **) file_content, &header_size);
|
||||
if (header_is_valid(header, map) == 1)
|
||||
{
|
||||
header_freer(header);
|
||||
ft_freer_tab_ultimate(1, file_content);
|
||||
return (1);
|
||||
}
|
||||
header_freer(header);
|
||||
map->map = get_body((const char **) file_content, header_size);
|
||||
ft_freer_tab_ultimate(1, file_content);
|
||||
return (body_is_valid(map) == 0);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:54:09 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 14:54:10 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSING_H
|
||||
# define PARSING_H
|
||||
# include "map.h"
|
||||
|
||||
int map_parsing(const char *path, t_map *map);
|
||||
|
||||
#endif
|
@ -1,85 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_body.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 14:51:13 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/06/16 14:39:18 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing_private.h"
|
||||
|
||||
char **get_body(const char **file_content, size_t header_size)
|
||||
{
|
||||
char **body;
|
||||
int i;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
while (file_content[header_size + len] != NULL)
|
||||
len++;
|
||||
body = malloc((len + 1) * sizeof(char *));
|
||||
if (body == NULL)
|
||||
return (NULL);
|
||||
body[len] = NULL;
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
body[i] = ft_strdup(file_content[header_size + i]);
|
||||
if (body[i] == NULL)
|
||||
{
|
||||
ft_cancel((void **) body, i);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (body);
|
||||
}
|
||||
|
||||
int get_spawn_position(const char **body, double *spawn_x, double *spawn_y)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
*spawn_x = -1;
|
||||
*spawn_y = -1;
|
||||
y = 0;
|
||||
while (body[y] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (body[y][x] != '\0')
|
||||
{
|
||||
if (ft_is_in("NSEW", body[y][x]))
|
||||
{
|
||||
if (*spawn_x != -1)
|
||||
return (1);
|
||||
*spawn_x = x;
|
||||
*spawn_y = y;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
if (*spawn_x == -1)
|
||||
return (2);
|
||||
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);
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_body2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 16:30:55 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/06/16 14:47:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing_private.h"
|
||||
|
||||
static int map_surround(const char **body)
|
||||
{
|
||||
size_t y;
|
||||
size_t x;
|
||||
|
||||
y = 0;
|
||||
while (body[y] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (body[y][x] != '\0')
|
||||
{
|
||||
if (body[y][x] == '0')
|
||||
{
|
||||
if (body[y + 1] == NULL || (y == 0)
|
||||
|| (body[y][x + 1] == '\0') || (x == 0)
|
||||
|| (x >= ft_strlen(body[y - 1])) || (body[y - 1][x] == ' ')
|
||||
|| (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'))
|
||||
return (1);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int body_contain_normal_char(const char **body)
|
||||
{
|
||||
unsigned int y;
|
||||
unsigned int x;
|
||||
|
||||
y = 0;
|
||||
while (body[y] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (body[y][x] != '\0')
|
||||
{
|
||||
if (!ft_is_in(" 01NEWS", body[y][x]))
|
||||
{
|
||||
ft_eprintf("map: %c: invalid character at rows=%u, colums=%u",
|
||||
body[y][x], y, x);
|
||||
return (0);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void get_size(const char **body, t_map *map)
|
||||
{
|
||||
int y;
|
||||
int x;
|
||||
|
||||
map->size_x = 0;
|
||||
y = 0;
|
||||
while (body[y] != NULL)
|
||||
{
|
||||
x = ft_strlen(body[y]);
|
||||
if (x > map->size_x)
|
||||
map->size_x = x;
|
||||
y++;
|
||||
}
|
||||
map->size_y = y;
|
||||
}
|
||||
|
||||
int body_is_valid2(t_map *map)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = get_spawn_position((const char **) map->map,
|
||||
&map->ply_x, &map->ply_y);
|
||||
if (error == 1)
|
||||
{
|
||||
ft_eprintf("map: spawn position: multiple definition");
|
||||
return (0);
|
||||
}
|
||||
else if (error == 2)
|
||||
{
|
||||
ft_eprintf("map: spawn position: not defined");
|
||||
return (0);
|
||||
}
|
||||
map->direction = map->map[(int) map->ply_y][(int) map->ply_x];
|
||||
map->map[(int) map->ply_y][(int) map->ply_x] = '0';
|
||||
error = map_is_in_one_part((const char **)map->map);
|
||||
if (error)
|
||||
{
|
||||
ft_eprintf("map: splitted");
|
||||
return (0);
|
||||
}
|
||||
if (body_contain_normal_char((const char **)map->map) == 0)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int body_is_valid(t_map *map)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (map->map == NULL)
|
||||
return (0);
|
||||
if (body_is_valid2(map) == 0)
|
||||
return (0);
|
||||
error = map_surround((const char **)map->map);
|
||||
if (error)
|
||||
{
|
||||
ft_eprintf("map: not surrounded");
|
||||
return (0);
|
||||
}
|
||||
get_size((const char **)map->map, map);
|
||||
return (1);
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_header.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 16:28:10 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 16:54:16 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parsing_private.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
int get_token(const char *key)
|
||||
{
|
||||
if (ft_strcmp(key, "NO") == 0)
|
||||
return (1);
|
||||
if (ft_strcmp(key, "SO") == 0)
|
||||
return (3);
|
||||
if (ft_strcmp(key, "WE") == 0)
|
||||
return (2);
|
||||
if (ft_strcmp(key, "EA") == 0)
|
||||
return (4);
|
||||
if (ft_strcmp(key, "F") == 0)
|
||||
return (5);
|
||||
if (ft_strcmp(key, "C") == 0)
|
||||
return (6);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int is_header(const char *line)
|
||||
{
|
||||
char **list;
|
||||
|
||||
list = ft_split(line, ' ');
|
||||
if (list == NULL)
|
||||
{
|
||||
ft_eprintf("malloc failed");
|
||||
ft_freer_tab_ultimate(1, list);
|
||||
return (0);
|
||||
}
|
||||
if (ft_tablen((const void **) list) != 2)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, list);
|
||||
return (0);
|
||||
}
|
||||
if (get_token(list[0]) == 0)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, list);
|
||||
return (0);
|
||||
}
|
||||
ft_freer_tab_ultimate(1, list);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static size_t get_header_size(const char **file_content, size_t *header_size)
|
||||
{
|
||||
ssize_t i;
|
||||
size_t len;
|
||||
|
||||
len = 0;
|
||||
i = -1;
|
||||
while (file_content[++i] != NULL)
|
||||
{
|
||||
if (ft_contain_only(file_content[i], ' '))
|
||||
continue ;
|
||||
if (!is_header(file_content[i]))
|
||||
break ;
|
||||
len++;
|
||||
}
|
||||
*header_size = i;
|
||||
return (len);
|
||||
}
|
||||
|
||||
char ***get_header(const char **file_content, size_t *header_size)
|
||||
{
|
||||
char ***header;
|
||||
size_t len;
|
||||
size_t i;
|
||||
ssize_t y;
|
||||
|
||||
len = get_header_size(file_content, header_size);
|
||||
header = malloc(sizeof(char *) * (len + 1));
|
||||
if (header == NULL)
|
||||
return (NULL);
|
||||
header[len] = NULL;
|
||||
y = -1;
|
||||
i = 0;
|
||||
while (++y < (ssize_t) len)
|
||||
{
|
||||
while (ft_contain_only(file_content[i], ' '))
|
||||
i++;
|
||||
header[y] = ft_split(file_content[i], ' ');
|
||||
if (header[y] == NULL)
|
||||
{
|
||||
ft_cancel((void **) header, y);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (header);
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_header2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/06/16 16:31:06 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parsing_private.h"
|
||||
|
||||
int set_texture(t_map *map, int token, const char *key, const char *value)
|
||||
{
|
||||
if (map->img_path[token - 1] != NULL)
|
||||
{
|
||||
ft_eprintf("redefinition of %s", key);
|
||||
return (1);
|
||||
}
|
||||
map->img_path[token - 1] = ft_strdup(value);
|
||||
if (map->img_path[token - 1] == NULL)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static unsigned int get_rgb(unsigned char red, unsigned char green,
|
||||
unsigned char blue)
|
||||
{
|
||||
return (red << 24 | green << 16 | blue << 8 | 255);
|
||||
}
|
||||
|
||||
static long long get_color(const char **tab)
|
||||
{
|
||||
long long rgb[3];
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 3)
|
||||
{
|
||||
if (ft_atoul_check(tab[i]) == 0)
|
||||
{
|
||||
ft_eprintf("map: %s color invalid format", tab[i]);
|
||||
return (-1);
|
||||
}
|
||||
rgb[i] = ft_atoul(tab[i]);
|
||||
if (rgb[i] > 255)
|
||||
{
|
||||
ft_eprintf("map: %s is a to high to be a color", tab[i]);
|
||||
return (-1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (get_rgb((unsigned char) rgb[0],
|
||||
(unsigned char) rgb[1], (unsigned char) rgb[2]));
|
||||
}
|
||||
|
||||
int set_color(long long *color, const char *key, const char *value)
|
||||
{
|
||||
char **tab;
|
||||
|
||||
if (*color != -1)
|
||||
{
|
||||
ft_eprintf("map: %s redefinition", key);
|
||||
return (1);
|
||||
}
|
||||
if (ft_count(value, ',') != 2)
|
||||
{
|
||||
ft_eprintf("map: invalid format %s %s", key, value);
|
||||
return (1);
|
||||
}
|
||||
tab = ft_split(value, ',');
|
||||
if (tab == NULL)
|
||||
return (1);
|
||||
*color = get_color((const char **) tab);
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
return (*color == -1);
|
||||
}
|
||||
|
||||
int check_header_is_complete(t_map *map)
|
||||
{
|
||||
if (map->img_path[0] == NULL)
|
||||
ft_eprintf("map: incomplete: Nord texture is missing");
|
||||
else if (map->img_path[1] == NULL)
|
||||
ft_eprintf("map: incomplete: WEST texture is missing");
|
||||
else if (map->img_path[2] == NULL)
|
||||
ft_eprintf("map: incomplete: SOUTH texture is missing");
|
||||
else if (map->img_path[3] == NULL)
|
||||
ft_eprintf("map: incomplete: EAST texture is missing");
|
||||
else if (map->color_bot == -1)
|
||||
ft_eprintf("map: incomplete: floor color is missing");
|
||||
else if (map->color_top == -1)
|
||||
ft_eprintf("map: incomplete: roof color is missing");
|
||||
else
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_header3.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 16:41:51 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 19:07:12 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parsing_private.h"
|
||||
|
||||
static int set_header_data(char ***header, size_t i, t_map *map)
|
||||
{
|
||||
int token;
|
||||
|
||||
token = get_token(header[i][0]);
|
||||
if (token > 0 && token < 5)
|
||||
{
|
||||
if (set_texture(map, token, header[i][0], header[i][1]))
|
||||
return (1);
|
||||
}
|
||||
else if (token == 5)
|
||||
{
|
||||
if (set_color(&map->color_bot,
|
||||
header[i][0], header[i][1]))
|
||||
return (1);
|
||||
}
|
||||
else if (token == 6)
|
||||
{
|
||||
if (set_color(&map->color_top,
|
||||
header[i][0], header[i][1]))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int header_is_valid(char ***header, t_map *map)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (header == NULL)
|
||||
return (1);
|
||||
map->color_bot = -1;
|
||||
map->color_top = -1;
|
||||
i = 0;
|
||||
while (i < ft_tablen((const void **) header))
|
||||
{
|
||||
if (set_header_data(header, i, map))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (check_header_is_complete(map));
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_meta.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 16:28:39 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 16:28:41 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parsing_private.h"
|
||||
|
||||
static int name_check(const char *path)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = ft_strlen(path);
|
||||
if (len < 4
|
||||
|| (ft_strcmp(".cub", path + len - 4) != 0))
|
||||
{
|
||||
ft_eprintf("map: name doesn't finish by .cub");
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int parsing_meta(const char *path)
|
||||
{
|
||||
return (name_check(path));
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing_private.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/16 16:27:57 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/05/16 18:46:21 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSING_PRIVATE_H
|
||||
# define PARSING_PRIVATE_H
|
||||
# include <sys/types.h>
|
||||
# include "../libftx/libftx.h"
|
||||
# include "./parsing.h"
|
||||
|
||||
int parsing_meta(const char *path);
|
||||
int get_token(const char *str);
|
||||
char ***get_header(const char **file_content, size_t *header_size);
|
||||
int header_is_valid(char ***header, t_map *map);
|
||||
char **get_body(const char **file_content, size_t header_size);
|
||||
int body_is_valid(t_map *map);
|
||||
int get_spawn_position(const char **body, double *x, double *y);
|
||||
int map_is_in_one_part(const char **body);
|
||||
int set_texture(t_map *map, int token, const char *key, const char *value);
|
||||
int set_color(long long *color, const char *key, const char *value);
|
||||
int check_header_is_complete(t_map *map);
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
01011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
bozoman
|
@ -1,9 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 200,100,0
|
||||
C 225,30,0
|
||||
|
||||
N
|
@ -1,22 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 1011110100010
|
||||
11111111 1111111 111111111111
|
@ -1,10 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 200,100,0
|
||||
C 225,30,0
|
||||
|
||||
1
|
||||
1N1
|
||||
1
|
@ -1,23 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
01011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
@ -1,20 +0,0 @@
|
||||
NO ./assets/red.png
|
||||
SO ./assets/blue.png
|
||||
WE ./assets/green.png
|
||||
EA ./assets/purple.png
|
||||
|
||||
F 200,100,0
|
||||
C 225,30,0
|
||||
|
||||
|
||||
11111111111111111111111111
|
||||
101100000111000000000000001
|
||||
101100000111000000000000001
|
||||
101100000111000000000000001 1111
|
||||
1011000001110000000000000011111100001
|
||||
101100000111000000000000000000000N001
|
||||
1011000001110000000000000011111100001
|
||||
101100000111000000000000001 10101
|
||||
101100000111000000000000001 11111
|
||||
101100000111000000000000001
|
||||
111111111111111111111111111
|
@ -1,23 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N00
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
@ -1,22 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N00
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
@ -1,23 +0,0 @@
|
||||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
Loading…
Reference in New Issue
Block a user