feat: loots of things!!! *

Added features:
- Check if the room is valid
- Pathfinding
- Firsk
- Camera
Changes:
- Borders
Dev:
- new test rooms
- ber.vim plugin
This commit is contained in:
mcolonna 2024-04-15 19:23:58 +02:00
parent b7a2d0494f
commit 9e81a59a7e
95 changed files with 8342 additions and 147 deletions

View file

@ -6,14 +6,14 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
/* Updated: 2024/04/05 18:43:19 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 16:20:07 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_ASSETS_H
# define DATA_ASSETS_H
# define NB_ASSETS 48
# define NB_ASSETS 61
typedef struct s_assetmeta
{
@ -37,7 +37,8 @@ typedef enum e_assetsmap_id
{
FLOOR_1,
FLOOR_2,
WALL_BORDER,
WALL_BORDER_TOP,
WALL_BORDER_BOTTOM,
WALL_INNER,
OBJECT_SNAS_DOWN,
OBJECT_SNAS_UP,
@ -55,10 +56,6 @@ typedef enum e_assetsmap_id
OBJECT_SNAS_WALK_UP_2,
OBJECT_SNAS_WALK_UP_3,
OBJECT_SNAS_WALK_UP_4,
OBJECT_FIRSK_DOWN,
OBJECT_FIRST_UP,
OBJECT_FIRST_LEFT,
OBJECT_FIRSK_RIGHT,
OBJECT_KETCHUP_STILL_1,
OBJECT_KETCHUP_STILL_2,
OBJECT_KETCHUP_STILL_3,
@ -82,7 +79,23 @@ typedef enum e_assetsmap_id
OBJECT_EXIT_USING2_4,
OBJECT_EXIT_USING2_5,
OBJECT_EXIT_USING2_6,
OBJECT_EXIT_USING2_7
OBJECT_EXIT_USING2_7,
OBJECT_FIRSK_DOWN,
OBJECT_FIRSK_UP,
OBJECT_FIRSK_LEFT,
OBJECT_FIRSK_RIGHT,
OBJECT_FIRSK_WALK_DOWN_1,
OBJECT_FIRSK_WALK_DOWN_2,
OBJECT_FIRSK_WALK_DOWN_3,
OBJECT_FIRSK_WALK_DOWN_4,
OBJECT_FIRSK_WALK_RIGHT_1,
OBJECT_FIRSK_WALK_RIGHT_2,
OBJECT_FIRSK_WALK_LEFT_1,
OBJECT_FIRSK_WALK_LEFT_2,
OBJECT_FIRSK_WALK_UP_1,
OBJECT_FIRSK_WALK_UP_2,
OBJECT_FIRSK_WALK_UP_3,
OBJECT_FIRSK_WALK_UP_4,
} t_assetsmap_id;
# define OBJECT_SNAS OBJECT_SNAS_DOWN

View file

@ -6,14 +6,14 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
/* Updated: 2024/04/08 15:30:53 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 16:22:44 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DATA_SPRITES_H
# define DATA_SPRITES_H
# define NB_SPRITES 14
# define NB_SPRITES 20
typedef enum e_spritetype
{
@ -36,7 +36,8 @@ extern const t_spritemeta g_spritesmap[NB_SPRITES];
typedef enum e_spritesmap_id
{
CASE_WALL,
CASE_BORDER_TOP,
CASE_BORDER_BOTTOM,
CASE_FLOOR_1,
CASE_FLOOR_2,
SPR_SNAS,
@ -50,6 +51,11 @@ typedef enum e_spritesmap_id
SPR_EXIT_INACTIVE,
SPR_EXIT_ACTIVE,
SPR_EXIT_USING,
SPR_FIRSK,
SPR_FIRSK_WALK_DOWN,
SPR_FIRSK_WALK_UP,
SPR_FIRSK_WALK_RIGHT,
SPR_FIRSK_WALK_LEFT,
} t_spritesmap_id;
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:26:51 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 17:15:31 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,9 +35,9 @@ void display_erase(void);
/**
* Draw an image somewhere in the window.
* You must call display_flush() after drawing all images.
* x,y is the top-left position of the image.
* p is the top-left position of the image.
*/
void display_draw(int x, int y, t_assetsmap_id asset);
void display_draw(t_point p, t_assetsmap_id asset);
/**
* Draw all the screen in the buffer.

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */
/* Updated: 2024/04/03 15:56:22 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 17:06:52 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ typedef struct s_sprite
t_sprite sprite_init(t_spritesmap_id spr);
// Return false only if the image drawn was the last (end of the animation).
bool sprite_draw(int x, int y, t_sprite *spr);
bool sprite_draw(t_point p, t_sprite *spr);
void sprite_character_set_direction(t_sprite *spr, t_direction value);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 13:53:41 by mcolonna #+# #+# */
/* Updated: 2024/04/03 15:56:53 by mcolonna ### ########.fr */
/* Updated: 2024/04/15 17:41:18 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,6 +28,7 @@
# include "utils/direction.h"
# include "utils/point.h"
# include "utils/map.h"
# include "display/pixel.h"
# include "display/data_assets.h"
@ -40,6 +41,8 @@
# include "room/character.h"
# include "room/objects.h"
# include "room/room.h"
# include "room/camera.h"
# include "room/pathfinding.h"
# include "main/env.h"
# include "main/error.h"

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
/* Updated: 2024/04/08 16:23:27 by mcolonna ### ########.fr */
/* Updated: 2024/04/15 18:01:07 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,6 @@
# define WINDOW_HEIGHT 400
# define WINDOW_TITLE "undretale"
# define FPS 20
# define WALK_STEPS_NB 4
typedef struct s_env
{
@ -29,6 +28,7 @@ typedef struct s_env
int ketchup;
int max_ketchup;
int moves;
t_camera camera;
} t_env;
extern t_env g_env;

25
includes/room/camera.h Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* camera.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/11 16:31:42 by mcolonna #+# #+# */
/* Updated: 2024/04/11 17:56:43 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CAMERA_H
# define CAMERA_H
# include "includes.h"
typedef struct s_camera
{
t_point pos;
} t_camera;
void camera_sync(void);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:46:05 by mcolonna #+# #+# */
/* Updated: 2024/04/02 17:46:46 by mcolonna ### ########.fr */
/* Updated: 2024/04/15 17:58:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,12 +27,13 @@ typedef struct s_character
t_direction direction;
t_sprite spr;
int walk_remaining_steps;
int walk_steps_nb;
t_character_sprites *sprites;
} t_character;
void character_draw(t_character *character, int x, int y);
void character_draw(t_character *character, t_point p);
t_point character_loop(t_character *character, t_point pos,
t_direction (*brain)(void));
t_character character_init(t_character_sprites *sprites);
t_direction (*brain)(t_point));
t_character character_init(t_character_sprites *sprites, int walk_steps_nb);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
/* Updated: 2024/04/09 14:34:13 by mcolonna ### ########.fr */
/* Updated: 2024/04/15 17:42:06 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,8 +21,9 @@ typedef t_object (*t_object_init)(t_memclass);
typedef struct s_objecttype
{
t_object_init init;
bool solid;
t_point (*loop)(t_object *, t_point pos);
void (*draw)(t_object *, int x, int y);
void (*draw)(t_object *, t_point p);
// Called when a character want to walk through this object.
// Returns false to block the character. If true, it will pass.
// If walk_through is NULL, the character is blocked.

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:47:01 by mcolonna #+# #+# */
/* Updated: 2024/04/08 15:22:05 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 13:54:23 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,6 +44,14 @@ typedef struct s_exit_data
bool active;
} t_exit_data;
// FIRSK
typedef struct s_firsk_data
{
t_character character;
} t_firsk_data;
t_object firsk_init(t_memclass mc);
t_object exit_init(t_memclass mc);
#endif

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pathfinding.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/10 18:13:05 by mcolonna #+# #+# */
/* Updated: 2024/04/12 17:50:50 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PATHFINDING_H
# define PATHFINDING_H
# include "includes.h"
t_direction pathfinding(t_point start, t_point finish);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
/* Updated: 2024/04/09 14:22:51 by mcolonna ### ########.fr */
/* Updated: 2024/04/15 17:50:29 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,4 +37,6 @@ t_object *room_getobjectfaced(
bool room_canwalk(
t_room room, t_character *character, t_point pos);
t_point room_find(t_object_init objtype);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 15:34:18 by mcolonna #+# #+# */
/* Updated: 2024/04/03 15:51:14 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 17:07:59 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@ typedef struct s_visual
t_sprite spr;
} t_visual;
void visual_loop(t_visual **visual, int x, int y);
void visual_loop(t_visual **visual, t_point p);
void visual_addtoroom(t_spritesmap_id sprid, t_point pos);
#endif

27
includes/utils/map.h Normal file
View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/12 19:14:26 by mcolonna #+# #+# */
/* Updated: 2024/04/15 16:36:45 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAP_H
# define MAP_H
typedef struct s_map
{
t_point dim;
void **cases;
} t_map;
t_map map_init(t_memclass mc, t_point dim);
void **map_at(t_map *map, t_point p);
void map_foreach(t_map *map, void (*f)(t_point p, void **el, void *arg),
void *arg);
#endif

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 15:05:03 by mcolonna #+# #+# */
/* Updated: 2024/04/02 14:39:41 by mcolonna ### ########.fr */
/* Updated: 2024/04/11 18:05:53 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,8 +20,10 @@ typedef struct s_point
} t_point;
t_point point_init(int x, int y);
t_point point_add(t_point point, int x);
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);
t_point point_subpoint(t_point p1, t_point p2);
#endif