FPS counter is now shows on screen

This commit is contained in:
djonker 2023-10-29 17:22:15 +01:00
parent 0148ee755e
commit 6404a697a4
5 changed files with 42 additions and 20 deletions

View File

@ -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

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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;

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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)

View File

@ -6,18 +6,16 @@
/* By: houtworm <codam@houtworm.net> +#+ */
/* +#+ */
/* 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 <stdio.h>
int ft_settexture(t_varlist *vl, char *line, int direction)
{
int i;
printf("line: %s\n", line);
i = 0;
while (line[i] != '.')
i++;