feat: base + display functions!!!!!

This commit is contained in:
mcolonna 2024-02-26 14:18:51 +01:00
parent ebb5931632
commit 664b18eb2e
187 changed files with 29451 additions and 0 deletions

78
includes/assets.h Normal file
View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef ASSETS_H
# define ASSETS_H
# include <stdint.h>
# include "display.h"
# define NB_ASSETS 36
/**
* 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_assetid
{
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_assetid;
typedef enum e_direction
{
DOWN,
UP,
LEFT,
RIGHT
} t_direction;
# define OBJECT_SNAS OBJECT_SNAS_DOWN
# define OBJECT_FIRSK OBJECT_FIRSK_DOWN
#endif

71
includes/display.h Normal file
View file

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* display.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */
/* Updated: 2024/03/06 14:20:39 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DISPLAY_H
# define DISPLAY_H
# 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;
typedef struct s_image
{
int width;
int height;
t_asset asset;
void *img;
t_pixel *data;
} t_image;
extern const t_asset g_assetsmap[];
/**
* 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_assetid 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

35
includes/display_utils.h Normal file
View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* display_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 12:59:24 by mcolonna #+# #+# */
/* Updated: 2024/03/06 13:47:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DISPLAY_UTILS_H
# define DISPLAY_UTILS_H
# include "display.h"
extern t_image g_allassets[NB_ASSETS];
extern t_image g_screenbuf;
typedef struct s_imglimits
{
int xmin;
int xmax;
int ymin;
int ymax;
} t_imglimits;
t_pixel *get_data_addr(void *img);
void apply_mask_to_image(void *img, void *mask, int nb_px);
void load_xpm_file_with_alpha(int i);
#endif

31
includes/env.h Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
/* Updated: 2024/02/27 16:47:57 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ENV_H
# define ENV_H
# include "libtf.h"
# define WINDOW_WIDTH 600
# define WINDOW_HEIGHT 400
# define WINDOW_TITLE "undretale"
typedef struct s_env
{
t_memclass mc;
void *mlx;
void *win;
} t_env;
extern t_env g_env;
#endif

21
includes/error.h Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:04:31 by mcolonna #+# #+# */
/* Updated: 2024/02/27 16:12:12 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ERROR_H
# define ERROR_H
# include "libtf.h"
void err(t_const_string msg);
void finish(void);
#endif