dev: reorganize global variables and constants

This commit is contained in:
mcolonna 2024-04-20 13:05:14 +02:00
parent a395676ee9
commit 5992784dce
26 changed files with 401 additions and 356 deletions

View file

@ -3,10 +3,9 @@ NAME = so_long
SRCS = src/
INCLUDES = includes/
CODE = $(addprefix main/, \
main error env input timedloop levels1 levels2 \
main error env input input_utils timedloop levels1 levels2 \
) \
$(addprefix display/, \
data_assets data_sprites \
display1 display2 display_utils sprite text \
) \
$(addprefix room/, \

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:00:28 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:20:36 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,10 +25,8 @@ typedef struct s_assetmeta
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.
* Index for each asset. Must be in the same order than g_consts.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

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
/* Updated: 2024/04/19 12:59:36 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:24:27 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,8 +32,6 @@ typedef struct s_spritemeta
int delay_frame;
} t_spritemeta;
extern const t_spritemeta g_spritesmap[NB_SPRITES];
typedef enum e_spritesmap_id
{
CASE_BORDER_TOP,

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 13:53:41 by mcolonna #+# #+# */
/* Updated: 2024/04/18 21:00:20 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:32:27 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,6 +27,8 @@
# include "libtf.h"
# include "mlx.h"
# include "main/main.h"
# include "utils/direction.h"
# include "utils/point.h"
# include "utils/map.h"
@ -53,6 +55,5 @@
# include "main/env.h"
# include "main/input.h"
# include "main/timedloop.h"
# include "main/main.h"
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
/* Updated: 2024/04/20 12:47:22 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:46:49 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,15 +18,13 @@
# define WINDOW_TITLE "undretale"
# define FPS 20
# define TEXT_SPACE 9
# define LEVEL_COUNT 10
extern const t_const_string g_levels[LEVEL_COUNT];
typedef struct s_env
{
// GLOBAL
t_memclass mc;
t_loopfunctions loopfunctions;
// IO
// display
@ -50,7 +48,15 @@ typedef struct s_env
// moves
int moves;
} t_env;
extern t_env g_env;
typedef struct s_consts
{
t_const_string levels[LEVEL_COUNT];
t_assetmeta assetsmap[NB_ASSETS];
t_spritemeta spritesmap[NB_SPRITES];
t_roomcase roomcases[];
} t_consts;
extern const t_consts g_consts;
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 13:39:54 by mcolonna #+# #+# */
/* Updated: 2024/04/17 13:17:59 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:29:14 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,6 @@ typedef struct s_loopfunctions
void (*draw)(void);
} t_loopfunctions;
extern t_loopfunctions g_loopfunctions;
int main(int argc, t_const_string *argv);
#endif

View file

@ -6,13 +6,20 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
/* Updated: 2024/04/18 13:32:49 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:45:36 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROOM_H
# define ROOM_H
typedef struct s_roomcase
{
char c;
t_object_init object;
t_spritesmap_id surface;
} t_roomcase;
typedef struct s_room
{
int width;

View file

@ -1,154 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_assets.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:01:22 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
/**
* Path of each asset relative to assets/, without extension.
*/
const t_assetmeta g_assetsmap[NB_ASSETS] = {
{"floor/1", 50, 100, 50, 125, true},
{"floor/2", 50, 100, 50, 125, true},
// WALL
{"wall/border_top", 50, 100, 50, 125, true},
{"wall/border_bottom", 50, 100, 50, 100, true},
{"wall/inner", 50, 100, 30, 100, false},
// BRIDGE
{"wall/bridge", 50, 100, 50, 125, false},
// OBJECTS
// snas
{"object/snas/down", 50, 100, 30, 100, false},
{"object/snas/up", 50, 100, 30, 100, false},
{"object/snas/left", 50, 100, 30, 100, false},
{"object/snas/right", 50, 100, 30, 100, false},
{"object/snas/walk_down_1", 50, 100, 30, 100, false},
{"object/snas/walk_down_2", 50, 100, 30, 100, false},
{"object/snas/walk_down_3", 50, 100, 30, 100, false},
{"object/snas/walk_down_4", 50, 100, 30, 100, false},
{"object/snas/walk_right_1", 50, 100, 30, 100, false},
{"object/snas/walk_right_2", 50, 100, 30, 100, false},
{"object/snas/walk_left_1", 50, 100, 30, 100, false},
{"object/snas/walk_left_2", 50, 100, 30, 100, false},
{"object/snas/walk_up_1", 50, 100, 30, 100, false},
{"object/snas/walk_up_2", 50, 100, 30, 100, false},
{"object/snas/walk_up_3", 50, 100, 30, 100, false},
{"object/snas/walk_up_4", 50, 100, 30, 100, false},
// ketchup
{"object/ketchup/still/1", 50, 100, 40, 110, false},
{"object/ketchup/still/2", 50, 100, 40, 110, false},
{"object/ketchup/still/3", 50, 100, 40, 110, false},
{"object/ketchup/still/4", 50, 100, 40, 110, false},
{"object/ketchup/fade/1", 50, 100, 40, 110, false},
{"object/ketchup/fade/2", 50, 100, 30, 120, false},
{"object/ketchup/fade/3", 50, 100, 20, 130, false},
// exit
{"object/exit/inactive/1", 50, 100, 50, 100, false},
{"object/exit/inactive/2", 50, 100, 50, 100, false},
{"object/exit/active/1", 50, 100, 50, 100, false},
{"object/exit/active/2", 50, 100, 50, 100, false},
{"object/exit/active/3", 50, 100, 50, 100, false},
{"object/exit/active/4", 50, 100, 50, 100, false},
{"object/exit/using1/1", 50, 100, 50, 100, false},
{"object/exit/using1/2", 50, 100, 50, 100, false},
{"object/exit/using1/3", 50, 100, 50, 100, false},
{"object/exit/using1/4", 50, 100, 50, 100, false},
{"object/exit/using2/1", 40, 110, 40, 110, false},
{"object/exit/using2/2", 40, 110, 40, 110, false},
{"object/exit/using2/3", 30, 120, 30, 120, false},
{"object/exit/using2/4", 50, 100, 50, 100, false},
{"object/exit/using2/5", 50, 100, 50, 100, false},
{"object/exit/using2/6", 50, 100, 50, 100, false},
{"object/exit/using2/7", 50, 100, 50, 100, false},
{"object/exit/tp/1", 50, 100, 30, 100, false},
{"object/exit/tp/2", 50, 100, 30, 100, false},
{"object/exit/tp/3", 50, 100, 30, 100, false},
{"object/exit/tp/4", 50, 100, 30, 100, false},
{"object/exit/tp/5", 50, 100, 30, 100, false},
{"object/exit/tp/6", 50, 100, 30, 100, false},
{"object/exit/tp/7", 50, 100, 30, 100, false},
{"object/exit/tp/8", 50, 100, 30, 100, false},
{"object/exit/tp/9", 50, 100, 30, 100, false},
// firsk
{"object/firsk/down", 50, 110, 30, 100, false},
{"object/firsk/up", 40, 100, 30, 100, false},
{"object/firsk/left", 50, 100, 30, 100, false},
{"object/firsk/right", 50, 110, 30, 100, false},
{"object/firsk/walk_down_1", 50, 110, 30, 100, false},
{"object/firsk/walk_down_2", 50, 110, 30, 100, false},
{"object/firsk/walk_down_3", 50, 110, 30, 100, false},
{"object/firsk/walk_down_4", 50, 110, 30, 100, false},
{"object/firsk/walk_right_1", 50, 110, 30, 100, false},
{"object/firsk/walk_right_2", 50, 110, 30, 100, false},
{"object/firsk/walk_left_1", 50, 100, 30, 100, false},
{"object/firsk/walk_left_2", 50, 100, 30, 100, false},
{"object/firsk/walk_up_1", 40, 100, 30, 100, false},
{"object/firsk/walk_up_2", 40, 100, 30, 100, false},
{"object/firsk/walk_up_3", 40, 100, 30, 100, false},
{"object/firsk/walk_up_4", 40, 100, 30, 100, false},
// ANIM
// knife attack
{"anim/knifeattack_1", 50, 100, 40, 110, false},
{"anim/knifeattack_2", 50, 100, 40, 110, false},
{"anim/knifeattack_3", 50, 100, 40, 110, false},
{"anim/knifeattack_4", 50, 100, 40, 110, false},
{"anim/knifeattack_5", 50, 100, 40, 110, false},
{"anim/knifeattack_6", 50, 100, 40, 110, false},
{"anim/knifeattack_7", 50, 100, 40, 110, false},
// explosion
{"anim/explosion_part1_1", 0, 100, 0, 141, false},
{"anim/explosion_part1_2", 0, 100, 0, 141, false},
{"anim/explosion_part1_3", 0, 100, 0, 141, false},
{"anim/explosion_part1_4", 0, 100, 0, 141, false},
{"anim/explosion_part1_5", 0, 100, 0, 141, false},
{"anim/explosion_part1_6", 0, 100, 0, 141, false},
{"anim/explosion_part1_7", 0, 100, 0, 141, false},
{"anim/explosion_part1_8", 0, 100, 0, 141, false},
{"anim/explosion_part2_1", 0, 100, 0, 141, false},
{"anim/explosion_part2_2", 0, 100, 0, 141, false},
{"anim/explosion_part2_3", 0, 100, 0, 141, false},
{"anim/explosion_part2_4", 0, 100, 0, 141, false},
{"anim/explosion_part2_5", 0, 100, 0, 141, false},
{"anim/explosion_part2_6", 0, 100, 0, 141, false},
{"anim/explosion_part2_7", 0, 100, 0, 141, false},
{"anim/explosion_part2_8", 0, 100, 0, 141, false},
{"anim/explosion_part2_9", 0, 100, 0, 141, false},
// TEXT
// little
{"text/little/0", 0, 600, 0, 400, false},
{"text/little/1", 0, 600, 0, 400, false},
{"text/little/2", 0, 600, 0, 400, false},
{"text/little/3", 0, 600, 0, 400, false},
{"text/little/4", 0, 600, 0, 400, false},
{"text/little/5", 0, 600, 0, 400, false},
{"text/little/6", 0, 600, 0, 400, false},
{"text/little/7", 0, 600, 0, 400, false},
{"text/little/8", 0, 600, 0, 400, false},
{"text/little/9", 0, 600, 0, 400, false},
{"text/little/pressentertoretry", 0, 600, 0, 400, false},
// regular
{"text/regular/0", 0, 600, 0, 400, false},
{"text/regular/1", 0, 600, 0, 400, false},
{"text/regular/2", 0, 600, 0, 400, false},
{"text/regular/3", 0, 600, 0, 400, false},
{"text/regular/4", 0, 600, 0, 400, false},
{"text/regular/5", 0, 600, 0, 400, false},
{"text/regular/6", 0, 600, 0, 400, false},
{"text/regular/7", 0, 600, 0, 400, false},
{"text/regular/8", 0, 600, 0, 400, false},
{"text/regular/9", 0, 600, 0, 400, false},
{"text/regular/in_x_moves_1", 0, 600, 0, 400, false},
{"text/regular/in_x_moves_2", 0, 600, 0, 400, false},
{"text/regular/youded", 0, 600, 0, 400, false},
// big
{"text/big/youwin", 0, 600, 0, 400, false},
{"text/big/gameover", 0, 600, 0, 400, false},
};

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_sprites.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
/* Updated: 2024/04/19 12:59:49 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
const t_spritemeta g_spritesmap[NB_SPRITES] = {
{WALL_BORDER_TOP, 50, 50, ANIMATION, 1, 1},
{WALL_BORDER_BOTTOM, 50, 50, ANIMATION, 1, 1},
{FLOOR_1, 50, 50, ANIMATION, 1, 1},
{FLOOR_2, 50, 50, ANIMATION, 1, 1},
{BRIDGE, 50, 50, ANIMATION, 1, 1},
{OBJECT_SNAS, 50, 50, CHARACTER_STILL, 0, 0},
{OBJECT_SNAS_WALK_DOWN_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_SNAS_WALK_UP_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_SNAS_WALK_RIGHT_1, 50, 50, ANIMATION, 2, 3},
{OBJECT_SNAS_WALK_LEFT_1, 50, 50, ANIMATION, 2, 3},
{WALL_INNER, 50, 50, ANIMATION, 1, 1},
{OBJECT_KETCHUP_STILL_1, 50, 50, ANIMATION, 4, 4},
{OBJECT_KETCHUP_FADE_1, 50, 50, ANIMATION_ONCE, 3, 1},
{OBJECT_EXIT_INACTIVE_1, 50, 50, ANIMATION, 2, 4},
{OBJECT_EXIT_ACTIVE_1, 50, 50, ANIMATION, 4, 2},
{OBJECT_EXIT_ACTIVE_1, 50, 50, ANIMATION_ONCE, 2, 2},
{OBJECT_EXIT_TP_1, 50, 50, ANIMATION_ONCE, 9, 1},
{OBJECT_FIRSK, 50, 50, CHARACTER_STILL, 0, 0},
{OBJECT_FIRSK_WALK_DOWN_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_FIRSK_WALK_UP_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_FIRSK_WALK_RIGHT_1, 50, 50, ANIMATION, 2, 3},
{OBJECT_FIRSK_WALK_LEFT_1, 50, 50, ANIMATION, 2, 3},
{ANIM_KNIFEATTACK_1, 50, 50, ANIMATION_ONCE, 7, 2},
{ANIM_EXPLOSION_PART1_1, 23, 50, ANIMATION_ONCE, 8, 1},
{ANIM_EXPLOSION_PART2_1, 23, 50, ANIMATION_ONCE, 9, 1},
};

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
/* Updated: 2024/04/18 20:11:30 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:00:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
void display_init(void)
{
t_image *const screenbuf = get_screenbuf();
int i;
i = 0;
@ -23,45 +24,48 @@ void display_init(void)
load_xpm_file_with_alpha(i);
i++;
}
g_screenbuf.img = mlx_new_image(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT);
if (!g_screenbuf.img)
screenbuf->img = mlx_new_image(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT);
if (!screenbuf->img)
error_err("on mlx_new_image()");
g_screenbuf.width = WINDOW_WIDTH;
g_screenbuf.height = WINDOW_HEIGHT;
g_screenbuf.data = get_data_addr(g_screenbuf.img);
screenbuf->width = WINDOW_WIDTH;
screenbuf->height = WINDOW_HEIGHT;
screenbuf->data = get_data_addr(screenbuf->img);
display_erase();
}
void display_erase(void)
{
t_pixel *const screenbuf_data = get_screenbuf()->data;
const unsigned int black = 0x00000000;
int i;
i = -1;
while (++i < WINDOW_WIDTH * WINDOW_HEIGHT)
g_screenbuf.data[i] = black;
screenbuf_data[i] = black;
}
void display_flush(void)
{
mlx_put_image_to_window(g_env.mlx, g_env.win, g_screenbuf.img, 0, 0);
mlx_put_image_to_window(g_env.mlx, g_env.win, get_screenbuf()->img, 0, 0);
}
void display_destroyall(void)
{
t_image *const screenbuf = get_screenbuf();
const t_image *allassets = *get_allassets();
int i;
void *img;
i = 0;
while (i < NB_ASSETS)
{
img = g_allassets[i].img;
img = allassets[i].img;
if (img)
mlx_destroy_image(g_env.mlx, img);
i++;
}
if (g_screenbuf.img)
mlx_destroy_image(g_env.mlx, g_screenbuf.img);
if (screenbuf->img)
mlx_destroy_image(g_env.mlx, screenbuf->img);
if (g_env.win)
mlx_destroy_window(g_env.mlx, g_env.win);
if (g_env.mlx)

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
/* Updated: 2024/04/18 21:03:27 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 14:03:28 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,6 +46,7 @@ static inline t_imglimits get_limits(t_point p, t_image img)
static inline void display_draw_alpha(t_point p, t_image img)
{
const t_image *screenbuf = get_screenbuf();
const t_imglimits limits = get_limits(p, img);
int img_x;
int img_y;
@ -57,7 +58,7 @@ static inline void display_draw_alpha(t_point p, t_image img)
while (img_x < limits.xmax)
{
add_color(
&g_screenbuf.data[(p.y + img_y) * WINDOW_WIDTH + (p.x + img_x)],
&screenbuf->data[(p.y + img_y) * WINDOW_WIDTH + (p.x + img_x)],
img.data[img_y * img.width + img_x]);
img_x++;
}
@ -67,6 +68,7 @@ static inline void display_draw_alpha(t_point p, t_image img)
static inline void display_draw_opaque(t_point p, t_image img)
{
const t_image *screenbuf = get_screenbuf();
const t_imglimits limits = get_limits(p, img);
int img_x;
int img_y;
@ -77,7 +79,7 @@ static inline void display_draw_opaque(t_point p, t_image img)
img_x = limits.xmin;
while (img_x < limits.xmax)
{
g_screenbuf.data[(p.y + img_y) * WINDOW_WIDTH + (p.x + img_x)]
screenbuf->data[(p.y + img_y) * WINDOW_WIDTH + (p.x + img_x)]
= img.data[img_y * img.width + img_x];
img_x++;
}
@ -87,7 +89,7 @@ static inline void display_draw_opaque(t_point p, t_image img)
void display_draw(t_point p, t_assetsmap_id asset)
{
const t_image img = g_allassets[asset];
const t_image img = (*get_allassets())[asset];
if (img.asset.opaque)
display_draw_opaque(p, img);

View file

@ -6,14 +6,26 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 13:03:30 by mcolonna #+# #+# */
/* Updated: 2024/04/18 17:10:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 14:46:39 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
t_image g_allassets[NB_ASSETS];
t_image g_screenbuf;
t_image *const *get_allassets(void)
{
static t_image v[NB_ASSETS];
static t_image *const vv = v;
return (&vv);
}
t_image *get_screenbuf(void)
{
static t_image v;
return (&v);
}
t_pixel *get_data_addr(void *img)
{
@ -42,27 +54,28 @@ void apply_mask_to_image(void *img, void *mask, int nb_px)
void load_xpm_file_with_alpha(int i)
{
t_image *const allassets = *get_allassets();
t_string tmp;
t_string src;
t_string src_mask;
void *mask;
tmp = str_join(error_err, g_env.mc, "assets/", g_assetsmap[i].src);
tmp = str_join(error_err, g_env.mc, "assets/", g_consts.assetsmap[i].src);
src = str_join(error_err, g_env.mc, tmp, ".xpm");
src_mask = str_join(error_err, g_env.mc, tmp, ".alpha.xpm");
g_allassets[i].img = mlx_xpm_file_to_image(g_env.mlx, src,
&(g_allassets[i].width), &g_allassets[i].height);
if (!g_allassets[i].img)
error_str(g_assetsmap[i].src, "image loading failed");
allassets[i].img = mlx_xpm_file_to_image(g_env.mlx, src,
&(allassets[i].width), &allassets[i].height);
if (!allassets[i].img)
error_str(g_consts.assetsmap[i].src, "image loading failed");
mask = mlx_xpm_file_to_image(g_env.mlx, src_mask,
&(g_allassets[i].width), &g_allassets[i].height);
&(allassets[i].width), &allassets[i].height);
if (!mask)
error_str(g_assetsmap[i].src, "image loading failed");
apply_mask_to_image(g_allassets[i].img, mask,
g_allassets[i].width * g_allassets[i].height);
error_str(g_consts.assetsmap[i].src, "image loading failed");
apply_mask_to_image(allassets[i].img, mask,
allassets[i].width * allassets[i].height);
mlx_destroy_image(g_env.mlx, mask);
g_allassets[i].data = get_data_addr(g_allassets[i].img);
g_allassets[i].asset = g_assetsmap[i];
allassets[i].data = get_data_addr(allassets[i].img);
allassets[i].asset = g_consts.assetsmap[i];
mem_free(tmp);
mem_free(src);
mem_free(src_mask);

View file

@ -6,15 +6,15 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 12:59:24 by mcolonna #+# #+# */
/* Updated: 2024/04/02 14:39:19 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 14:51:14 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DISPLAY_UTILS_H
# define DISPLAY_UTILS_H
extern t_image g_allassets[NB_ASSETS];
extern t_image g_screenbuf;
t_image *const *get_allassets(void);
t_image *get_screenbuf(void);
typedef struct s_imglimits
{

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 22:28:52 by mcolonna #+# #+# */
/* Updated: 2024/04/11 17:24:03 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:26:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@ t_sprite sprite_init(t_spritesmap_id id)
{
t_sprite r;
r.meta = (t_spritemeta *)(g_spritesmap + id);
r.meta = (t_spritemeta *)(g_consts.spritesmap + id);
r.index = 0;
return (r);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 19:57:28 by mcolonna #+# #+# */
/* Updated: 2024/04/19 11:55:23 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:59:17 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@
void display_text(t_point *p, t_assetsmap_id asset)
{
display_draw(*p, asset);
p->x += g_allassets[asset].width;
p->x += (*get_allassets())[asset].width;
}
void display_uint(t_point *p, unsigned int n, bool little)

View file

@ -6,14 +6,19 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/16 20:02:29 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:17:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:48:31 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
#include "gameover_utils.h"
static t_gameover_env g_gameover_env;
static t_gameover_env *get_gameover_env(void)
{
static t_gameover_env v;
return (&v);
}
static void gameover_byfirskattack_loop(void)
{
@ -21,25 +26,25 @@ static void gameover_byfirskattack_loop(void)
static void gameover_byfirskattack_draw(void)
{
t_gameover_env *const env = get_gameover_env();
void *const allsprites[][5] = {
{&g_gameover_env.spr_snas, &g_gameover_env.spr_attack, NULL, NULL, NULL},
{&g_gameover_env.spr_snas, &g_gameover_env.spr_explosion1, NULL, NULL,
{&env->spr_snas, &env->spr_attack, NULL, NULL, NULL},
{&env->spr_snas, &env->spr_explosion1, NULL, NULL,
NULL},
{&g_gameover_env.spr_explosion2, NULL, (void *)1, (void *)1, NULL},
{NULL, NULL, (void *)1, (void *)1, &ask_retry},
};
void *const *sprites = allsprites[g_gameover_env.state];
{&env->spr_explosion2, NULL, (void *)1, (void *)1, NULL},
{NULL, NULL, (void *)1, (void *)1, &ask_retry}};
void *const *sprites = allsprites[env->state];
t_point p_gameover;
t_point p_youded;
p_gameover = point_init(145, 120);
p_youded = point_init(145, 210);
if (sprites[0])
if (!sprite_draw(g_gameover_env.snaspos, sprites[0]))
g_gameover_env.state++;
if (!sprite_draw(env->snaspos, sprites[0]))
env->state++;
if (sprites[1])
if (!sprite_draw(g_gameover_env.snaspos, sprites[1]))
g_gameover_env.state++;
if (!sprite_draw(env->snaspos, sprites[1]))
env->state++;
if (sprites[2])
display_text(&p_gameover, TEXT_BIG_GAMEOVER);
if (sprites[3])
@ -50,11 +55,11 @@ static void gameover_byfirskattack_draw(void)
void gameover_byfirskattack(t_character *character)
{
t_gameover_env *const env = get_gameover_env();
const t_point snas_p = room_find(snas_init);
const t_spritesmap_id snas_sprite = character->sprites->still;
g_gameover_env.snaspos
= point_subpoint(
env->snaspos = point_subpoint(
point_subpoint(
point_multiply(snas_p, 50),
g_env.camera.pos),
@ -62,12 +67,12 @@ void gameover_byfirskattack(t_character *character)
point_fromdirection(character->direction),
character->walk_remaining_steps * 50 / character->walk_steps_nb
));
g_gameover_env.spr_snas = sprite_init(snas_sprite);
g_gameover_env.spr_snas.index = character->direction;
g_gameover_env.spr_attack = sprite_init(SPR_KNIFEATTACK);
g_gameover_env.spr_explosion1 = sprite_init(SPR_EXPLOSION_1);
g_gameover_env.spr_explosion2 = sprite_init(SPR_EXPLOSION_2);
g_gameover_env.state = 0;
g_loopfunctions.loop = gameover_byfirskattack_loop;
g_loopfunctions.draw = gameover_byfirskattack_draw;
env->spr_snas = sprite_init(snas_sprite);
env->spr_snas.index = character->direction;
env->spr_attack = sprite_init(SPR_KNIFEATTACK);
env->spr_explosion1 = sprite_init(SPR_EXPLOSION_1);
env->spr_explosion2 = sprite_init(SPR_EXPLOSION_2);
env->state = 0;
g_env.loopfunctions.loop = gameover_byfirskattack_loop;
g_env.loopfunctions.draw = gameover_byfirskattack_draw;
}

View file

@ -6,13 +6,26 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:32:36 by mcolonna #+# #+# */
/* Updated: 2024/04/20 12:48:15 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:47:12 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
const t_const_string g_levels[LEVEL_COUNT] = {
t_env g_env;
const t_consts g_consts = {
roomcases: {
{c: '0', object: NULL, surface: CASE_FLOOR_1},
{c: '1', object: wall_init, surface: CASE_FLOOR_1},
{c: 'P', object: snas_init, surface: CASE_FLOOR_1},
{c: 'C', object: ketchup_init, surface: CASE_FLOOR_1},
{c: 'E', object: exit_init, surface: CASE_FLOOR_1},
{c: 'F', object: firsk_init, surface: CASE_FLOOR_1},
{c: 'B', object: NULL, surface: CASE_BRIDGE},
{c: '\0'}
},
levels: {
"rooms/01.ber",
"rooms/02.ber",
"rooms/03.ber",
@ -23,6 +36,169 @@ const t_const_string g_levels[LEVEL_COUNT] = {
"rooms/08.ber",
"rooms/09.ber",
"rooms/10.ber",
},
assetsmap: {
{"floor/1", 50, 100, 50, 125, true},
{"floor/2", 50, 100, 50, 125, true},
// WALL
{"wall/border_top", 50, 100, 50, 125, true},
{"wall/border_bottom", 50, 100, 50, 100, true},
{"wall/inner", 50, 100, 30, 100, false},
// BRIDGE
{"wall/bridge", 50, 100, 50, 125, false},
// OBJECTS
// snas
{"object/snas/down", 50, 100, 30, 100, false},
{"object/snas/up", 50, 100, 30, 100, false},
{"object/snas/left", 50, 100, 30, 100, false},
{"object/snas/right", 50, 100, 30, 100, false},
{"object/snas/walk_down_1", 50, 100, 30, 100, false},
{"object/snas/walk_down_2", 50, 100, 30, 100, false},
{"object/snas/walk_down_3", 50, 100, 30, 100, false},
{"object/snas/walk_down_4", 50, 100, 30, 100, false},
{"object/snas/walk_right_1", 50, 100, 30, 100, false},
{"object/snas/walk_right_2", 50, 100, 30, 100, false},
{"object/snas/walk_left_1", 50, 100, 30, 100, false},
{"object/snas/walk_left_2", 50, 100, 30, 100, false},
{"object/snas/walk_up_1", 50, 100, 30, 100, false},
{"object/snas/walk_up_2", 50, 100, 30, 100, false},
{"object/snas/walk_up_3", 50, 100, 30, 100, false},
{"object/snas/walk_up_4", 50, 100, 30, 100, false},
// ketchup
{"object/ketchup/still/1", 50, 100, 40, 110, false},
{"object/ketchup/still/2", 50, 100, 40, 110, false},
{"object/ketchup/still/3", 50, 100, 40, 110, false},
{"object/ketchup/still/4", 50, 100, 40, 110, false},
{"object/ketchup/fade/1", 50, 100, 40, 110, false},
{"object/ketchup/fade/2", 50, 100, 30, 120, false},
{"object/ketchup/fade/3", 50, 100, 20, 130, false},
// exit
{"object/exit/inactive/1", 50, 100, 50, 100, false},
{"object/exit/inactive/2", 50, 100, 50, 100, false},
{"object/exit/active/1", 50, 100, 50, 100, false},
{"object/exit/active/2", 50, 100, 50, 100, false},
{"object/exit/active/3", 50, 100, 50, 100, false},
{"object/exit/active/4", 50, 100, 50, 100, false},
{"object/exit/using1/1", 50, 100, 50, 100, false},
{"object/exit/using1/2", 50, 100, 50, 100, false},
{"object/exit/using1/3", 50, 100, 50, 100, false},
{"object/exit/using1/4", 50, 100, 50, 100, false},
{"object/exit/using2/1", 40, 110, 40, 110, false},
{"object/exit/using2/2", 40, 110, 40, 110, false},
{"object/exit/using2/3", 30, 120, 30, 120, false},
{"object/exit/using2/4", 50, 100, 50, 100, false},
{"object/exit/using2/5", 50, 100, 50, 100, false},
{"object/exit/using2/6", 50, 100, 50, 100, false},
{"object/exit/using2/7", 50, 100, 50, 100, false},
{"object/exit/tp/1", 50, 100, 30, 100, false},
{"object/exit/tp/2", 50, 100, 30, 100, false},
{"object/exit/tp/3", 50, 100, 30, 100, false},
{"object/exit/tp/4", 50, 100, 30, 100, false},
{"object/exit/tp/5", 50, 100, 30, 100, false},
{"object/exit/tp/6", 50, 100, 30, 100, false},
{"object/exit/tp/7", 50, 100, 30, 100, false},
{"object/exit/tp/8", 50, 100, 30, 100, false},
{"object/exit/tp/9", 50, 100, 30, 100, false},
// firsk
{"object/firsk/down", 50, 110, 30, 100, false},
{"object/firsk/up", 40, 100, 30, 100, false},
{"object/firsk/left", 50, 100, 30, 100, false},
{"object/firsk/right", 50, 110, 30, 100, false},
{"object/firsk/walk_down_1", 50, 110, 30, 100, false},
{"object/firsk/walk_down_2", 50, 110, 30, 100, false},
{"object/firsk/walk_down_3", 50, 110, 30, 100, false},
{"object/firsk/walk_down_4", 50, 110, 30, 100, false},
{"object/firsk/walk_right_1", 50, 110, 30, 100, false},
{"object/firsk/walk_right_2", 50, 110, 30, 100, false},
{"object/firsk/walk_left_1", 50, 100, 30, 100, false},
{"object/firsk/walk_left_2", 50, 100, 30, 100, false},
{"object/firsk/walk_up_1", 40, 100, 30, 100, false},
{"object/firsk/walk_up_2", 40, 100, 30, 100, false},
{"object/firsk/walk_up_3", 40, 100, 30, 100, false},
{"object/firsk/walk_up_4", 40, 100, 30, 100, false},
// ANIM
// knife attack
{"anim/knifeattack_1", 50, 100, 40, 110, false},
{"anim/knifeattack_2", 50, 100, 40, 110, false},
{"anim/knifeattack_3", 50, 100, 40, 110, false},
{"anim/knifeattack_4", 50, 100, 40, 110, false},
{"anim/knifeattack_5", 50, 100, 40, 110, false},
{"anim/knifeattack_6", 50, 100, 40, 110, false},
{"anim/knifeattack_7", 50, 100, 40, 110, false},
// explosion
{"anim/explosion_part1_1", 0, 100, 0, 141, false},
{"anim/explosion_part1_2", 0, 100, 0, 141, false},
{"anim/explosion_part1_3", 0, 100, 0, 141, false},
{"anim/explosion_part1_4", 0, 100, 0, 141, false},
{"anim/explosion_part1_5", 0, 100, 0, 141, false},
{"anim/explosion_part1_6", 0, 100, 0, 141, false},
{"anim/explosion_part1_7", 0, 100, 0, 141, false},
{"anim/explosion_part1_8", 0, 100, 0, 141, false},
{"anim/explosion_part2_1", 0, 100, 0, 141, false},
{"anim/explosion_part2_2", 0, 100, 0, 141, false},
{"anim/explosion_part2_3", 0, 100, 0, 141, false},
{"anim/explosion_part2_4", 0, 100, 0, 141, false},
{"anim/explosion_part2_5", 0, 100, 0, 141, false},
{"anim/explosion_part2_6", 0, 100, 0, 141, false},
{"anim/explosion_part2_7", 0, 100, 0, 141, false},
{"anim/explosion_part2_8", 0, 100, 0, 141, false},
{"anim/explosion_part2_9", 0, 100, 0, 141, false},
// TEXT
// little
{"text/little/0", 0, 600, 0, 400, false},
{"text/little/1", 0, 600, 0, 400, false},
{"text/little/2", 0, 600, 0, 400, false},
{"text/little/3", 0, 600, 0, 400, false},
{"text/little/4", 0, 600, 0, 400, false},
{"text/little/5", 0, 600, 0, 400, false},
{"text/little/6", 0, 600, 0, 400, false},
{"text/little/7", 0, 600, 0, 400, false},
{"text/little/8", 0, 600, 0, 400, false},
{"text/little/9", 0, 600, 0, 400, false},
{"text/little/pressentertoretry", 0, 600, 0, 400, false},
// regular
{"text/regular/0", 0, 600, 0, 400, false},
{"text/regular/1", 0, 600, 0, 400, false},
{"text/regular/2", 0, 600, 0, 400, false},
{"text/regular/3", 0, 600, 0, 400, false},
{"text/regular/4", 0, 600, 0, 400, false},
{"text/regular/5", 0, 600, 0, 400, false},
{"text/regular/6", 0, 600, 0, 400, false},
{"text/regular/7", 0, 600, 0, 400, false},
{"text/regular/8", 0, 600, 0, 400, false},
{"text/regular/9", 0, 600, 0, 400, false},
{"text/regular/in_x_moves_1", 0, 600, 0, 400, false},
{"text/regular/in_x_moves_2", 0, 600, 0, 400, false},
{"text/regular/youded", 0, 600, 0, 400, false},
// big
{"text/big/youwin", 0, 600, 0, 400, false},
{"text/big/gameover", 0, 600, 0, 400, false},
},
spritesmap: {
{WALL_BORDER_TOP, 50, 50, ANIMATION, 1, 1},
{WALL_BORDER_BOTTOM, 50, 50, ANIMATION, 1, 1},
{FLOOR_1, 50, 50, ANIMATION, 1, 1},
{FLOOR_2, 50, 50, ANIMATION, 1, 1},
{BRIDGE, 50, 50, ANIMATION, 1, 1},
{OBJECT_SNAS, 50, 50, CHARACTER_STILL, 0, 0},
{OBJECT_SNAS_WALK_DOWN_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_SNAS_WALK_UP_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_SNAS_WALK_RIGHT_1, 50, 50, ANIMATION, 2, 3},
{OBJECT_SNAS_WALK_LEFT_1, 50, 50, ANIMATION, 2, 3},
{WALL_INNER, 50, 50, ANIMATION, 1, 1},
{OBJECT_KETCHUP_STILL_1, 50, 50, ANIMATION, 4, 4},
{OBJECT_KETCHUP_FADE_1, 50, 50, ANIMATION_ONCE, 3, 1},
{OBJECT_EXIT_INACTIVE_1, 50, 50, ANIMATION, 2, 4},
{OBJECT_EXIT_ACTIVE_1, 50, 50, ANIMATION, 4, 2},
{OBJECT_EXIT_ACTIVE_1, 50, 50, ANIMATION_ONCE, 2, 2},
{OBJECT_EXIT_TP_1, 50, 50, ANIMATION_ONCE, 9, 1},
{OBJECT_FIRSK, 50, 50, CHARACTER_STILL, 0, 0},
{OBJECT_FIRSK_WALK_DOWN_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_FIRSK_WALK_UP_1, 50, 50, ANIMATION, 4, 3},
{OBJECT_FIRSK_WALK_RIGHT_1, 50, 50, ANIMATION, 2, 3},
{OBJECT_FIRSK_WALK_LEFT_1, 50, 50, ANIMATION, 2, 3},
{ANIM_KNIFEATTACK_1, 50, 50, ANIMATION_ONCE, 7, 2},
{ANIM_EXPLOSION_PART1_1, 23, 50, ANIMATION_ONCE, 8, 1},
{ANIM_EXPLOSION_PART2_1, 23, 50, ANIMATION_ONCE, 9, 1},
},
};
t_env g_env;

View file

@ -6,32 +6,29 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/26 12:26:17 by mcolonna #+# #+# */
/* Updated: 2024/04/19 12:35:00 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:40:29 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
static bool g_enter = false;
static int g_input_i = 0;
static bool g_to_unpress[4] = {false, false, false, false};
static bool g_inputbuf[4] = {false, false, false, false};
#include "input_utils.h"
static void set_direction(t_direction direction, bool value)
{
t_input_hidden *const hidden = get_input_hidden();
static int last_press[4] = {0, 0, 0, 0};
if (value)
{
last_press[direction] = g_input_i;
g_to_unpress[direction] = false;
last_press[direction] = hidden->input_i;
hidden->to_unpress[direction] = false;
}
if (!value && last_press[direction] == g_input_i)
if (!value && last_press[direction] == hidden->input_i)
{
g_to_unpress[direction] = true;
hidden->to_unpress[direction] = true;
return ;
}
g_inputbuf[direction] = value;
hidden->inputbuf[direction] = value;
}
static void setkey(int keycode, bool value)
@ -54,10 +51,12 @@ static void setkey(int keycode, bool value)
int key_press_hook(int keycode)
{
t_input_hidden *const hidden = get_input_hidden();
if (keycode == XK_Escape)
success();
if (keycode == XK_Return)
g_enter = true;
hidden->enter = true;
setkey(keycode, true);
return (0);
}
@ -70,16 +69,17 @@ int key_release_hook(int keycode)
void input_loop(void)
{
t_input_hidden *const hidden = get_input_hidden();
t_direction direction;
g_env.enter = g_enter;
g_enter = false;
g_input_i++;
g_env.enter = hidden->enter;
hidden->enter = false;
hidden->input_i++;
direction = -1;
while (++direction < 4)
{
g_env.input[direction] = g_inputbuf[direction];
if (g_to_unpress[direction])
g_env.input[direction] = hidden->inputbuf[direction];
if (hidden->to_unpress[direction])
set_direction(direction, false);
}
}

25
src/main/input_utils.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/20 15:05:54 by mcolonna #+# #+# */
/* Updated: 2024/04/20 15:16:29 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "input_utils.h"
t_input_hidden *get_input_hidden(void)
{
static t_input_hidden v = {
enter: false,
input_i: 0,
to_unpress: {false, false, false, false},
inputbuf: {false, false, false, false},
};
return (&v);
}

28
src/main/input_utils.h Normal file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/20 15:05:54 by mcolonna #+# #+# */
/* Updated: 2024/04/20 15:16:11 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INPUT_UTILS_H
# define INPUT_UTILS_H
# include "includes.h"
typedef struct s_input_hidden
{
bool enter;
int input_i;
bool to_unpress[4];
bool inputbuf[4];
} t_input_hidden;
t_input_hidden *get_input_hidden(void);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:49:39 by mcolonna #+# #+# */
/* Updated: 2024/04/19 20:35:03 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:31:03 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,7 +67,7 @@ void win(void)
g_env.level_to_load = g_env.level_current + 1;
if (g_env.level_to_load >= g_env.level_count)
{
g_loopfunctions.loop = end_loop;
g_loopfunctions.draw = end_draw;
g_env.loopfunctions.loop = end_loop;
g_env.loopfunctions.draw = end_draw;
}
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 13:18:06 by mcolonna #+# #+# */
/* Updated: 2024/04/19 19:46:14 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:30:24 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@ void init_level(void)
{
if (g_env.level_current >= g_env.level_count)
win();
g_loopfunctions.loop = room_loop;
g_loopfunctions.draw = room_draw;
g_env.loopfunctions.loop = room_loop;
g_env.loopfunctions.draw = room_draw;
room_init(g_env.levels[g_env.level_current]);
}

View file

@ -6,14 +6,12 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */
/* Updated: 2024/04/19 20:30:19 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 13:30:47 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
t_loopfunctions g_loopfunctions;
int expose_hook(void)
{
display_flush();
@ -28,16 +26,16 @@ int close_hook(void)
static void loop(void)
{
if (g_loopfunctions.loop == room_loop
if (g_env.loopfunctions.loop == room_loop
&& g_env.level_to_load != g_env.level_current)
{
g_env.level_current = g_env.level_to_load;
init_level();
}
input_loop();
g_loopfunctions.loop();
g_env.loopfunctions.loop();
display_erase();
g_loopfunctions.draw();
g_env.loopfunctions.draw();
display_flush();
}
@ -64,7 +62,7 @@ int main(int argc, t_const_string *argv)
if (argc == 2)
init_levels(1, &argv[1]);
else
init_levels(LEVEL_COUNT, g_levels);
init_levels(LEVEL_COUNT, g_consts.levels);
mlx_expose_hook(g_env.win, expose_hook, NULL);
mlx_hook(g_env.win, DestroyNotify, StructureNotifyMask, close_hook, NULL);
mlx_loop_hook(g_env.mlx, loop_hook, NULL);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:11:29 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:14:38 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:50:09 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,7 @@ static bool room_fromfile2(
int fd, t_const_string path, int *i, t_room *room)
{
t_const_string line;
t_roomcase *roomcase;
const t_roomcase *roomcase;
const t_memclass mc = mem_subclass(error_err, g_env.mc);
line = read_line(err_remember, mc, fd);

View file

@ -6,22 +6,15 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:23:43 by mcolonna #+# #+# */
/* Updated: 2024/04/18 21:08:02 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:49:47 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROOM_UTILS_H
# define ROOM_UTILS_H
typedef struct s_roomcase
{
char c;
t_object_init object;
t_spritesmap_id surface;
} t_roomcase;
void room_getsize(t_memclass mc, t_room *r, t_const_string path);
t_roomcase *getroomcase(t_const_string path, char c);
const t_roomcase *getroomcase(t_const_string path, char c);
int room_count(t_object_init objtype);
void room_checkwallsallaround(t_const_string path, t_room *room);
t_point to_camera_pos(t_point p);

View file

@ -6,24 +6,13 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:21:33 by mcolonna #+# #+# */
/* Updated: 2024/04/18 13:51:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/20 15:49:01 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
#include "room_utils.h"
static t_roomcase g_roomcases[] = {
{c: '0', object: NULL, surface: CASE_FLOOR_1},
{c: '1', object: wall_init, surface: CASE_FLOOR_1},
{c: 'P', object: snas_init, surface: CASE_FLOOR_1},
{c: 'C', object: ketchup_init, surface: CASE_FLOOR_1},
{c: 'E', object: exit_init, surface: CASE_FLOOR_1},
{c: 'F', object: firsk_init, surface: CASE_FLOOR_1},
{c: 'B', object: NULL, surface: CASE_BRIDGE},
{c: '\0'}
};
static int getlinelen(t_const_string line)
{
int r;
@ -62,15 +51,15 @@ void room_getsize(t_memclass mc, t_room *r, t_const_string path)
}
}
t_roomcase *getroomcase(t_const_string path, char c)
const t_roomcase *getroomcase(t_const_string path, char c)
{
int i;
i = -1;
while (g_roomcases[++i].c)
while (g_consts.roomcases[++i].c)
{
if (g_roomcases[i].c == c)
return (&g_roomcases[i]);
if (g_consts.roomcases[i].c == c)
return (&g_consts.roomcases[i]);
}
error_str(path, "unknown char");
return (NULL);