-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.22.13] - map maker, tick entity segfault fix, better goal texture
- Loading branch information
1 parent
97e4ef4
commit eb6c520
Showing
13 changed files
with
373 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
cub3d | ||
generated_maze.cub | ||
generated_map.cub | ||
|
||
# General files | ||
# Basic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.