Compare commits

...

3 commits

Author SHA1 Message Date
Theo Champion
7bd8fb2615 wip: trying to render sprites 2025-08-05 14:17:29 +02:00
Theo Champion
410f5722e7 feat: Made a sprite structure and added a static sprite field in data
A static sprite is a sprite that is not supposed to move, it'll be
placed at the parsing part. The sprite struct is prone to change as I am
testing it
2025-08-05 13:38:07 +02:00
Theo Champion
22c20539ca feat: added a poorly drawn mystery box texture 2025-08-05 13:37:47 +02:00
4 changed files with 120 additions and 2 deletions

82
ressources/box.xpm Normal file
View file

@ -0,0 +1,82 @@
/* XPM */
static char * box_xpm[] = {
"64 64 15 1",
" c None",
". c #914500",
"+ c #B2A600",
"@ c #B9B400",
"# c #A78B00",
"$ c #B5AD00",
"% c #A38100",
"& c #9A6800",
"* c #965800",
"= c #A58700",
"- c #CAD500",
"; c #BEBE00",
"> c #C7D000",
", c #C1C500",
"' c #6A3300",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"................++@@#$..........................................",
"..............%%&&..#$............@.............................",
"..............**.....##.........................................",
"....................&+.............@$...........................",
"....................+&..............$@..........................",
"................................+&...@..........................",
"..................=-...........##....;&.........................",
"..................>,............$$##+#..........................",
"..................................##&...........................",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''",
"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"};

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
/* Updated: 2025/08/05 13:09:22 by kcolin ### ########.fr */
/* Updated: 2025/08/05 13:37:57 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,12 @@
# include "map/mapdata.h"
# include "draw/img_data.h"
# include "sprites/sprite.h"
# include "player/player.h"
# include "utils/keypresses.h"
# include "consts.h"
// the 4 static sprites are some of the perks and the mystery box
typedef struct s_cub3d_data
{
void *mlx;
@ -34,6 +36,7 @@ typedef struct s_cub3d_data
int *screen_matrix;
int delta;
int last_tick;
t_sprite static_sprite[4];
} t_cub3d_data;
#endif // CUB3D_DATA_H

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/07/31 15:01:00 by kcolin ### ########.fr */
/* Updated: 2025/08/05 13:20:05 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,7 @@
#include "raycast/raycaster.h"
#include "renderer/render.h"
#include "raycast/ray.h"
#include "sprites/sprite.h"
#include "utils/hooks.h"
#include "utils/inits.h"
#include <bits/types/struct_timeval.h>
@ -29,6 +30,9 @@
#include <fcntl.h>
#include "utils/time.h"
// for testing purposes
// TODO: Put all of that code in separated files
int game_loop(t_cub3d_data *data)
{
t_ray ray;
@ -56,6 +60,10 @@ int main(int argc, char **argv)
if (argc < 2)
return (ft_printf("Error: Missing cub3d file\n"), 1);
init_cub3d_data(&data, argv);
// placing a sprite next to player to ease debugging
data.static_sprite[0].x = data.map->startx + 1;
data.static_sprite[0].y = data.map->starty;
data.static_sprite[0].texture = mlx_xpm_file_to_image(&data.mlx, "ressources/box.xpm", &data.static_sprite[0].texture_width, &data.static_sprite[0].texture_height);
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
keyrelease_handler, &data);

25
src/sprites/sprite.h Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 12:59:44 by tchampio #+# #+# */
/* Updated: 2025/08/05 13:19:30 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SPRITE_H
# define SPRITE_H
typedef struct s_sprite
{
double x;
double y;
void *texture;
int texture_width;
int texture_height;
} t_sprite;
#endif // SPRITE_H