feat: the exit works :D
This commit is contained in:
parent
0e745f82b3
commit
d3c7d8c08f
36 changed files with 3645 additions and 51 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 13:57:37 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 16:52:02 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -68,6 +68,15 @@ const t_assetmeta g_assetsmap[NB_ASSETS] = {
|
|||
{"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},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 14:00:05 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 18:26:32 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,7 +28,8 @@ const t_spritemeta g_spritesmap[NB_SPRITES] = {
|
|||
{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},
|
||||
{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},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/06 13:03:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 18:03:15 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 17:10:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -53,11 +53,11 @@ void load_xpm_file_with_alpha(int i)
|
|||
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_err("image loading failed");
|
||||
error_str(g_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);
|
||||
if (!mask)
|
||||
error_err("image loading failed");
|
||||
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);
|
||||
mlx_destroy_image(g_env.mlx, mask);
|
||||
|
|
|
|||
38
src/main/levels.c
Normal file
38
src/main/levels.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* levels.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 17:49:39 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 18:02:40 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
static void init_level_index(void)
|
||||
{
|
||||
g_loopfunctions.loop = room_loop;
|
||||
g_loopfunctions.draw = room_draw;
|
||||
room_init(g_env.levels[g_env.level_current]);
|
||||
}
|
||||
|
||||
void init_levels(int count, t_const_string *srcs)
|
||||
{
|
||||
g_env.levels = srcs;
|
||||
g_env.level_count = count;
|
||||
if (count <= 0)
|
||||
error_err("if you don't want to play any level don't start the game");
|
||||
g_env.level_current = 0;
|
||||
init_level_index();
|
||||
}
|
||||
|
||||
void win(void)
|
||||
{
|
||||
g_env.level_current++;
|
||||
if (g_env.level_current >= g_env.level_count)
|
||||
error_err("end all levels!"); // TODO
|
||||
init_level_index();
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/17 13:26:57 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 18:04:37 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -43,8 +43,6 @@ int loop_hook(void)
|
|||
|
||||
int main(int argc, t_const_string *argv)
|
||||
{
|
||||
g_loopfunctions.loop = room_loop;
|
||||
g_loopfunctions.draw = room_draw;
|
||||
if (argc != 2)
|
||||
error_str("so_long", "takes 1 argument");
|
||||
g_env.mc = mem_newclass(error_err);
|
||||
|
|
@ -57,7 +55,7 @@ int main(int argc, t_const_string *argv)
|
|||
WINDOW_TITLE);
|
||||
if (!g_env.win)
|
||||
error_err("mlx_new_window() failed");
|
||||
room_init(argv[1]);
|
||||
init_levels(1, &argv[1]);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/08 15:01:16 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 15:56:50 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 18:25:16 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,11 +36,15 @@ static bool exit_walk_through(
|
|||
t_object *obj, t_character *character, t_point pos)
|
||||
{
|
||||
t_exit_data *const data = (t_exit_data *)(obj->data);
|
||||
const t_point snas_p = room_find(snas_init);
|
||||
|
||||
(void)character;
|
||||
(void)pos;
|
||||
if (!data->active)
|
||||
return (false);
|
||||
visual_addtoroom(SPR_EXIT_USING, pos);
|
||||
((t_snas_data *)g_env.room.objects[snas_p.y * g_env.room.width + snas_p.x]
|
||||
->data)->state++;
|
||||
visual_addtoroom(sprite_init(SPR_EXIT_REMAINING), pos);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 15:57:45 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 17:14:55 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ static bool ketchup_walk_through(
|
|||
(void)obj;
|
||||
(void)character;
|
||||
g_env.ketchup++;
|
||||
visual_addtoroom(SPR_KETCHUP_FADE, pos);
|
||||
visual_addtoroom(sprite_init(SPR_KETCHUP_FADE), pos);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 15:58:11 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 18:29:33 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,8 @@ static bool snas_walk_through(t_object *obj, t_character *character,
|
|||
(void)obj;
|
||||
(void)character;
|
||||
(void)pos;
|
||||
gameover_byfirskattack(&((t_snas_data *)obj->data)->character);
|
||||
if (!((t_snas_data *)obj->data)->state)
|
||||
gameover_byfirskattack(&((t_snas_data *)obj->data)->character);
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
|
@ -38,9 +39,27 @@ static t_direction snas_brain(t_point pos)
|
|||
|
||||
static t_point snas_loop(t_object *obj, t_point pos)
|
||||
{
|
||||
t_point r;
|
||||
t_snas_data *const data = (t_snas_data *)obj->data;
|
||||
t_point r;
|
||||
|
||||
r = character_loop(&((t_snas_data *)obj->data)->character, pos, snas_brain);
|
||||
if (data->state == SNAS_STATE_GOING_TO_EXIT
|
||||
&& !data->character.walk_remaining_steps)
|
||||
{
|
||||
data->state++;
|
||||
data->tp_spr = sprite_init(SPR_EXIT_TP);
|
||||
}
|
||||
if (data->state == SNAS_STATE_WAITING_TO_WIN)
|
||||
{
|
||||
data->wait_before_win--;
|
||||
if (!data->wait_before_win)
|
||||
{
|
||||
win();
|
||||
return (point_init(0, 0));
|
||||
}
|
||||
}
|
||||
if (data->state > SNAS_STATE_GOING_TO_EXIT)
|
||||
return (point_init(0, 0));
|
||||
r = character_loop(&data->character, pos, snas_brain);
|
||||
if (r.x || r.y)
|
||||
g_env.moves++;
|
||||
return (r);
|
||||
|
|
@ -48,7 +67,20 @@ static t_point snas_loop(t_object *obj, t_point pos)
|
|||
|
||||
static void snas_draw(t_object *obj, t_point p)
|
||||
{
|
||||
return (character_draw(&((t_snas_data *)obj->data)->character, p));
|
||||
t_snas_data *const data = (t_snas_data *)obj->data;
|
||||
|
||||
if (data->state <= SNAS_STATE_GOING_TO_EXIT)
|
||||
return (character_draw(&data->character, p));
|
||||
if (data->state == SNAS_STATE_DISAPPEARS)
|
||||
{
|
||||
if (!sprite_draw(p, &data->tp_spr))
|
||||
{
|
||||
data->state = SNAS_STATE_WAITING_TO_WIN;
|
||||
data->wait_before_win = 10;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
t_object snas_init(t_memclass mc)
|
||||
|
|
@ -70,6 +102,7 @@ t_object snas_init(t_memclass mc)
|
|||
r.type = type;
|
||||
data = mem_alloc(error_err, mc, sizeof(t_snas_data));
|
||||
data->character = character_init((t_character_sprites *)&sprites, 4);
|
||||
data->state = SNAS_STATE_DEFAULT;
|
||||
r.data = data;
|
||||
return (r);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/15 17:35:13 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 16:05:23 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 18:30:25 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,10 +25,8 @@ void path_map_case_init(t_point p, void **el, void *args_p)
|
|||
before: point_init(-1, -1),
|
||||
solid: p.x == 0 || p.x == room.width - 1 || p.y == 0
|
||||
|| p.y == room.height - 1 || (
|
||||
obj && (
|
||||
(args->for_firsk && obj->type.solid_firsk)
|
||||
|| (!args->for_firsk && obj->type.solid_snas)
|
||||
))
|
||||
obj && ((args->for_firsk && obj->type.solid_firsk)
|
||||
|| (!args->for_firsk && obj->type.solid_snas)))
|
||||
|| (args->for_firsk && surface->meta->first_frame == BRIDGE)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 15:35:28 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/11 17:08:14 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 17:15:45 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,13 +23,11 @@ void visual_loop(t_visual **visual, t_point p)
|
|||
}
|
||||
}
|
||||
|
||||
void visual_addtoroom(t_spritesmap_id sprid, t_point pos)
|
||||
void visual_addtoroom(t_sprite spr, t_point pos)
|
||||
{
|
||||
t_visual *visual;
|
||||
t_sprite spr;
|
||||
|
||||
visual = mem_alloc(error_err, g_env.room.mc, sizeof(t_visual));
|
||||
spr = sprite_init(sprid);
|
||||
visual->spr = spr;
|
||||
g_env.room.visuals[pos.y * g_env.room.width + pos.x] = visual;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue