feat: comic sans move number (also fix *)
fix: the limits of an asset can exceed the image dimensions
This commit is contained in:
parent
d179734202
commit
bc9cee22d7
33 changed files with 1954 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 16:52:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 20:52:29 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -122,6 +122,16 @@ 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},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/09 15:29:39 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 20:11:30 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -44,13 +44,7 @@ void display_erase(void)
|
|||
|
||||
void display_flush(void)
|
||||
{
|
||||
const t_memclass mc = mem_subclass(error_err, g_env.mc);
|
||||
t_string str;
|
||||
|
||||
mlx_put_image_to_window(g_env.mlx, g_env.win, g_screenbuf.img, 0, 0);
|
||||
str = str_inttostr(error_err, mc, g_env.moves);
|
||||
mlx_string_put(g_env.mlx, g_env.win, 0, 10, 0xFFFFFF, str);
|
||||
mem_freeall(mc);
|
||||
}
|
||||
|
||||
void display_destroyall(void)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/11 17:22:45 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 21:03:27 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -37,18 +37,10 @@ static inline t_imglimits get_limits(t_point p, t_image img)
|
|||
{
|
||||
t_imglimits r;
|
||||
|
||||
r.xmin = -p.x;
|
||||
if (img.asset.limit_left > r.xmin)
|
||||
r.xmin = img.asset.limit_left;
|
||||
r.xmax = WINDOW_WIDTH - p.x;
|
||||
if (img.asset.limit_right < r.xmax)
|
||||
r.xmax = img.asset.limit_right;
|
||||
r.ymin = -p.y;
|
||||
if (img.asset.limit_up > r.ymin)
|
||||
r.ymin = img.asset.limit_up;
|
||||
r.ymax = WINDOW_HEIGHT - p.y;
|
||||
if (img.asset.limit_down < r.ymax)
|
||||
r.ymax = img.asset.limit_down;
|
||||
r.xmin = fmax(-p.x, fmax(img.asset.limit_left, 0));
|
||||
r.xmax = fmin(WINDOW_WIDTH - p.x, fmin(img.asset.limit_right, img.width));
|
||||
r.ymin = fmax(-p.y, fmax(img.asset.limit_up, 0));
|
||||
r.ymax = fmin(WINDOW_HEIGHT - p.y, fmin(img.asset.limit_down, img.height));
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
|
|
|||
34
src/display/text.c
Normal file
34
src/display/text.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 19:57:28 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 20:22:33 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes.h"
|
||||
#include "display_utils.h"
|
||||
|
||||
void display_text(t_point *p, t_assetsmap_id asset)
|
||||
{
|
||||
display_draw(*p, asset);
|
||||
p->x += g_allassets[asset].width;
|
||||
}
|
||||
|
||||
void display_uint(t_point *p, unsigned int n)
|
||||
{
|
||||
const t_memclass mc = mem_subclass(error_err, g_env.mc);
|
||||
t_string str;
|
||||
|
||||
str = str_uinttostr(error_err, mc, n);
|
||||
while (*str)
|
||||
{
|
||||
display_text(p, TEXT_LITTLE_0 + *str - '0');
|
||||
str++;
|
||||
}
|
||||
mem_freeall(mc);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 15:11:29 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 14:36:25 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 21:09:31 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -119,28 +119,8 @@ void room_init(t_const_string path)
|
|||
void room_draw(void)
|
||||
{
|
||||
t_point p;
|
||||
t_object *obj;
|
||||
|
||||
camera_sync();
|
||||
p.y = -1;
|
||||
while (++p.y < g_env.room.height)
|
||||
{
|
||||
p.x = -1;
|
||||
while (++p.x < g_env.room.width)
|
||||
sprite_draw(to_camera_pos(p),
|
||||
g_env.room.surfaces + p.y * g_env.room.width + p.x);
|
||||
}
|
||||
p.y = -1;
|
||||
while (++p.y < g_env.room.height)
|
||||
{
|
||||
p.x = -1;
|
||||
while (++p.x < g_env.room.width)
|
||||
{
|
||||
obj = g_env.room.objects[p.y * g_env.room.width + p.x];
|
||||
if (obj)
|
||||
obj->type.draw(obj, to_camera_pos(p));
|
||||
visual_loop(&g_env.room.visuals[p.y * g_env.room.width + p.x],
|
||||
to_camera_pos(p));
|
||||
}
|
||||
}
|
||||
room_drawsurfaceandobjects();
|
||||
p = point_init(10, 4);
|
||||
display_uint(&p, g_env.moves);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 15:23:43 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/18 13:34:08 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 21:08:02 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,5 +26,6 @@ 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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 16:04:41 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/11 17:24:53 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/18 21:09:01 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,3 +51,32 @@ t_point to_camera_pos(t_point p)
|
|||
r.y = p.y * 50 - g_env.camera.pos.y;
|
||||
return (r);
|
||||
}
|
||||
|
||||
void room_drawsurfaceandobjects(void)
|
||||
{
|
||||
t_point p;
|
||||
t_object *obj;
|
||||
|
||||
camera_sync();
|
||||
p.y = -1;
|
||||
while (++p.y < g_env.room.height)
|
||||
{
|
||||
p.x = -1;
|
||||
while (++p.x < g_env.room.width)
|
||||
sprite_draw(to_camera_pos(p),
|
||||
g_env.room.surfaces + p.y * g_env.room.width + p.x);
|
||||
}
|
||||
p.y = -1;
|
||||
while (++p.y < g_env.room.height)
|
||||
{
|
||||
p.x = -1;
|
||||
while (++p.x < g_env.room.width)
|
||||
{
|
||||
obj = g_env.room.objects[p.y * g_env.room.width + p.x];
|
||||
if (obj)
|
||||
obj->type.draw(obj, to_camera_pos(p));
|
||||
visual_loop(&g_env.room.visuals[p.y * g_env.room.width + p.x],
|
||||
to_camera_pos(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue