feat: reorganize the code
This commit is contained in:
parent
a00a02e527
commit
5103cbf709
40 changed files with 326 additions and 325 deletions
79
includes/display/data_assets.h
Normal file
79
includes/display/data_assets.h
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* data_assets.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:27:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DATA_ASSETS_H
|
||||
# define DATA_ASSETS_H
|
||||
|
||||
# define NB_ASSETS 36
|
||||
|
||||
typedef struct s_assetmeta
|
||||
{
|
||||
t_const_string src;
|
||||
int limit_left;
|
||||
int limit_right;
|
||||
int limit_up;
|
||||
int limit_down;
|
||||
bool opaque;
|
||||
} t_assetmeta;
|
||||
|
||||
extern const t_assetmeta 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.
|
||||
* The images of an object with directions must be in this order:
|
||||
* down, up, left, right
|
||||
*/
|
||||
typedef enum e_assetsmap_id
|
||||
{
|
||||
FLOOR_1,
|
||||
FLOOR_2,
|
||||
WALL_BORDER,
|
||||
WALL_INNER,
|
||||
OBJECT_SNAS_DOWN,
|
||||
OBJECT_SNAS_UP,
|
||||
OBJECT_SNAS_LEFT,
|
||||
OBJECT_SNAS_RIGHT,
|
||||
OBJECT_FIRSK_DOWN,
|
||||
OBJECT_FIRST_UP,
|
||||
OBJECT_FIRST_LEFT,
|
||||
OBJECT_FIRSK_RIGHT,
|
||||
OBJECT_KETCHUP_STILL_1,
|
||||
OBJECT_KETCHUP_STILL_2,
|
||||
OBJECT_KETCHUP_STILL_3,
|
||||
OBJECT_KETCHUP_STILL_4,
|
||||
OBJECT_KETCHUP_FADE_1,
|
||||
OBJECT_KETCHUP_FADE_2,
|
||||
OBJECT_KETCHUP_FADE_3,
|
||||
OBJECT_EXIT_INACTIVE_1,
|
||||
OBJECT_EXIT_INACTIVE_2,
|
||||
OBJECT_EXIT_ACTIVE_1,
|
||||
OBJECT_EXIT_ACTIVE_2,
|
||||
OBJECT_EXIT_ACTIVE_3,
|
||||
OBJECT_EXIT_ACTIVE_4,
|
||||
OBJECT_EXIT_USING1_1,
|
||||
OBJECT_EXIT_USING1_2,
|
||||
OBJECT_EXIT_USING1_3,
|
||||
OBJECT_EXIT_USING1_4,
|
||||
OBJECT_EXIT_USING2_1,
|
||||
OBJECT_EXIT_USING2_2,
|
||||
OBJECT_EXIT_USING2_3,
|
||||
OBJECT_EXIT_USING2_4,
|
||||
OBJECT_EXIT_USING2_5,
|
||||
OBJECT_EXIT_USING2_6,
|
||||
OBJECT_EXIT_USING2_7
|
||||
} t_assetsmap_id;
|
||||
|
||||
# define OBJECT_SNAS OBJECT_SNAS_DOWN
|
||||
# define OBJECT_FIRSK OBJECT_FIRSK_DOWN
|
||||
|
||||
#endif
|
||||
48
includes/display/data_sprites.h
Normal file
48
includes/display/data_sprites.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* data_sprites.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:38:37 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DATA_SPRITES_H
|
||||
# define DATA_SPRITES_H
|
||||
|
||||
# define NB_SPRITES 9
|
||||
|
||||
typedef enum e_spritetype
|
||||
{
|
||||
ANIMATION, // loops through all the sprites
|
||||
CHARACTER_STILL, // down up left and right positions
|
||||
} t_spritetype;
|
||||
|
||||
typedef struct s_spritemeta
|
||||
{
|
||||
t_assetsmap_id first_frame;
|
||||
int nb_frames;
|
||||
int origin_x;
|
||||
int origin_y;
|
||||
t_spritetype type;
|
||||
} t_spritemeta;
|
||||
|
||||
extern const t_spritemeta g_spritesmap[NB_SPRITES];
|
||||
|
||||
typedef enum e_spritesmap_id
|
||||
{
|
||||
CASE_WALL,
|
||||
CASE_FLOOR_1,
|
||||
CASE_FLOOR_2,
|
||||
SPR_SNAS,
|
||||
SPR_SNAS_DOWN,
|
||||
SPR_SNAS_UP,
|
||||
SPR_SNAS_LEFT,
|
||||
SPR_SNAS_RIGHT,
|
||||
SPR_WALL,
|
||||
} t_spritesmap_id;
|
||||
|
||||
#endif
|
||||
52
includes/display/display.h
Normal file
52
includes/display/display.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* display.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:26:51 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DISPLAY_H
|
||||
# define DISPLAY_H
|
||||
|
||||
typedef struct s_image
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
t_assetmeta asset;
|
||||
void *img;
|
||||
t_pixel *data;
|
||||
} t_image;
|
||||
|
||||
/**
|
||||
* Load all assets at the start of the program and prepare the screen buffer.
|
||||
*/
|
||||
void display_init(void);
|
||||
|
||||
/**
|
||||
* Fill the buffer with black.
|
||||
*/
|
||||
void display_erase(void);
|
||||
|
||||
/**
|
||||
* Draw an image somewhere in the window.
|
||||
* You must call display_flush() after drawing all images.
|
||||
* x,y is the top-left position of the image.
|
||||
*/
|
||||
void display_draw(int x, int y, t_assetsmap_id asset);
|
||||
|
||||
/**
|
||||
* Draw all the screen in the buffer.
|
||||
*/
|
||||
void display_flush(void);
|
||||
|
||||
/**
|
||||
* Destroy all assets and the screen buffer before finishing the program.
|
||||
*/
|
||||
void display_destroyall(void);
|
||||
|
||||
#endif
|
||||
19
includes/display/pixel.h
Normal file
19
includes/display/pixel.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pixel.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:17:44 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:18:22 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PIXEL_H
|
||||
# define PIXEL_H
|
||||
|
||||
typedef uint32_t t_pixel;
|
||||
typedef uint8_t t_component;
|
||||
|
||||
#endif
|
||||
28
includes/display/sprite.h
Normal file
28
includes/display/sprite.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sprite.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:37:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SPRITE_H
|
||||
# define SPRITE_H
|
||||
|
||||
typedef struct s_sprite
|
||||
{
|
||||
t_spritemeta *meta;
|
||||
int index;
|
||||
} t_sprite;
|
||||
|
||||
t_sprite sprite_init(t_spritesmap_id spr);
|
||||
|
||||
void sprite_draw(int x, int y, t_sprite *spr);
|
||||
|
||||
void sprite_character_set_direction(t_sprite *spr, t_direction value);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue