feat: add exit (without game over screen) *
also: - fix: walk_through's prototype - misc: remove ketchup debug thing - dev: rename room_patch -> room_fromfile3
This commit is contained in:
parent
6ad613d4bb
commit
7ec3eb6841
16 changed files with 103 additions and 23 deletions
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ CODE = $(addprefix main/, \
|
|||
) \
|
||||
$(addprefix room/, \
|
||||
visual room1 room2 room_utils1 room_utils2 \
|
||||
object_character object_snas object_wall object_ketchup \
|
||||
object_character object_snas object_wall object_ketchup object_exit \
|
||||
) \
|
||||
utils/point
|
||||
LIBRARIES = mlx libtf
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/05 18:01:55 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:30:53 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DATA_SPRITES_H
|
||||
# define DATA_SPRITES_H
|
||||
|
||||
# define NB_SPRITES 11
|
||||
# define NB_SPRITES 14
|
||||
|
||||
typedef enum e_spritetype
|
||||
{
|
||||
|
@ -47,6 +47,9 @@ typedef enum e_spritesmap_id
|
|||
SPR_WALL,
|
||||
SPR_KETCHUP,
|
||||
SPR_KETCHUP_FADE,
|
||||
SPR_EXIT_INACTIVE,
|
||||
SPR_EXIT_ACTIVE,
|
||||
SPR_EXIT_USING,
|
||||
} t_spritesmap_id;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/05 16:31:40 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:17:26 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -27,6 +27,7 @@ typedef struct s_env
|
|||
t_room room;
|
||||
bool input[4];
|
||||
int ketchup;
|
||||
int max_ketchup;
|
||||
} t_env;
|
||||
|
||||
extern t_env g_env;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 16:11:55 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:35:33 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -23,7 +23,7 @@ typedef struct s_objecttype
|
|||
// Called when a character want to walk through this object.
|
||||
// Returns false to block the character. If true, it will pass.
|
||||
// If walk_through is NULL, the character is blocked.
|
||||
bool (*walk_through)(t_character *, t_point pos);
|
||||
bool (*walk_through)(t_object *, t_character *, t_point pos);
|
||||
} t_objecttype;
|
||||
|
||||
typedef struct s_object
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:47:01 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 15:25:31 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:22:05 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -37,4 +37,13 @@ typedef struct s_ketchup_data
|
|||
|
||||
t_object ketchup_init(t_memclass mc);
|
||||
|
||||
// EXIT
|
||||
typedef struct s_exit_data
|
||||
{
|
||||
t_sprite spr;
|
||||
bool active;
|
||||
} t_exit_data;
|
||||
|
||||
t_object exit_init(t_memclass mc);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 15:32:23 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:17:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
1000011111001
|
||||
100001P0000K1
|
||||
1KKK111111111
|
||||
1000000000001
|
||||
10000000000E1
|
||||
1111111111111
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/05 18:45:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:33:56 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -24,4 +24,7 @@ const t_spritemeta g_spritesmap[NB_SPRITES] = {
|
|||
{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_USING1_1, 50, 50, ANIMATION_ONCE, 11, 1},
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 16:08:07 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:16:57 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -42,6 +42,7 @@ int loop_hook(void)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
g_env.max_ketchup = 0;
|
||||
g_env.mc = mem_newclass(error_err);
|
||||
g_env.mlx = mlx_init();
|
||||
if (!g_env.mlx)
|
||||
|
|
60
src/room/object_exit.c
Normal file
60
src/room/object_exit.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* object_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/08 15:01:16 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/08 15:36:22 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
static t_point exit_loop(t_object *obj, t_point pos)
|
||||
{
|
||||
t_exit_data *const data = (t_exit_data *)(obj->data);
|
||||
|
||||
(void)pos;
|
||||
if (!data->active && g_env.ketchup == g_env.max_ketchup)
|
||||
{
|
||||
data->active = true;
|
||||
data->spr = sprite_init(SPR_EXIT_ACTIVE);
|
||||
}
|
||||
return (point_init(0, 0));
|
||||
}
|
||||
|
||||
static void exit_draw(t_object *obj, int x, int y)
|
||||
{
|
||||
t_exit_data *const data = (t_exit_data *)(obj->data);
|
||||
|
||||
sprite_draw(x, y, &data->spr);
|
||||
}
|
||||
|
||||
static bool exit_walk_through(
|
||||
t_object *obj, t_character *character, t_point pos)
|
||||
{
|
||||
t_exit_data *const data = (t_exit_data *)(obj->data);
|
||||
|
||||
(void)character;
|
||||
if (!data->active)
|
||||
return (false);
|
||||
visual_addtoroom(SPR_EXIT_USING, pos);
|
||||
return (true);
|
||||
}
|
||||
|
||||
t_object exit_init(t_memclass mc)
|
||||
{
|
||||
static const t_objecttype type
|
||||
= {loop: exit_loop, draw: exit_draw, walk_through: exit_walk_through};
|
||||
t_object r;
|
||||
t_exit_data *data;
|
||||
|
||||
r.type = type;
|
||||
data = mem_alloc(error_err, mc, sizeof(t_exit_data));
|
||||
data->spr = sprite_init(SPR_EXIT_INACTIVE);
|
||||
data->active = false;
|
||||
r.data = data;
|
||||
return (r);
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 16:10:39 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:36:10 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -24,11 +24,12 @@ static void ketchup_draw(t_object *obj, int x, int y)
|
|||
sprite_draw(x, y, &((t_wall_data *)obj->data)->spr);
|
||||
}
|
||||
|
||||
static bool ketchup_walk_through(t_character *character, t_point pos)
|
||||
static bool ketchup_walk_through(
|
||||
t_object *obj, t_character *character, t_point pos)
|
||||
{
|
||||
(void)obj;
|
||||
(void)character;
|
||||
g_env.ketchup++;
|
||||
tf_printf("Ketchup level: %i\n", g_env.ketchup);
|
||||
visual_addtoroom(SPR_KETCHUP_FADE, pos);
|
||||
return (true);
|
||||
}
|
||||
|
@ -45,5 +46,6 @@ t_object ketchup_init(t_memclass mc)
|
|||
data = mem_alloc(error_err, mc, sizeof(t_wall_data));
|
||||
data->spr = sprite_init(SPR_KETCHUP);
|
||||
r.data = data;
|
||||
g_env.max_ketchup++;
|
||||
return (r);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 15:43:44 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:13:16 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -68,7 +68,7 @@ t_room room_fromfile(t_const_string path)
|
|||
while (room_fromfile2(fd, path, &i, &r))
|
||||
;
|
||||
mem_freeall(mc);
|
||||
room_patch(&r);
|
||||
room_fromfile3(&r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 16:10:23 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:36:42 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -35,7 +35,7 @@ bool room_canwalk(t_room room, t_character *character, t_point pos)
|
|||
obj = room_getobjectfaced(room, character, pos);
|
||||
r = (!obj || (
|
||||
obj->type.walk_through
|
||||
&& obj->type.walk_through(character, after)));
|
||||
&& obj->type.walk_through(obj, character, after)));
|
||||
if (r)
|
||||
mem_free(obj);
|
||||
return (r);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:51:05 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:13:43 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -24,6 +24,6 @@ void room_getsize(t_memclass mc, t_room *r, t_const_string path);
|
|||
t_roomcase *getroomcase(t_const_string path, char c);
|
||||
void moveobject(t_room room, t_point start, t_point move);
|
||||
bool isinlist(void *addr, t_list list);
|
||||
void room_patch(t_room *room);
|
||||
void room_fromfile3(t_room *room);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/03 13:35:35 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:07:16 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -18,6 +18,7 @@ static t_roomcase g_roomcases[] = {
|
|||
{c: '1', object: wall_init},
|
||||
{c: 'P', object: snas_init},
|
||||
{c: 'K', object: ketchup_init},
|
||||
{c: 'E', object: exit_init},
|
||||
{c: '\0'}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 12:33:48 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:52:14 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/08 15:16:01 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes.h"
|
||||
#include "room_utils.h"
|
||||
|
||||
void room_patch(t_room *room)
|
||||
void room_fromfile3(t_room *room)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
|
Loading…
Add table
Reference in a new issue