From 6404a697a4506362331ff2af2bebd26e2096b659 Mon Sep 17 00:00:00 2001 From: djonker Date: Sun, 29 Oct 2023 17:22:15 +0100 Subject: [PATCH] FPS counter is now shows on screen --- Readme.md | 38 ++++++++++++++++++++++++++------------ cub3d.h | 4 +++- src/init.c | 2 +- src/main.c | 14 +++++++++++--- src/parse.c | 4 +--- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Readme.md b/Readme.md index d62f122..d0a8a60 100644 --- a/Readme.md +++ b/Readme.md @@ -4,34 +4,48 @@ Cub3D is a simple raycasting game using the mlx library --- ## Todo ### Parsing -- Parse the .cub file for the floor and ceiling colors -- Parse the .cub file for the 4 textures -- Parse the .cub file for the map -- Flood fill the map and test if it is closed +- Flood fill the map starting from the player to check if it is a closed map - Check if all needed elements are present in the closed part of the map ### Raycasting -- Render the walls correctly -- Render the walls correctly with movement -- Render the walls correctly with rotation +- Replace walls with textures ### Bonus - Doors -- Wall Collision - Minimap - Animated Sprites -- Rotate with the mouse ### Extra -- FPS counter -- A Menu? - Levels? -- Skybox? - Enemies? +- Moving Enemies? - Weapon Sprite that fires? - Barrels? +- Skybox? +- Sounds? +- Music? +- A Menu? - Jumping? - Vertical Aiming? +--- +## Features +### Mandatory +- Parsing .cub file for colors and sprites +- Parsing .cub file for the map +- Set floor and ceiling color based on .cub file +- Set Player starting direction based on letter in map +- Render walls by raycasting +- Walk in 4 directions +- Rotate with arrow keys +### Bonus +- Wall Collision +- Rotate with the mouse +### Extra +- FPS counter +- Player can walk in 8 directions +- Player can Run + --- ## Bugs +- Player gets stuck in walls --- ## Usage diff --git a/cub3d.h b/cub3d.h index c1b1f1e..7935615 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ -/* Updated: 2023/10/29 15:54:07 by houtworm ######## odam.nl */ +/* Updated: 2023/10/29 17:04:28 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -24,6 +24,8 @@ typedef struct s_varlist { mlx_t *mlx; mlx_image_t *img; + mlx_image_t *fps; + int fpsrefresh; int w; int h; char **map; diff --git a/src/init.c b/src/init.c index a758e26..eb7d3ad 100644 --- a/src/init.c +++ b/src/init.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */ -/* Updated: 2023/10/29 15:23:35 by houtworm ######## odam.nl */ +/* Updated: 2023/10/29 17:17:54 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/main.c b/src/main.c index 6d9d594..7807d49 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 14:13:07 by houtworm #+# #+# */ -/* Updated: 2023/10/29 15:56:15 by houtworm ######## odam.nl */ +/* Updated: 2023/10/29 17:18:22 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,11 +14,18 @@ void ft_frametime(t_varlist *vl) { + char *itoa; + char *print; + vl->frametime = vl->mlx->delta_time; - ft_putnbr(1 / vl->frametime); - ft_putendl(" FPS"); vl->movespeed = vl->frametime * 3.0; vl->rotspeed = vl->frametime * 3.0; + mlx_delete_image(vl->mlx, vl->fps); + itoa = ft_itoa(1 / vl->frametime); + print = ft_strjoin(itoa, " FPS"); + vl->fps = mlx_put_string(vl->mlx, print, 10, 10); + mlx_set_instance_depth(vl->fps->instances, 2); + ft_vafree(2, itoa, print); } void mainloop(void *param) @@ -33,6 +40,7 @@ void mainloop(void *param) ft_movementkeys(vl); if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0)) ft_errorexit("image to window failed ", "mainloop", 1); + mlx_set_instance_depth(vl->img->instances, 1); } int main(int argc, char **argv) diff --git a/src/parse.c b/src/parse.c index 0f3d1be..a1023f0 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,18 +6,16 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */ -/* Updated: 2023/10/29 15:14:40 by houtworm ######## odam.nl */ +/* Updated: 2023/10/29 16:32:12 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -#include int ft_settexture(t_varlist *vl, char *line, int direction) { int i; - printf("line: %s\n", line); i = 0; while (line[i] != '.') i++;