Skip to content

Commit

Permalink
[0.22.13] - map maker, tick entity segfault fix, better goal texture
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyMSchubert committed Jun 28, 2024
1 parent 97e4ef4 commit eb6c520
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cub3d
generated_maze.cub
generated_map.cub

# General files
# Basic
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### [0.22.13] - 28.06.2024 - Freddy
- Better goal texture
- Readded map maker functionality
- tick entity segfaulting if there are no entities fix

### [0.22.12] - 28.06.2024 - Freddy
- Blights not properly shooting at you if youre not looking at you fix (Calculated shooting angle based on rot not pos)
- BLIGHT_SHOOTING_INACCURACY_DEG to modify shooting accuracy of a blight
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ endif

HEADERS := -I ./include -I $(LIBMLX)/include -I $(LIBFT)/include -I $(GNL)/include -I $(GLFW_PATH)/include
LIBS := $(LIBMLX)/build/libmlx42.a -ldl -lm -L$(GLFW_PATH)/lib -lglfw $(LIBFT)/libft.a $(GNL)/libftgnl.a
CFLAGS := -Wall -Werror -Wextra -Wunreachable-code
CFLAGS := -Wall -Werror -Wextra -Wunreachable-code -fsanitize=address -g -O0

$(NAME): setup $(OBJ) $(LIBMLX)/build/libmlx42.a $(LIBFT)/libft.a $(GNL)/libftgnl.a
cc $(OBJ) $(LIBS) $(HEADERS) -o $(NAME)
cc $(OBJ) $(LIBS) $(HEADERS) -o $(NAME) -fsanitize=address -g -O0

$(OBJ_DIR)/%.o: ./src/%.c
@mkdir -p $(OBJ_DIR)
Expand Down
Binary file modified assets/textures/entities/goal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions include/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:37:47 by jkauker #+# #+# */
/* Updated: 2024/06/28 13:41:18 by freddy ### ########.fr */
/* Updated: 2024/06/28 18:06:45 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -85,9 +85,20 @@ t_persistent_data *game(void);
t_list **gc(void);
t_player *player(void);

// ----- 0_texture_init
void load_static_textures(void);

// ----- 0_map_generation
// mapmaker
void generate_map(void);
// features
void remove_walls(char **maze, int height, int width);
void place_player_spawn(char **maze, t_scale map_scale);
void add_rooms(char **maze, t_scale scale, int room_count);
// file writer
void write_cub_file(char **maze, int height, int width, char *filename);
// util
int random_int(int min, int max);

// ----- 1_input_parsing
void parse_input(char *filepath);
// file helper
Expand Down
12 changes: 11 additions & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 08:45:22 by freddy #+# #+# */
/* Updated: 2024/06/28 17:47:45 by freddy ### ########.fr */
/* Updated: 2024/06/28 18:07:08 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,16 @@

# define MOUSE_SENSITIVITY 0.45

// Map Making

# define MIN_MAP_SIZE 5
# define MAX_MAP_SIZE 30
# define MIN_ROOMS_AMOUNT 0
# define MAX_ROOMS_AMOUNT 3
# define MIN_ROOM_SIZE 2
# define MAX_ROOM_SIZE 5
# define WALL_REMOVAL_CHANCE_PERCENT 20

// --- Window Setup

# define START_HEIGHT 540
Expand Down
92 changes: 92 additions & 0 deletions src/0_maze_gen/features.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* features.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 22:50:16 by freddy #+# #+# */
/* Updated: 2024/06/28 18:04:29 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../include/cub3d.h"

void remove_walls(char **maze, int height, int width)
{
int i;
int j;

i = 2;
while (i < height - 4)
{
j = 2;
while (j < width - 4)
{
if (maze[i][j] == '1' && random_int(1, 100) < \
WALL_REMOVAL_CHANCE_PERCENT)
maze[i][j] = '0';
j++;
}
i++;
}
}

void place_player_spawn(char **maze, t_scale map_scale)
{
int found_pos;
int x;
int y;

found_pos = false;
while (found_pos == false)
{
x = random_int(1, map_scale.x - 2);
y = random_int(1, map_scale.y - 2);
if (x <= 0 || y <= 0)
continue ;
if (x >= map_scale.x - 1 || y >= map_scale.y - 1)
continue ;
found_pos = true;
maze[y][x] = "NSWE"[random_int(0, 3)];
}
}

static void add_room(char **maze, t_scale start_pos, t_scale room_scale, t_scale maze_size)
{
int x;
int y;

x = start_pos.x - 1;
while (++x < start_pos.x + room_scale.y)
{
y = start_pos.y - 1;
while (++y < start_pos.y + room_scale.x)
{
if (x > 0 && y > 0 && x < maze_size.y - 1 && \
y < maze_size.x - 1 && maze[x][y] == '1')
maze[x][y] = '0';
}
}
}

void add_rooms(char **maze, t_scale scale, int room_count)
{
t_scale room_scale;
t_scale start_pos;
int i;

i = -1;
while (++i < room_count)
{
room_scale.x = random_int(MIN_ROOM_SIZE, MAX_ROOM_SIZE);
room_scale.y = random_int(MIN_ROOM_SIZE, MAX_ROOM_SIZE);
start_pos.x = random_int(1, scale.x - room_scale.y - 2);
start_pos.y = random_int(1, scale.y - room_scale.x - 2);
if (room_scale.x <= 0 || room_scale.y <= 0)
continue ;
if (start_pos.x <= 0 || start_pos.y <= 0)
continue ;
add_room(maze, start_pos, room_scale, scale);
}
}
114 changes: 114 additions & 0 deletions src/0_maze_gen/file_writer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file_writer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: freddy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 22:51:32 by freddy #+# #+# */
/* Updated: 2024/06/28 18:15:23 by freddy ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../include/cub3d.h"

#define TEXTURES_AMOUNT 22

static char *get_random_texture(void)
{
char *textures[TEXTURES_AMOUNT];

textures[0] = "./assets/textures/walls/amethyst_block.png";
textures[1] = "./assets/textures/walls/bamboo_block.png";
textures[2] = "./assets/textures/walls/bamboo_mosaic.png";
textures[3] = "./assets/textures/walls/bamboo_planks.png";
textures[4] = "./assets/textures/walls/blackstone.png";
textures[5] = "./assets/textures/walls/bookshelf.png";
textures[6] = "./assets/textures/walls/brain_coral.png";
textures[7] = "./assets/textures/walls/bricks.png";
textures[8] = "./assets/textures/walls/bubble_coral.png";
textures[9] = "./assets/textures/walls/cherry_planks.png";
textures[10] = "./assets/textures/walls/chiseled_tuff.png";
textures[11] = "./assets/textures/walls/chiseled_tuff_top.png";
textures[12] = "./assets/textures/walls/chiseled_tuff_bricks.png";
textures[13] = "./assets/textures/walls/chiseled_tuff_bricks_top.png";
textures[14] = "./assets/textures/walls/diamond_ore.png";
textures[15] = "./assets/textures/walls/fire_coral.png";
textures[16] = "./assets/textures/walls/horn_coral.png";
textures[17] = "./assets/textures/walls/redstone_ore.png";
textures[18] = "./assets/textures/walls/structure_block.png";
textures[19] = "./assets/textures/walls/structure_block_corner.png";
textures[20] = "./assets/textures/walls/structure_block_data.png";
textures[21] = "./assets/textures/walls/structure_block_load.png";
return (textures[random_int(0, TEXTURES_AMOUNT - 1)]);
}

static void write_parameters(int fd)
{
char *texture;

write(fd, "NO ", 3);
texture = get_random_texture();
write(fd, texture, ft_strlen(texture));
write(fd, "\n", 1);
write(fd, "SO ", 3);
texture = get_random_texture();
write(fd, texture, ft_strlen(texture));
write(fd, "\n", 1);
write(fd, "WE ", 3);
texture = get_random_texture();
write(fd, texture, ft_strlen(texture));
write(fd, "\n", 1);
write(fd, "EA ", 3);
texture = get_random_texture();
write(fd, texture, ft_strlen(texture));
write(fd, "\n", 1);
}

static void write_random_color(int fd, int min, int max)
{
char *color;
int color_int;

color_int = random_int(min, max);
color = ft_itoa(color_int);
write(fd, color, ft_strlen(color));
}

static void write_colors(int fd)
{
write(fd, "F ", 2);
write_random_color(fd, 0, 255);
write(fd, ",", 1);
write_random_color(fd, 0, 255);
write(fd, ",", 1);
write_random_color(fd, 0, 255);
write(fd, "\n", 1);
write(fd, "C ", 2);
write_random_color(fd, 0, 255);
write(fd, ",", 1);
write_random_color(fd, 0, 255);
write(fd, ",", 1);
write_random_color(fd, 0, 255);
write(fd, "\n", 1);
}

void write_cub_file(char **maze, int height, int width, char *filename)
{
int fd;
int i;
int j;

fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
write_parameters(fd);
write_colors(fd);
i = -1;
while (++i < height)
{
j = -1;
while (++j < width)
write(fd, &maze[i][j], 1);
write(fd, "\n", 1);
}
close(fd);
}
Loading

0 comments on commit eb6c520

Please sign in to comment.