shadert, battery en record light
This commit is contained in:
parent
6c34f24462
commit
98bced2a5e
Binary file not shown.
|
Before Width: | Height: | Size: 761 KiB After Width: | Height: | Size: 528 KiB |
@ -51,16 +51,19 @@ void main()
|
||||
noise3 *= 0.9 + 0.1 * sin(uv.y * 400.0);
|
||||
|
||||
float offset = 0.001 / (u_battery * u_battery + 0.001 );
|
||||
offset = offset > .05 ? .05 : offset;
|
||||
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);
|
||||
|
||||
vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), strength / 2);
|
||||
vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), (strength / 2 + .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));
|
||||
float flicker = (1 - strength * 0.5) + 0.25 * (strength * sin(u_time + sin(u_time * 7.0) + 1));
|
||||
|
||||
float dim = u_battery < 0.1 ? u_battery * 10.0 : 1;
|
||||
FragColor = vec4(noisyColor, texColor.a * flicker * dim);
|
||||
|
||||
FragColor = vec4(noisyColor, texColor.a * flicker);
|
||||
} else {
|
||||
FragColor = texColor;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/23 15:23:14 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:29:23 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
84
src/game.c
84
src/game.c
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/23 15:58:12 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:20:34 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,6 +38,81 @@ void free_game(t_game **game)
|
||||
}
|
||||
}
|
||||
|
||||
int battery_color(float battery)
|
||||
{
|
||||
if (battery > 0.5f)
|
||||
return (0x00FF0066);
|
||||
else if (battery > 0.25f)
|
||||
return (0xFFFF0066);
|
||||
else
|
||||
return (0xFF000066);
|
||||
}
|
||||
|
||||
void draw_battery(mlx_image_t *img, float battery)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
x = 1340;
|
||||
while (x < 1350)
|
||||
{
|
||||
y = 265;
|
||||
while (y < 285)
|
||||
{
|
||||
mlx_put_pixel(img, x, y, battery_color(battery));
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
x = 1350;
|
||||
while (x < 1450)
|
||||
{
|
||||
y = 250;
|
||||
while (y < 300)
|
||||
{
|
||||
mlx_put_pixel(img, x, y, battery_color(battery));
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_battery(t_game *game)
|
||||
{
|
||||
game->player->battery -= game->screen->mlx->delta_time / 50;
|
||||
if (game->player->battery < 0)
|
||||
game->player->battery = 0.001f;
|
||||
draw_battery(game->screen->minimap, game->player->battery);
|
||||
}
|
||||
|
||||
void handle_record(t_game *game)
|
||||
{
|
||||
static int flash = 0;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
flash = (game->framecount / 30) % 2;
|
||||
y = -15;
|
||||
while (y <= 15)
|
||||
{
|
||||
x = -15;
|
||||
while (x <= 15)
|
||||
{
|
||||
if (x * x + y * y <= 225)
|
||||
{
|
||||
if (flash)
|
||||
mlx_put_pixel(
|
||||
game->screen->hud, 1530 + x, 212 + y, 0xFF000055);
|
||||
else
|
||||
mlx_put_pixel(
|
||||
game->screen->hud, 1530 + x, 212 + y, 0x00000066);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
void game_loop(void *param)
|
||||
{
|
||||
t_game *game;
|
||||
@ -50,7 +125,7 @@ void game_loop(void *param)
|
||||
if (game->framecount % 20 == 0)
|
||||
{
|
||||
game->fps = (int)(fps / 20);
|
||||
fprintf(stderr, "battery: %f FPS: %d\n",game->player->battery, fps / 20);
|
||||
fprintf(stderr, "FPS: %d\n", fps / 20);
|
||||
fps = 0;
|
||||
}
|
||||
player_update(game, game->screen->mlx->delta_time);
|
||||
@ -62,9 +137,8 @@ void game_loop(void *param)
|
||||
game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20;
|
||||
game->screen->img->instances[0].y = cos(game->framecount / 3.0) * 10;
|
||||
}
|
||||
game->player->battery -= game->screen->mlx->delta_time / 10;
|
||||
if (game->player->battery < 0)
|
||||
game->player->battery = 0.001f;
|
||||
handle_battery(game);
|
||||
handle_record(game);
|
||||
}
|
||||
|
||||
void game_free(t_game *game)
|
||||
|
||||
@ -6,13 +6,12 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/23 14:56:02 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:29:05 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
|
||||
mlx_texture_t *load_texture(const char *path)
|
||||
{
|
||||
mlx_texture_t *texture;
|
||||
@ -127,7 +126,6 @@ t_token_handler handle_config_token(const char *token, t_map *map)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
int parse_config_line(char *line, t_map *map)
|
||||
{
|
||||
char *token;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/23 14:49:45 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:27:52 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/23 14:11:39 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:29:13 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,12 +37,6 @@ 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");
|
||||
if (!game->map->textures[SIDE_NORTH] || !game->map->textures[SIDE_EAST]
|
||||
|| !game->map->textures[SIDE_SOUTH] || !game->map->textures[SIDE_WEST])
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/23 15:05:50 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/23 17:28:36 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,7 +25,7 @@ static t_sprite make_sprite(char *path, double x, double y, int collectible)
|
||||
}
|
||||
if (sprite.texture->width % 64 != 0)
|
||||
{
|
||||
fprintf(stderr, "Error: Texture %s width is not a multiple of 64\n", path);
|
||||
fprintf(stderr, "Error: Texture %s width not a multiple of 64\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sprite.texture->height != 64)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user