feat: ultimate ketchup ending

This commit is contained in:
mcolonna 2024-04-21 15:52:23 +02:00
parent 840d0b31e9
commit 14bcb02d5a
48 changed files with 6101 additions and 2320 deletions

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 19:57:28 by mcolonna #+# #+# */
/* Updated: 2024/04/20 13:59:17 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 19:41:35 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,6 +32,10 @@ void display_uint(t_point *p, unsigned int n, bool little)
while (*str)
{
display_text(p, zero + *str - '0');
if (little)
p->x -= 3;
else
p->x -= 5;
str++;
}
mem_freeall(mc);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:32:36 by mcolonna #+# #+# */
/* Updated: 2024/04/21 16:04:08 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 17:53:00 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,6 +24,7 @@ const t_consts g_consts = {
{c: 'F', object: firsk_init, surface: CASE_FLOOR_1},
{c: 'B', object: NULL, surface: CASE_BRIDGE},
{c: 'A', object: activablewall_init, surface: CASE_FLOOR_1},
{c: 'U', object: ultimateketchup_init, surface: CASE_FLOOR_1},
{c: '\0'}
},
levels: {
@ -117,6 +118,8 @@ const t_consts g_consts = {
{"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},
// ultimate ketchup
{"object/ultimateketchup/1", 0, 900, 0, 900, false},
// ANIM
// knife attack
{"anim/knifeattack_1", 50, 100, 40, 110, false},
@ -171,6 +174,8 @@ const t_consts g_consts = {
{"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},
{"text/regular/youfoundtheultimateketchup_1", 0, 600, 0, 400, false},
{"text/regular/youfoundtheultimateketchup_2", 0, 600, 0, 400, false},
// big
{"text/big/youwin", 0, 600, 0, 400, false},
{"text/big/gameover", 0, 600, 0, 400, false},
@ -198,6 +203,7 @@ const t_consts g_consts = {
{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},
{OBJECT_ULTIMATEKETCHUP, 300, 300, ANIMATION, 1, 1},
{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/04/11 16:34:56 by mcolonna #+# #+# */
/* Updated: 2024/04/15 18:09:36 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 19:37:20 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,6 +49,13 @@ static void limit(int *n, int min, int max)
*n = max;
}
static void camera_sync_ending(void)
{
g_env.camera.pos.y -= 5;
if (g_env.camera.pos.y < 50)
g_env.camera.pos.y = 50;
}
void camera_sync(void)
{
const t_point obj_pos = find_snas_position();
@ -56,6 +63,8 @@ void camera_sync(void)
point_init(g_env.room.width, g_env.room.height), 50);
t_point *const camera_pos = &g_env.camera.pos;
if (g_env.room.ending)
return (camera_sync_ending());
if (room_dims.x <= WINDOW_WIDTH)
camera_pos->x = -(WINDOW_WIDTH - room_dims.x) / 2;
else

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/08 15:01:16 by mcolonna #+# #+# */
/* Updated: 2024/04/18 18:25:16 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 17:06:07 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,8 +16,10 @@ static t_point exit_loop(t_object *obj, t_point pos)
{
t_exit_data *const data = (t_exit_data *)(obj->data);
data->finalexit = room_count(ultimateketchup_init) == 1;
(void)pos;
if (!data->active && g_env.ketchup == g_env.max_ketchup)
if (!data->finalexit
&& !data->active && g_env.ketchup == g_env.max_ketchup)
{
data->active = true;
data->spr = sprite_init(SPR_EXIT_ACTIVE);
@ -29,7 +31,8 @@ static void exit_draw(t_object *obj, t_point p)
{
t_exit_data *const data = (t_exit_data *)(obj->data);
sprite_draw(p, &data->spr);
if (!data->finalexit)
sprite_draw(p, &data->spr);
}
static bool exit_walk_through(
@ -40,6 +43,11 @@ static bool exit_walk_through(
(void)character;
(void)pos;
if (data->finalexit)
{
g_env.room.ending = true;
return (false);
}
if (!data->active)
return (false);
((t_snas_data *)g_env.room.objects[snas_p.y * g_env.room.width + snas_p.x]

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
/* Updated: 2024/04/20 16:21:05 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 16:30:38 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,6 +26,8 @@ static bool snas_walk_through(t_object *obj, t_character *character,
static t_direction snas_brain(t_point pos)
{
(void)pos;
if (g_env.room.ending)
return (NO_DIRECTION);
if (g_env.input[UP] && !g_env.input[DOWN])
return (UP);
if (g_env.input[DOWN] && !g_env.input[UP])

View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* object_ultimateketchup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
/* Updated: 2024/04/21 19:50:16 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
static t_point ultimateketchup_loop(t_object *obj, t_point pos)
{
(void)obj;
(void)pos;
if (g_env.room.ending)
((t_ultimateketchup_data *)obj->data)->time++;
return (point_init(0, 0));
}
static void ultimateketchup_draw(t_object *obj, t_point p)
{
sprite_draw(p, &((t_ultimateketchup_data *)obj->data)->spr);
}
t_object ultimateketchup_init(t_memclass mc)
{
static const t_objecttype type
= {solid_firsk: true, solid_snas: true,
init: ultimateketchup_init, loop: ultimateketchup_loop,
draw: ultimateketchup_draw, walk_through: NULL};
t_object r;
t_ultimateketchup_data *data;
r.type = type;
data = mem_alloc(error_err, mc, sizeof(t_ultimateketchup_data));
data->spr = sprite_init(SPR_ULTIMATEKETCHUP);
data->time = 0;
r.data = data;
return (r);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:11:29 by mcolonna #+# #+# */
/* Updated: 2024/04/20 16:15:11 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 19:29:19 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -104,6 +104,8 @@ static t_room room_fromfile(t_room *r, t_const_string path)
void room_init(t_const_string path)
{
room_fromfile(&g_env.room, path);
g_env.room.ending = false;
g_env.room.time_after_ending = 0;
g_env.ketchup = 0;
g_env.max_ketchup = room_count(ketchup_init);
g_env.snas_moved = false;
@ -118,9 +120,14 @@ void room_init(t_const_string path)
void room_draw(void)
{
t_point p;
t_point p;
room_drawsurfaceandobjects();
p = point_init(4, 4);
display_uint(&p, g_env.moves, true);
if (g_env.room.ending)
room_endingdraw();
else
{
p = point_init(4, 4);
display_uint(&p, g_env.moves, true);
}
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:18:38 by mcolonna #+# #+# */
/* Updated: 2024/04/15 18:10:15 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 16:59:11 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,3 +58,17 @@ t_point room_find(t_object_init objtype)
}
return (point_init(-1, -1));
}
int room_count(t_object_init objtype)
{
int i;
int r;
r = 0;
i = -1;
while (++i < g_env.room.width * g_env.room.height)
if (g_env.room.objects[i]
&& g_env.room.objects[i]->type.init == objtype)
r++;
return (r);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:23:43 by mcolonna #+# #+# */
/* Updated: 2024/04/20 15:49:47 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 19:29:37 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,10 @@
void room_getsize(t_memclass mc, t_room *r, t_const_string path);
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);
void room_checkaccessibilities(t_const_string path);
void room_drawsurfaceandobjects(void);
void room_endingdraw(void);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:21:33 by mcolonna #+# #+# */
/* Updated: 2024/04/20 15:49:01 by mcolonna ### ########.fr */
/* Updated: 2024/04/21 19:47:00 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,20 +65,6 @@ const t_roomcase *getroomcase(t_const_string path, char c)
return (NULL);
}
int room_count(t_object_init objtype)
{
int i;
int r;
r = 0;
i = -1;
while (++i < g_env.room.width * g_env.room.height)
if (g_env.room.objects[i]
&& g_env.room.objects[i]->type.init == objtype)
r++;
return (r);
}
void room_checkaccessibilities(t_const_string path)
{
t_point p;
@ -101,3 +87,27 @@ void room_checkaccessibilities(t_const_string path)
if (pathfinding(snas_pos, room_find(exit_init), false) == NO_DIRECTION)
error_str(path, "the exit must be accessible.");
}
void room_endingdraw(void)
{
const int time = g_env.room.time_after_ending;
t_point p;
g_env.room.time_after_ending++;
if (time < 30)
return ;
p = point_init(200, 75);
display_text(&p, TEXT_REGULAR_YOUFOUNDTHEULTIMATEKETCHUP_1);
if (time < 60)
return ;
p = point_init(25, 125);
display_text(&p, TEXT_REGULAR_YOUFOUNDTHEULTIMATEKETCHUP_2);
if (time < 100)
return ;
p = point_init(235, 310);
display_text(&p, TEXT_REGULAR_IN_X_MOVES_1);
p.x += TEXT_SPACE;
display_uint(&p, g_env.moves, false);
p.x += TEXT_SPACE;
display_text(&p, TEXT_REGULAR_IN_X_MOVES_2);
}