feat: reorganize the code

This commit is contained in:
mcolonna 2024-04-02 14:45:03 +02:00
parent a00a02e527
commit 5103cbf709
40 changed files with 326 additions and 325 deletions

38
includes/room/character.h Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* character.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:46:05 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:46:46 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CHARACTER_H
# define CHARACTER_H
typedef struct s_character_sprites
{
t_spritesmap_id still;
t_spritesmap_id walk_left;
t_spritesmap_id walk_right;
t_spritesmap_id walk_up;
t_spritesmap_id walk_down;
} t_character_sprites;
typedef struct s_character
{
t_direction direction;
t_sprite spr;
int walk_remaining_steps;
t_character_sprites *sprites;
} t_character;
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);
#endif

33
includes/room/object.h Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* object.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:49:28 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef OBJECT_H
# define OBJECT_H
typedef struct s_object t_object;
typedef struct s_objecttype
{
t_point (*loop)(t_object *, t_point pos);
void (*draw)(t_object *, int x, int y);
} t_objecttype;
typedef struct s_object
{
t_objecttype type;
void *data;
bool solid;
} t_object;
typedef t_object (*t_object_init)(t_memclass);
#endif

32
includes/room/objects.h Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* objects.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:47:01 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:48:38 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef OBJECTS_H
# define OBJECTS_H
// SNAS
typedef struct s_snas_data
{
t_character character;
} t_snas_data;
t_object snas_init(t_memclass mc);
// WALL
typedef struct s_wall_data
{
t_sprite spr;
} t_wall_data;
t_object wall_init(t_memclass mc);
#endif

39
includes/room/room.h Normal file
View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* room.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:50:58 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROOM_H
# define ROOM_H
typedef struct s_room
{
int width;
int height;
t_sprite *surfaces;
t_object **objects;
t_memclass mc;
} t_room;
t_room room_fromfile(t_const_string path);
void room_loop(t_room room);
void room_draw(t_room room);
void room_free(t_room room);
t_object *room_getobjectfaced(
t_room room, t_character *character, t_point pos);
bool room_canwalk(
t_room room, t_character *character, t_point pos);
#endif