feat: game over and win screens *

feat:
- win screen
- "press enter to retry" in both screens
- reset moves only when winning the game

change:
- game over screen display
- display top-left move a little differently

dev:
- scripts to import different text sizes
This commit is contained in:
mcolonna 2024-04-19 13:19:53 +02:00
parent bc9cee22d7
commit 30a935cf70
53 changed files with 4140 additions and 2163 deletions

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */
/* Updated: 2024/04/18 20:52:29 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 13:01:22 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -122,16 +122,33 @@ const t_assetmeta g_assetsmap[NB_ASSETS] = {
{"anim/explosion_part2_8", 0, 100, 0, 141, false},
{"anim/explosion_part2_9", 0, 100, 0, 141, false},
// TEXT
{"text/little/0", 0, 600, 0, 100, false},
{"text/little/1", 0, 600, 0, 100, false},
{"text/little/2", 0, 600, 0, 100, false},
{"text/little/3", 0, 600, 0, 100, false},
{"text/little/4", 0, 600, 0, 100, false},
{"text/little/5", 0, 600, 0, 100, false},
{"text/little/6", 0, 600, 0, 100, false},
{"text/little/7", 0, 600, 0, 100, false},
{"text/little/8", 0, 600, 0, 100, false},
{"text/little/9", 0, 600, 0, 100, false},
{"text/gameover", 100, 510, 120, 190, false},
{"text/youded", 240, 360, 230, 280, false},
// 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

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
/* Updated: 2024/04/18 18:26:32 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 12:59:49 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,4 @@ const t_spritemeta g_spritesmap[NB_SPRITES] = {
{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},
{TEXT_GAMEOVER, 0, 0, ANIMATION, 1, 1},
{TEXT_YOUDED, 0, 0, ANIMATION, 1, 1},
};

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 19:57:28 by mcolonna #+# #+# */
/* Updated: 2024/04/18 20:22:33 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 11:55:23 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,15 +19,19 @@ void display_text(t_point *p, t_assetsmap_id asset)
p->x += g_allassets[asset].width;
}
void display_uint(t_point *p, unsigned int n)
void display_uint(t_point *p, unsigned int n, bool little)
{
const t_memclass mc = mem_subclass(error_err, g_env.mc);
t_assetsmap_id zero;
t_string str;
zero = TEXT_REGULAR_0;
if (little)
zero = TEXT_LITTLE_0;
str = str_uinttostr(error_err, mc, n);
while (*str)
{
display_text(p, TEXT_LITTLE_0 + *str - '0');
display_text(p, zero + *str - '0');
str++;
}
mem_freeall(mc);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/16 20:02:29 by mcolonna #+# #+# */
/* Updated: 2024/04/17 18:21:17 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 13:17:46 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,14 +21,19 @@ static void gameover_byfirskattack_loop(void)
static void gameover_byfirskattack_draw(void)
{
t_sprite *const allsprites[][4] = {
{&g_gameover_env.spr_snas, &g_gameover_env.spr_attack, NULL, NULL},
{&g_gameover_env.spr_snas, &g_gameover_env.spr_explosion1, NULL, NULL},
{&g_gameover_env.spr_explosion2, NULL, &g_gameover_env.spr_gameover,
&g_gameover_env.spr_youded},
{NULL, NULL, &g_gameover_env.spr_gameover, &g_gameover_env.spr_youded}};
t_sprite *const *sprites = allsprites[g_gameover_env.state];
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,
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];
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++;
@ -36,11 +41,11 @@ static void gameover_byfirskattack_draw(void)
if (!sprite_draw(g_gameover_env.snaspos, sprites[1]))
g_gameover_env.state++;
if (sprites[2])
if (!sprite_draw(point_init(0, 0), sprites[2]))
g_gameover_env.state++;
display_text(&p_gameover, TEXT_BIG_GAMEOVER);
if (sprites[3])
if (!sprite_draw(point_init(0, 0), sprites[3]))
g_gameover_env.state++;
display_text(&p_youded, TEXT_REGULAR_YOUDED);
if (sprites[4])
((void (*)(bool))sprites[4])(true);
}
void gameover_byfirskattack(t_character *character)
@ -60,8 +65,6 @@ void gameover_byfirskattack(t_character *character)
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_gameover = sprite_init(SPR_GAMEOVER);
g_gameover_env.spr_youded = sprite_init(SPR_YOUDED);
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;

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/17 18:19:30 by mcolonna #+# #+# */
/* Updated: 2024/04/17 18:20:07 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 13:06:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,8 +20,6 @@ typedef struct s_gameover_env
t_point snaspos;
t_sprite spr_snas;
t_sprite spr_attack;
t_sprite spr_gameover;
t_sprite spr_youded;
t_sprite spr_explosion1;
t_sprite spr_explosion2;
int state;

View file

@ -6,12 +6,13 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/26 12:26:17 by mcolonna #+# #+# */
/* Updated: 2024/04/09 13:44:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 12:35:00 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};
@ -55,6 +56,8 @@ int key_press_hook(int keycode)
{
if (keycode == XK_Escape)
success();
if (keycode == XK_Return)
g_enter = true;
setkey(keycode, true);
return (0);
}
@ -69,6 +72,8 @@ void input_loop(void)
{
t_direction direction;
g_env.enter = g_enter;
g_enter = false;
g_input_i++;
direction = -1;
while (++direction < 4)

72
src/main/levels1.c Normal file
View file

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* levels1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:49:39 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:18:45 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
void ask_retry(bool current)
{
t_point p;
p = point_init(WINDOW_WIDTH - 26 - 219, WINDOW_HEIGHT - 26 - 26);
display_text(&p, TEXT_LITTLE_PRESSENTERTORETRY);
if (g_env.enter)
{
if (!current)
{
g_env.moves = 0;
g_env.level_current = 0;
}
init_level();
}
}
void init_levels(int count, t_const_string *srcs)
{
g_env.moves = 0;
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");
init_level();
}
static void end_loop(void)
{
}
static void end_draw(void)
{
t_point p;
p = point_init(200, 120);
display_text(&p, TEXT_BIG_YOUWIN);
p = point_init(200, 210);
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);
g_env.level_current = 0;
ask_retry(false);
}
void win(void)
{
g_env.level_current++;
if (g_env.level_current >= g_env.level_count)
{
g_loopfunctions.loop = end_loop;
g_loopfunctions.draw = end_draw;
}
else
init_level();
}

View file

@ -1,38 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* levels.c :+: :+: :+: */
/* levels2.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 */
/* Created: 2024/04/19 13:18:06 by mcolonna #+# #+# */
/* Updated: 2024/04/19 13:18:18 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes.h"
static void init_level_index(void)
void init_level(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();
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:11:29 by mcolonna #+# #+# */
/* Updated: 2024/04/18 21:09:31 by mcolonna ### ########.fr */
/* Updated: 2024/04/19 13:14:38 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -104,7 +104,6 @@ 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.moves = 0;
g_env.ketchup = 0;
g_env.max_ketchup = room_count(ketchup_init);
if (room_count(exit_init) != 1)
@ -121,6 +120,6 @@ void room_draw(void)
t_point p;
room_drawsurfaceandobjects();
p = point_init(10, 4);
display_uint(&p, g_env.moves);
p = point_init(4, 4);
display_uint(&p, g_env.moves, true);
}