misc: many things

This commit is contained in:
mcolonna 2024-03-07 23:37:34 +01:00
parent 664b18eb2e
commit 8076487071
25 changed files with 554 additions and 73 deletions

View file

@ -1,23 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* assets.h :+: :+: :+: */
/* data_assets.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
/* Updated: 2024/03/06 13:42:57 by mcolonna ### ########.fr */
/* Updated: 2024/03/13 15:43:09 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ASSETS_H
# define ASSETS_H
#ifndef DATA_ASSETS_H
# define DATA_ASSETS_H
# include <stdint.h>
# include "display.h"
# include "libtf.h"
# define NB_ASSETS 36
typedef uint32_t t_pixel;
typedef uint8_t t_component;
typedef struct s_asset
{
t_const_string src;
int limit_left;
int limit_right;
int limit_up;
int limit_down;
bool opaque;
} t_assetinfo;
extern const t_assetinfo g_assetsmap[NB_ASSETS];
/**
* Index for each asset. Must be in the same order than g_assetsmap.
* The frames of an animation must be together and sorted.
@ -61,7 +76,7 @@ typedef enum e_assetid
OBJECT_EXIT_USING2_4,
OBJECT_EXIT_USING2_5,
OBJECT_EXIT_USING2_6,
OBJECT_EXIT_USING2_7,
OBJECT_EXIT_USING2_7
} t_assetid;
typedef enum e_direction

36
includes/data_sprites.h Normal file
View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_sprites.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
/* Updated: 2024/03/11 16:31:33 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_SPRITES_H
# define DATA_SPRITES_H
# include "data_assets.h"
# define NB_SPRITES 2
typedef struct s_spriteinfo
{
t_assetid first_frame;
int nb_frames;
int origin_x;
int origin_y;
} t_spriteinfo;
extern const t_spriteinfo g_spritesmap[NB_SPRITES];
typedef enum e_spriteid
{
CASE_WALL,
CASE_FLOOR
} t_spriteid;
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */
/* Updated: 2024/03/06 14:20:39 by mcolonna ### ########.fr */
/* Updated: 2024/03/11 15:53:57 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,31 +15,16 @@
# include <stdint.h>
# include "libtf.h"
# include "assets.h"
typedef uint32_t t_pixel;
typedef uint8_t t_component;
typedef struct s_asset
{
t_const_string src;
int limit_left;
int limit_right;
int limit_up;
int limit_down;
bool opaque;
} t_asset;
# include "data_assets.h"
typedef struct s_image
{
int width;
int height;
t_asset asset;
void *img;
t_pixel *data;
} t_image;
extern const t_asset g_assetsmap[];
int width;
int height;
t_assetinfo asset;
void *img;
t_pixel *data;
} t_image;
/**
* Load all assets at the start of the program and prepare the screen buffer.

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
/* Updated: 2024/02/27 16:47:57 by mcolonna ### ########.fr */
/* Updated: 2024/03/08 13:54:52 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
# define ENV_H
# include "libtf.h"
# include "room.h"
# define WINDOW_WIDTH 600
# define WINDOW_HEIGHT 400
@ -24,6 +25,7 @@ typedef struct s_env
t_memclass mc;
void *mlx;
void *win;
t_room room;
} t_env;
extern t_env g_env;

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:04:31 by mcolonna #+# #+# */
/* Updated: 2024/02/27 16:12:12 by mcolonna ### ########.fr */
/* Updated: 2024/03/11 13:23:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@
# include "libtf.h"
void err(t_const_string msg);
void err_perror(t_const_string s);
void err_perror_str(t_const_string s, t_const_string msg);
void finish(void);
#endif

45
includes/room.h Normal file
View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* room.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
/* Updated: 2024/03/13 14:11:13 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROOM_H
# define ROOM_H
# include "sprite.h"
# include "libtf.h"
typedef struct s_object
{
t_sprite spr;
} t_object;
typedef struct s_room
{
int width;
int height;
t_sprite *surfaces;
t_object **objects;
t_memclass mc;
} t_room;
typedef struct s_roomcase
{
char c;
t_spriteid surface_spr;
} t_roomcase;
t_room room_fromfile(t_const_string path);
void room_draw(t_room room);
void room_free(t_room room);
#endif

23
includes/room_utils.h Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* room_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */
/* Updated: 2024/03/13 16:46:44 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROOM_UTILS_H
# define ROOM_UTILS_H
# include "libtf.h"
# include "room.h"
int getlinelen(t_const_string line);
void room_getsize(t_memclass mc, t_room *r, t_const_string path);
t_roomcase *getroomcase(t_const_string path, char c);
#endif

29
includes/sprite.h Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */
/* Updated: 2024/03/11 16:26:48 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SPRITE_H
# define SPRITE_H
# include "data_assets.h"
# include "data_sprites.h"
typedef struct s_sprite
{
const t_spriteinfo *info;
int index;
} t_sprite;
t_sprite sprite_init(t_spriteid spr);
void sprite_draw(int x, int y, t_sprite *spr);
#endif