feat: snas can move!!!!!1!

This commit is contained in:
mcolonna 2024-03-26 16:54:10 +01:00
parent 4bd12ffcf1
commit ef0941e44f
17 changed files with 296 additions and 58 deletions

View file

@ -5,7 +5,8 @@ INCLUDES = includes/
CODE = main error env input timedloop \ CODE = main error env input timedloop \
data_assets data_sprites \ data_assets data_sprites \
display1 display2 display_utils sprite \ display1 display2 display_utils sprite \
room room_utils object room room_utils point \
object_character object_snas
LIBRARIES = mlx libtf LIBRARIES = mlx libtf
LIBRARIES_FILES = libtf/libtf.a LIBRARIES_FILES = libtf/libtf.a
LIBRARIES_LINK = mlx LIBRARIES_LINK = mlx

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */ /* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
/* Updated: 2024/03/13 15:43:09 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 15:09:30 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -84,7 +84,8 @@ typedef enum e_direction
DOWN, DOWN,
UP, UP,
LEFT, LEFT,
RIGHT RIGHT,
NO_DIRECTION
} t_direction; } t_direction;
# define OBJECT_SNAS OBJECT_SNAS_DOWN # define OBJECT_SNAS OBJECT_SNAS_DOWN

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */ /* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
/* Updated: 2024/03/15 18:49:12 by mcolonna ### ########.fr */ /* Updated: 2024/03/29 13:55:24 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,13 @@
# include "data_assets.h" # include "data_assets.h"
# define NB_SPRITES 3 # define NB_SPRITES 7
typedef enum e_assettype
{
ANIMATION, // loops through all the sprites
CHARACTER_STILL, // down up left and right positions
} t_assettype;
typedef struct s_spriteinfo typedef struct s_spriteinfo
{ {
@ -23,6 +29,7 @@ typedef struct s_spriteinfo
int nb_frames; int nb_frames;
int origin_x; int origin_x;
int origin_y; int origin_y;
t_assettype type;
} t_spriteinfo; } t_spriteinfo;
extern const t_spriteinfo g_spritesmap[NB_SPRITES]; extern const t_spriteinfo g_spritesmap[NB_SPRITES];
@ -31,7 +38,11 @@ typedef enum e_spriteid
{ {
CASE_WALL, CASE_WALL,
CASE_FLOOR, CASE_FLOOR,
SPR_SNAS_DOWN SPR_SNAS,
SPR_SNAS_DOWN,
SPR_SNAS_UP,
SPR_SNAS_LEFT,
SPR_SNAS_RIGHT,
} t_spriteid; } t_spriteid;
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */ /* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
/* Updated: 2024/03/26 15:48:24 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 12:50:14 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,8 @@
# define WINDOW_WIDTH 600 # define WINDOW_WIDTH 600
# define WINDOW_HEIGHT 400 # define WINDOW_HEIGHT 400
# define WINDOW_TITLE "undretale" # define WINDOW_TITLE "undretale"
# define FPS 10 # define FPS 20
# define WALK_STEPS_NB 4
typedef struct s_env typedef struct s_env
{ {

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */ /* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
/* Updated: 2024/03/15 20:06:45 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 17:51:55 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@
# include "display.h" # include "display.h"
# include "sprite.h" # include "sprite.h"
/**** OBJECT ****/
typedef struct s_object t_object; typedef struct s_object t_object;
typedef struct s_objecttype typedef struct s_objecttype
@ -33,13 +34,36 @@ typedef struct s_object
void *data; void *data;
} t_object; } t_object;
typedef struct s_snas_data typedef t_object (*t_object_init)(t_memclass);
/**** CHARACTER ****/
typedef struct s_character_sprites
{
t_spriteid still;
t_spriteid walk_left;
t_spriteid walk_right;
t_spriteid walk_up;
t_spriteid walk_down;
} t_character_sprites;
typedef struct s_character
{ {
t_direction direction; t_direction direction;
t_sprite spr; t_sprite spr;
} t_snas_data; int walk_remaining_steps;
t_character_sprites *sprites;
} t_character;
typedef t_object (*t_object_init)(t_memclass); void character_draw(t_character *character, int x, int y);
t_point character_loop(t_character *character, t_point pos,
t_direction (*brain)(void));
t_character character_init(t_character_sprites *sprites);
/**** SNAS ****/
typedef struct s_snas_data
{
t_character character;
} t_snas_data;
t_object snas_init(t_memclass mc); t_object snas_init(t_memclass mc);

View file

@ -6,22 +6,24 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:05:03 by mcolonna #+# #+# */ /* Created: 2024/03/15 15:05:03 by mcolonna #+# #+# */
/* Updated: 2024/03/15 19:38:46 by mcolonna ### ########.fr */ /* Updated: 2024/03/27 18:22:51 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef POINT_H #ifndef POINT_H
# define POINT_H # define POINT_H
# include "data_assets.h"
typedef struct s_point typedef struct s_point
{ {
int x; int x;
int y; int y;
} t_point; } t_point;
/*
t_point point_init(int x, int y); t_point point_init(int x, int y);
void point_addto(t_point *dest, t_point src); void point_addto(t_point *dest, t_point src);
*/ t_point point_fromdirection(t_direction direction);
t_point point_multiply(t_point point, int x);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */ /* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
/* Updated: 2024/03/15 18:51:14 by mcolonna ### ########.fr */ /* Updated: 2024/03/26 16:06:02 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,6 +35,8 @@ typedef struct s_roomcase
t_room room_fromfile(t_const_string path); t_room room_fromfile(t_const_string path);
void room_loop(t_room room);
void room_draw(t_room room); void room_draw(t_room room);
void room_free(t_room room); void room_free(t_room room);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */ /* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */
/* Updated: 2024/03/13 16:46:44 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 17:54:32 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,5 +19,7 @@
int getlinelen(t_const_string line); int getlinelen(t_const_string line);
void room_getsize(t_memclass mc, t_room *r, t_const_string path); void room_getsize(t_memclass mc, t_room *r, t_const_string path);
t_roomcase *getroomcase(t_const_string path, char c); 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);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */ /* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */
/* Updated: 2024/03/15 19:55:46 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 15:59:30 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@
typedef struct s_sprite typedef struct s_sprite
{ {
const t_spriteinfo *info; t_spriteinfo *info;
int index; int index;
} t_sprite; } t_sprite;
@ -26,4 +26,6 @@ t_sprite sprite_init(t_spriteid spr);
void sprite_draw(int x, int y, t_sprite *spr); void sprite_draw(int x, int y, t_sprite *spr);
void sprite_character_set_direction(t_sprite *spr, t_direction value);
#endif #endif

View file

@ -6,14 +6,18 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */ /* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
/* Updated: 2024/03/15 15:31:48 by mcolonna ### ########.fr */ /* Updated: 2024/03/29 14:32:57 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "data_sprites.h" #include "data_sprites.h"
const t_spriteinfo g_spritesmap[NB_SPRITES] = { const t_spriteinfo g_spritesmap[NB_SPRITES] = {
{WALL_BORDER, 1, 50, 50}, {WALL_BORDER, 1, 50, 50, ANIMATION},
{FLOOR_1, 1, 50, 50}, {FLOOR_1, 1, 50, 50, ANIMATION},
{OBJECT_SNAS_DOWN, 1, 50, 50} {OBJECT_SNAS, 0, 50, 50, CHARACTER_STILL},
{OBJECT_SNAS_DOWN, 1, 50, 50, ANIMATION},
{OBJECT_SNAS_UP, 1, 50, 50, ANIMATION},
{OBJECT_SNAS_LEFT, 1, 50, 50, ANIMATION},
{OBJECT_SNAS_RIGHT, 1, 50, 50, ANIMATION},
}; };

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */ /* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */
/* Updated: 2024/03/26 15:59:54 by mcolonna ### ########.fr */ /* Updated: 2024/03/26 16:42:18 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,15 +33,12 @@ int close_hook(void)
return (0); return (0);
} }
static bool g_tac = false;
static void loop(void) static void loop(void)
{ {
if (g_tac) room_loop(g_env.room);
print_line(err, 1, " tac"); display_erase();
else room_draw(g_env.room);
print_line(err, 1, "tic"); display_flush();
g_tac = !g_tac;
} }
int loop_hook(void) int loop_hook(void)

84
src/object_character.c Normal file
View file

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* object_character.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
/* Updated: 2024/03/29 13:56:58 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "object.h"
#include "error.h"
#include "sprite.h"
#include "libtf.h"
#include "env.h"
static void character_initstate(t_character *character)
{
const t_spriteid walk_sprites[] = {
character->sprites->walk_down,
character->sprites->walk_up,
character->sprites->walk_left,
character->sprites->walk_right,
};
if (character->walk_remaining_steps)
character->spr = sprite_init(walk_sprites[character->direction]);
else
{
character->spr = sprite_init(SPR_SNAS);
sprite_character_set_direction(&character->spr, character->direction);
}
}
void character_draw(t_character *character, int x, int y)
{
t_point pos;
pos = point_init(x, y);
point_addto(&pos,
point_multiply(
point_fromdirection(character->direction),
character->walk_remaining_steps * 50 / -WALK_STEPS_NB
));
sprite_draw(pos.x, pos.y, &character->spr);
}
t_point character_loop(
t_character *character, t_point pos, t_direction (*brain)(void))
{
t_direction move;
(void)pos;
move = NO_DIRECTION;
if (character->walk_remaining_steps)
if (!--character->walk_remaining_steps)
character_initstate(character);
if (!character->walk_remaining_steps)
{
move = brain();
if (move != NO_DIRECTION)
{
character->walk_remaining_steps = WALK_STEPS_NB - 1;
character->direction = move;
character_initstate(character);
}
}
if (move != NO_DIRECTION)
return (point_fromdirection(character->direction));
return (point_init(0, 0));
}
t_character character_init(t_character_sprites *sprites)
{
t_character r;
r.direction = DOWN;
r.sprites = sprites;
r.walk_remaining_steps = 0;
character_initstate(&r);
return (r);
}

View file

@ -1,42 +1,62 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* object.c :+: :+: :+: */ /* object_snas.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */ /* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
/* Updated: 2024/03/15 20:00:25 by mcolonna ### ########.fr */ /* Updated: 2024/03/29 13:54:55 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "object.h" #include "object.h"
#include "error.h" #include "error.h"
#include "sprite.h" #include "sprite.h"
#include "libtf.h"
#include "env.h"
static t_direction snas_brain(void)
{
if (g_env.up && !g_env.down)
return (UP);
if (g_env.down && !g_env.up)
return (DOWN);
if (g_env.left && !g_env.right)
return (LEFT);
if (g_env.right && !g_env.left)
return (RIGHT);
return (NO_DIRECTION);
}
static t_point snas_loop(t_object *obj, t_point pos) static t_point snas_loop(t_object *obj, t_point pos)
{ {
const t_point r = {0, 0}; return (character_loop(
&((t_snas_data *)obj->data)->character, pos, snas_brain));
(void)((void)obj, pos);
return (r);
} }
static void snas_draw(t_object *obj, int x, int y) static void snas_draw(t_object *obj, int x, int y)
{ {
sprite_draw(x, y, &((t_snas_data *)obj->data)->spr); return (character_draw(&((t_snas_data *)obj->data)->character, x, y));
} }
t_object snas_init(t_memclass mc) t_object snas_init(t_memclass mc)
{ {
static const t_objecttype type = {loop: snas_loop, draw: snas_draw}; static const t_objecttype type
= {loop: snas_loop, draw: snas_draw};
static const t_character_sprites sprites = {
still: SPR_SNAS,
walk_left: SPR_SNAS_LEFT,
walk_right: SPR_SNAS_RIGHT,
walk_up: SPR_SNAS_UP,
walk_down: SPR_SNAS_DOWN,
};
t_object r; t_object r;
t_snas_data *data; t_snas_data *data;
r.type = type; r.type = type;
data = mem_alloc(err, mc, sizeof(t_snas_data)); data = mem_alloc(err, mc, sizeof(t_snas_data));
data->direction = DOWN; data->character = character_init((t_character_sprites *)&sprites);
data->spr = sprite_init(SPR_SNAS_DOWN);
r.data = data; r.data = data;
return (r); return (r);
} }

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:24:37 by mcolonna #+# #+# */ /* Created: 2024/03/15 15:24:37 by mcolonna #+# #+# */
/* Updated: 2024/03/15 15:26:34 by mcolonna ### ########.fr */ /* Updated: 2024/03/27 18:23:24 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,3 +24,23 @@ void point_addto(t_point *dest, t_point src)
dest->x += src.x; dest->x += src.x;
dest->y += src.y; dest->y += src.y;
} }
t_point point_fromdirection(t_direction direction)
{
if (direction == LEFT)
return (point_init(-1, 0));
if (direction == RIGHT)
return (point_init(+1, 0));
if (direction == UP)
return (point_init(0, -1));
if (direction == DOWN)
return (point_init(0, +1));
return (point_init(0, 0));
}
t_point point_multiply(t_point point, int x)
{
point.x *= x;
point.y *= x;
return (point);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */ /* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */
/* Updated: 2024/03/25 14:42:55 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 17:53:28 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -94,6 +94,35 @@ void room_draw(t_room room)
} }
} }
void room_loop(t_room room)
{
t_point pos;
t_object *object;
t_point move;
const t_memclass mc = mem_subclass(err, g_env.mc);
t_list objects_done;
objects_done = list_createempty(mc);
pos.x = 0;
while (pos.x < room.width)
{
pos.y = 0;
while (pos.y < room.height)
{
object = room.objects[pos.y * room.height + pos.x];
if (object && !isinlist(object, objects_done))
{
move = object->type.loop(object, pos);
moveobject(room, pos, move);
list_add(err, &objects_done, object);
}
pos.y++;
}
pos.x++;
}
mem_freeall(mc);
}
void room_free(t_room room) void room_free(t_room room)
{ {
mem_freeall(room.mc); mem_freeall(room.mc);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */ /* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */
/* Updated: 2024/03/15 18:55:48 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 17:54:58 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -73,3 +73,30 @@ t_roomcase *getroomcase(t_const_string path, char c)
err_perror_str(path, "unknown char"); err_perror_str(path, "unknown char");
return (NULL); return (NULL);
} }
void moveobject(t_room room, t_point start, t_point move)
{
t_point end;
end = start;
point_addto(&end, move);
if (start.x == end.x && start.y == end.y)
return ;
room.objects[end.y * room.height + end.x]
= room.objects[start.y * room.height + start.x];
room.objects[start.y * room.height + start.x] = NULL;
}
bool isinlist(void *addr, t_list list)
{
t_list_element *el;
el = list.first;
while (el)
{
if (el->value == addr)
return (true);
el = el->next;
}
return (false);
}

View file

@ -6,18 +6,19 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 22:28:52 by mcolonna #+# #+# */ /* Created: 2024/03/07 22:28:52 by mcolonna #+# #+# */
/* Updated: 2024/03/11 16:36:45 by mcolonna ### ########.fr */ /* Updated: 2024/03/28 16:02:01 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "sprite.h" #include "sprite.h"
#include "display.h" #include "display.h"
#include "error.h"
t_sprite sprite_init(t_spriteid id) t_sprite sprite_init(t_spriteid id)
{ {
t_sprite r; t_sprite r;
r.info = g_spritesmap + id; r.info = (t_spriteinfo *)(g_spritesmap + id);
r.index = 0; r.index = 0;
return (r); return (r);
} }
@ -27,7 +28,17 @@ void sprite_draw(int x, int y, t_sprite *spr)
display_draw( display_draw(
x - spr->info->origin_x, y - spr->info->origin_y, x - spr->info->origin_x, y - spr->info->origin_y,
spr->info->first_frame + spr->index); spr->info->first_frame + spr->index);
if (spr->info->type == ANIMATION)
{
spr->index++; spr->index++;
if (spr->index >= spr->info->nb_frames) if (spr->index >= spr->info->nb_frames)
spr->index = 0; spr->index = 0;
} }
}
void sprite_character_set_direction(t_sprite *spr, t_direction value)
{
if (spr->info->type != CHARACTER_STILL)
err("the sprite must be a CHARACTER_STILL sprite.");
spr->index = value;
}