basic parsing + colectable sprites and camera degradation
This commit is contained in:
parent
3faa63104d
commit
180e5f9c8d
12
Makefile
12
Makefile
@ -1,12 +1,12 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: qmennen <qmennen@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
||||
# Updated: 2025/05/22 16:48:29 by qmennen ### ########.fr #
|
||||
# Updated: 2025/05/23 11:22:47 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ uniform sampler2D Texture2;
|
||||
uniform sampler2D Texture3;
|
||||
|
||||
uniform float u_time;
|
||||
uniform float u_battery;
|
||||
uniform vec2 u_resolution;
|
||||
|
||||
float rand(vec2 co) {
|
||||
@ -36,7 +37,8 @@ void main()
|
||||
if (TexIndex == 1) {
|
||||
vec2 uv = gl_FragCoord.xy / u_resolution.xy;
|
||||
uv.x *= u_resolution.x / u_resolution.y;
|
||||
float blockSize = 8.0;
|
||||
float blockSize = 6.0;
|
||||
float strength = 1.0 - u_battery;
|
||||
|
||||
vec2 blockUV = floor(gl_FragCoord.xy / blockSize);
|
||||
float noise = hash(blockUV + vec2(u_time * 3.0, u_time * 7.0));
|
||||
@ -48,14 +50,13 @@ void main()
|
||||
noise2 *= 0.9 + 0.1 * sin(uv.y * 400.0);
|
||||
noise3 *= 0.9 + 0.1 * sin(uv.y * 400.0);
|
||||
|
||||
float offset = 0.01;
|
||||
float r = texture(Texture1, TexCoord + vec2(offset, 0.0)).r;
|
||||
float g = texture(Texture1, TexCoord).g;
|
||||
float offset = 0.001 / (u_battery * u_battery + 0.001 );
|
||||
float r = texture(Texture1, TexCoord + vec2(offset * 5, 0.0)).r;
|
||||
float g = texture(Texture1, TexCoord + vec2(0.0, offset * 2.0)).g;
|
||||
float b = texture(Texture1, TexCoord - vec2(offset, 0.0)).b;
|
||||
vec3 color = vec3(r, g, b);
|
||||
|
||||
float strength = 0.4;
|
||||
vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), strength);
|
||||
vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), strength / 2);
|
||||
// float flicker = 0.75 + sin(u_time * 6.0 + sin(u_time * 3)) * 0.25;
|
||||
float flicker = 0.75 + 0.25 * sin(u_time + sin(u_time * 7.0));
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 14:40:47 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/14 12:42:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 15:11:20 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,5 +17,7 @@
|
||||
|
||||
int collision_horizontal(t_map *map, t_player *player, double xa);
|
||||
int collision_vertical(t_map *map, t_player *player, double ya);
|
||||
int collision_sprite(t_map *map, t_player *player, double xa, double ya);
|
||||
void collect(t_player *player);
|
||||
|
||||
#endif
|
||||
|
||||
13
inc/cub3d.h
13
inc/cub3d.h
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cub3d.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* cub3d.h :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 14:05:24 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 11:34:52 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,5 +57,6 @@
|
||||
|
||||
int initialize_cub3d(t_game **game, const char *mapfile);
|
||||
int shader_init(t_game **game);
|
||||
void set_uniforms(t_game *game);
|
||||
|
||||
#endif
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/19 14:41:55 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/25 11:43:55 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 14:00:34 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,7 +20,7 @@ ssize_t get_file_size(const char *filename);
|
||||
char *read_map_file(const char *filename);
|
||||
int is_map_line(const char *line);
|
||||
unsigned int parse_color(const char *color_str);
|
||||
int parse_config_line(const char *line, t_map *map);
|
||||
int parse_config_line(char *line, t_map *map);
|
||||
int map_width(char **lines);
|
||||
int parse_tile(char c);
|
||||
int parse_map(char **lines, t_game *game);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/16 14:59:09 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 15:17:29 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -55,6 +55,7 @@ typedef struct s_player
|
||||
t_vec2 camera;
|
||||
double speed;
|
||||
int is_moving;
|
||||
float battery;
|
||||
} t_player;
|
||||
|
||||
typedef struct s_sprite
|
||||
@ -63,6 +64,8 @@ typedef struct s_sprite
|
||||
double dist;
|
||||
double cam_frac;
|
||||
int alpha;
|
||||
int visible;
|
||||
int collectible;
|
||||
mlx_texture_t *texture;
|
||||
t_vec2 pos;
|
||||
} t_sprite;
|
||||
@ -85,6 +88,8 @@ typedef struct s_map
|
||||
unsigned int ceiling_color;
|
||||
} t_map;
|
||||
|
||||
typedef int (*t_token_handler)(char *token, t_map *map);
|
||||
|
||||
typedef struct s_keyboard
|
||||
{
|
||||
int keys[NUM_KEYS];
|
||||
|
||||
@ -6,12 +6,43 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/07 11:33:06 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 15:23:14 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "collision.h"
|
||||
|
||||
void collect(t_player *player)
|
||||
{
|
||||
player->battery += 0.5f;
|
||||
if (player->battery > 1.f)
|
||||
player->battery = 1.f;
|
||||
}
|
||||
|
||||
int collision_sprite(t_map *map, t_player *player, double xa, double ya)
|
||||
{
|
||||
t_sprite *sprites;
|
||||
int i;
|
||||
|
||||
sprites = map->sprites;
|
||||
i = 0;
|
||||
while (i < map->n_sprites)
|
||||
{
|
||||
if (sprites[i].visible && sprites[i].collectible)
|
||||
{
|
||||
if (fabs(player->pos.x + xa - sprites[i].pos.x) < 0.5
|
||||
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5)
|
||||
{
|
||||
sprites[i].visible = 0;
|
||||
collect(player);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int collision_horizontal(t_map *map, t_player *player, double xa)
|
||||
{
|
||||
t_tile tile;
|
||||
|
||||
21
src/game.c
21
src/game.c
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* game.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* game.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 17:48:48 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 15:46:03 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,17 +41,12 @@ void free_game(t_game **game)
|
||||
void game_loop(void *param)
|
||||
{
|
||||
t_game *game;
|
||||
mlx_ctx_t *ctx;
|
||||
double delta_time;
|
||||
static int fps = 0;
|
||||
|
||||
game = (t_game *)param;
|
||||
ctx = (mlx_ctx_t *)game->screen->mlx->context;
|
||||
game->framecount++;
|
||||
delta_time = game->screen->mlx->delta_time;
|
||||
fps += (int)(1.f / delta_time);
|
||||
glUniform1f(glGetUniformLocation(ctx->shaderprogram, "u_time"), glfwGetTime());
|
||||
glUniform2f(glGetUniformLocation(ctx->shaderprogram, "u_resolution"), game->screen->width, game->screen->height);
|
||||
fps += (int)(1.f / game->screen->mlx->delta_time);
|
||||
set_uniforms(game);
|
||||
if (game->framecount % 20 == 0)
|
||||
{
|
||||
game->fps = (int)(fps / 20);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 18:46:08 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 14:59:06 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
13
src/moves.c
13
src/moves.c
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* moves.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* moves.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/22 14:47:58 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 15:11:58 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,6 +29,7 @@ static void move(t_map *map, t_player *player, int dir, double delta)
|
||||
player->pos.y += ya;
|
||||
player->is_moving = 1;
|
||||
}
|
||||
collision_sprite(map, player, xa, ya);
|
||||
}
|
||||
|
||||
static void strave(t_map *map, t_player *player, int dir, double delta)
|
||||
|
||||
@ -6,36 +6,141 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/14 20:13:13 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 14:56:02 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int parse_config_line(const char *line, t_map *map)
|
||||
{
|
||||
char **tokens;
|
||||
|
||||
tokens = ft_split(line, ' ');
|
||||
if (!tokens || !tokens[0] || !tokens[1] || tokens[2])
|
||||
return (FAILURE);
|
||||
if (ft_strncmp(tokens[0], "NO", 2) == 0)
|
||||
map->north_texture = ft_strdup(tokens[1]);
|
||||
else if (ft_strncmp(tokens[0], "SO", 2) == 0)
|
||||
map->south_texture = ft_strdup(tokens[1]);
|
||||
else if (ft_strncmp(tokens[0], "WE", 2) == 0)
|
||||
map->west_texture = ft_strdup(tokens[1]);
|
||||
else if (ft_strncmp(tokens[0], "EA", 2) == 0)
|
||||
map->east_texture = ft_strdup(tokens[1]);
|
||||
else if (ft_strncmp(tokens[0], "F", 1) == 0)
|
||||
map->floor_color = parse_color(tokens[1]);
|
||||
else if (ft_strncmp(tokens[0], "C", 1) == 0)
|
||||
map->ceiling_color = parse_color(tokens[1]);
|
||||
else
|
||||
mlx_texture_t *load_texture(const char *path)
|
||||
{
|
||||
ft_free_arr(tokens);
|
||||
mlx_texture_t *texture;
|
||||
|
||||
printf("Loading texture: |%s|\n", path);
|
||||
texture = mlx_load_png(path);
|
||||
if (texture == NULL)
|
||||
{
|
||||
ft_putstr_fd("Error: Failed to load texture\n", 2);
|
||||
return (NULL);
|
||||
}
|
||||
return (texture);
|
||||
}
|
||||
|
||||
int handle_wall(char *token, t_map *map)
|
||||
{
|
||||
const char *wall_tokens[] = {
|
||||
"NO", "SO", "WE", "EA", NULL
|
||||
};
|
||||
char *texture_path;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (texture_path == NULL)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " ") != NULL)
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
while (wall_tokens[i])
|
||||
{
|
||||
if (ft_strcmp(token, wall_tokens[i]) == 0)
|
||||
{
|
||||
map->textures[i] = load_texture(texture_path);
|
||||
if (map->textures[i] == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
ft_free_arr(tokens);
|
||||
i++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_color(char *token, t_map *map)
|
||||
{
|
||||
char *color_str;
|
||||
int color;
|
||||
|
||||
color_str = ft_strtok(NULL, " ");
|
||||
if (!color_str)
|
||||
return (ft_putstr_fd("Error: Missing color value\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after color value\n", 2),
|
||||
FAILURE);
|
||||
color = parse_color(color_str);
|
||||
if (!color)
|
||||
return (ft_putstr_fd("Error: Invalid color value\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "F") == 0)
|
||||
map->floor_color = color;
|
||||
else if (ft_strcmp(token, "C") == 0)
|
||||
map->ceiling_color = color;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_texture(char *token, t_map *map)
|
||||
{
|
||||
char *texture_path;
|
||||
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (!texture_path)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "FT") == 0)
|
||||
{
|
||||
map->texture_floor = load_texture(texture_path);
|
||||
if (map->texture_floor == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
else if (ft_strcmp(token, "CT") == 0)
|
||||
{
|
||||
map->texture_ceiling = load_texture(texture_path);
|
||||
if (map->texture_ceiling == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_sprite(char *token, t_map *map)
|
||||
{
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
t_token_handler handle_config_token(const char *token, t_map *map)
|
||||
{
|
||||
const char *config_tokens[] = {
|
||||
"NO", "SO", "WE", "EA", "F", "C", "FT", "CT", "-c", "-s", NULL
|
||||
};
|
||||
const t_token_handler handlers[] = {
|
||||
handle_wall, handle_wall, handle_wall, handle_wall,
|
||||
handle_fc_color, handle_fc_color, handle_fc_texture, handle_fc_texture,
|
||||
handle_sprite, handle_sprite, NULL
|
||||
};
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
printf("Token: %s\n", token);
|
||||
while (config_tokens[i] != NULL)
|
||||
{
|
||||
if (ft_strcmp(token, config_tokens[i]) == 0)
|
||||
return (handlers[i]);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
int parse_config_line(char *line, t_map *map)
|
||||
{
|
||||
char *token;
|
||||
t_token_handler handler;
|
||||
|
||||
token = ft_strtok(line, " ");
|
||||
if (token == NULL)
|
||||
return (0);
|
||||
handler = handle_config_token(token, map);
|
||||
if (handler == NULL)
|
||||
return (ft_putstr_fd("Error: Invalid config token\n", 2), FAILURE);
|
||||
if (handler(token, map) == 0)
|
||||
return (ft_putstr_fd("Error: Failed to handle config token\n", 2),
|
||||
FAILURE);
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
13
src/player.c
13
src/player.c
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* player.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 13:57:00 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 15:22:22 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,6 +23,7 @@ int player_create(t_game **game)
|
||||
player->pos.x = -1;
|
||||
player->pos.y = -1;
|
||||
player->speed = 3.f;
|
||||
player->battery = .5f;
|
||||
(*game)->player = player;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/14 19:51:02 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 14:49:45 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,10 +29,16 @@ static void draw_floor_ceiling_pixel(t_game *game,
|
||||
const t_vec2_int tex = vec2_to_int(mul(get_fraction(floor_pos), 64));
|
||||
int color;
|
||||
|
||||
if (game->map->texture_floor == NULL)
|
||||
color = game->map->floor_color << 8 | (int)(1.0 / row_dist * 255) ;
|
||||
else
|
||||
color = get_texture_color(game->map->texture_floor,
|
||||
(t_render){row_dist, 0, 0}, tex);
|
||||
mlx_put_pixel(game->screen->img,
|
||||
coord.x, coord.y, color);
|
||||
if (game->map->texture_ceiling == NULL)
|
||||
color = game->map->ceiling_color << 8 | (int)(1.0 / row_dist * 255);
|
||||
else
|
||||
color = get_texture_color(game->map->texture_ceiling,
|
||||
(t_render){row_dist, 0, 0}, tex);
|
||||
mlx_put_pixel(game->screen->img,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/18 12:49:56 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 15:12:57 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -99,6 +99,11 @@ void render_sprites(t_render *render, t_game *game)
|
||||
i = 0;
|
||||
while (i < game->map->n_sprites)
|
||||
{
|
||||
if (!game->map->sprites[i].visible)
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
cam_fraction(game, &game->map->sprites[i]);
|
||||
draw_sprite(game, &game->map->sprites[i], render);
|
||||
i++;
|
||||
|
||||
12
src/screen.c
12
src/screen.c
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* screen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* screen.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 16:56:31 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 15:17:59 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,17 +6,31 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 18:45:29 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 15:24:19 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "glad.h"
|
||||
#include "MLX42_Int.h"
|
||||
|
||||
extern char *vert_shader;
|
||||
extern char *frag_shader;
|
||||
// extern char *vert_shader;
|
||||
// extern char *frag_shader;
|
||||
|
||||
char *read_shader(int type)
|
||||
void set_uniforms(t_game *game)
|
||||
{
|
||||
mlx_ctx_t *ctx;
|
||||
|
||||
ctx = (mlx_ctx_t *)game->screen->mlx->context;
|
||||
glUniform1f(glGetUniformLocation(ctx->shaderprogram, "u_time"),
|
||||
glfwGetTime());
|
||||
glUniform1f(glGetUniformLocation(ctx->shaderprogram, "u_battery"),
|
||||
game->player->battery);
|
||||
glUniform2f(glGetUniformLocation(ctx->shaderprogram, "u_resolution"),
|
||||
game->screen->width, game->screen->height);
|
||||
}
|
||||
|
||||
const char *read_shader(int type)
|
||||
{
|
||||
char *shader;
|
||||
char *target;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/14 20:01:57 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 14:11:39 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,12 +37,12 @@ void texture_delete(t_game *game)
|
||||
|
||||
int texture_load(t_game *game)
|
||||
{
|
||||
game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->north_texture);
|
||||
game->map->textures[SIDE_EAST] = mlx_load_png(game->map->east_texture);
|
||||
game->map->textures[SIDE_SOUTH] = mlx_load_png(game->map->south_texture);
|
||||
game->map->textures[SIDE_WEST] = mlx_load_png(game->map->west_texture);
|
||||
game->map->texture_floor = mlx_load_png("./assets/floor.png");
|
||||
game->map->texture_ceiling = mlx_load_png("./assets/ceiling64x64.png");
|
||||
// game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->north_texture);
|
||||
// game->map->textures[SIDE_EAST] = mlx_load_png(game->map->east_texture);
|
||||
// game->map->textures[SIDE_SOUTH] = mlx_load_png(game->map->south_texture);
|
||||
// game->map->textures[SIDE_WEST] = mlx_load_png(game->map->west_texture);
|
||||
// game->map->texture_floor = mlx_load_png("./assets/floor.png");
|
||||
// game->map->texture_ceiling = mlx_load_png("./assets/ceiling64x64.png");
|
||||
if (!game->map->textures[SIDE_NORTH] || !game->map->textures[SIDE_EAST]
|
||||
|| !game->map->textures[SIDE_SOUTH] || !game->map->textures[SIDE_WEST])
|
||||
{
|
||||
|
||||
@ -1,28 +1,43 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* initialize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* initialize.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 14:06:29 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/23 15:05:50 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
static t_sprite make_sprite(char *path, double x, double y, int n)
|
||||
static t_sprite make_sprite(char *path, double x, double y, int collectible)
|
||||
{
|
||||
t_sprite sprite;
|
||||
|
||||
ft_memset(&sprite, 0, sizeof(t_sprite));
|
||||
sprite.texture = mlx_load_png(path);
|
||||
sprite.n_frames = n;
|
||||
if (!sprite.texture)
|
||||
{
|
||||
fprintf(stderr, "Error loading texture: %s\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sprite.texture->width % 64 != 0)
|
||||
{
|
||||
fprintf(stderr, "Error: Texture %s width is not a multiple of 64\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sprite.texture->height != 64)
|
||||
{
|
||||
fprintf(stderr, "Error: Texture %s height is not 64\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sprite.n_frames = sprite.texture->width / 64;
|
||||
sprite.pos.x = x;
|
||||
sprite.pos.y = y;
|
||||
sprite.dist = 0;
|
||||
sprite.cam_frac = 0;
|
||||
sprite.alpha = 0;
|
||||
sprite.visible = 1;
|
||||
sprite.collectible = collectible;
|
||||
return (sprite);
|
||||
}
|
||||
|
||||
@ -35,15 +50,15 @@ static int init_temp(t_game **game)
|
||||
return (FAILURE);
|
||||
sprites = (*game)->map->sprites;
|
||||
sprites[0] = make_sprite("./assets/battery.png", 3.5, 3.5, 1);
|
||||
sprites[1] = make_sprite("./assets/plant.png", 2.5, 3.5, 4);
|
||||
sprites[2] = make_sprite("./assets/plant.png", 1.5, 3.5, 4);
|
||||
sprites[3] = make_sprite("./assets/broken_mirror.png", 3.5, 4.5, 1);
|
||||
sprites[4] = make_sprite("./assets/lamp.png", 2.5, 5.5, 1);
|
||||
sprites[1] = make_sprite("./assets/plant.png", 2.5, 3.5, 0);
|
||||
sprites[2] = make_sprite("./assets/plant.png", 1.5, 3.5, 0);
|
||||
sprites[3] = make_sprite("./assets/broken_mirror.png", 3.5, 4.5, 0);
|
||||
sprites[4] = make_sprite("./assets/lamp.png", 2.5, 5.5, 0);
|
||||
sprites[5] = make_sprite("./assets/battery.png", 10.5, 6.5, 1);
|
||||
sprites[6] = make_sprite("./assets/plant.png", 14.5, 3.5, 4);
|
||||
sprites[7] = make_sprite("./assets/battery.png", 36.5, 3.5, 1);
|
||||
sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 1);
|
||||
sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 1);
|
||||
sprites[6] = make_sprite("./assets/plant.png", 14.5, 3.5, 0);
|
||||
sprites[7] = make_sprite("./assets/battery.png", 2.5, 7.5, 1);
|
||||
sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 0);
|
||||
sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 0);
|
||||
(*game)->map->n_sprites = 10;
|
||||
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
|
||||
mlx_load_png("./assets/overlay2.png"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user