feat: reorganize the code
This commit is contained in:
parent
a00a02e527
commit
5103cbf709
40 changed files with 326 additions and 325 deletions
17
Makefile
17
Makefile
|
@ -2,11 +2,18 @@
|
|||
NAME = so_long
|
||||
SRCS = src/
|
||||
INCLUDES = includes/
|
||||
CODE = main error env input timedloop \
|
||||
data_assets data_sprites \
|
||||
display1 display2 display_utils sprite \
|
||||
room1 room2 room_utils1 room_utils2 point \
|
||||
object_character object_snas object_wall
|
||||
CODE = $(addprefix main/, \
|
||||
main error env input timedloop \
|
||||
) \
|
||||
$(addprefix display/, \
|
||||
data_assets data_sprites \
|
||||
display1 display2 display_utils sprite \
|
||||
) \
|
||||
$(addprefix room/, \
|
||||
room1 room2 room_utils1 room_utils2 \
|
||||
object_character object_snas object_wall \
|
||||
) \
|
||||
utils/point
|
||||
LIBRARIES = mlx libtf
|
||||
LIBRARIES_FILES = libtf/libtf.a
|
||||
LIBRARIES_LINK = mlx
|
||||
|
|
49
dev/map.md
49
dev/map.md
|
@ -1,49 +0,0 @@
|
|||
/!\ NEEDS UPDATE
|
||||
|
||||
data\_assets
|
||||
- `NB_ASSETS`
|
||||
- `t_assetinfo`
|
||||
- `g_assetsmap`
|
||||
- `t_assetid`...
|
||||
- `t_direction`
|
||||
- `t_pixel`
|
||||
- `t_component`
|
||||
data\_sprites
|
||||
- `NB_SPRITES`
|
||||
- `t_spriteinfo`
|
||||
- `t_spritesmap`
|
||||
- `t_spriteid`
|
||||
display
|
||||
- `t_image`
|
||||
- `display_init()`
|
||||
- `display_erase()`
|
||||
- `display_draw()`
|
||||
- `display_flush()`
|
||||
- `display_destroyall()`
|
||||
env
|
||||
- `WINDOW_WIDTH`
|
||||
- `WINDOW_HEIGHT`
|
||||
- `WINDOW_TITLE`
|
||||
- `t_env`
|
||||
- `g_env`
|
||||
error
|
||||
- `err()`
|
||||
- `err_perror()`
|
||||
- `finish()`
|
||||
room
|
||||
- `t_surface`...
|
||||
- `t_object`
|
||||
- `t_room`
|
||||
- `t_roomcase`
|
||||
- `room_fromfile()`
|
||||
- `room_draw()`
|
||||
- `room_free()`
|
||||
sprite
|
||||
- `t_sprite`
|
||||
- `sprite_init()`
|
||||
- `sprite_draw()`
|
||||
main
|
||||
- `main()`
|
||||
- `expose_hook()`
|
||||
- `close_hook()`
|
||||
- `loop_hook()`
|
|
@ -6,22 +6,16 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/29 17:43:01 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/28 15:09:30 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:27:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DATA_ASSETS_H
|
||||
# define DATA_ASSETS_H
|
||||
|
||||
# include <stdint.h>
|
||||
# include "libtf.h"
|
||||
|
||||
# define NB_ASSETS 36
|
||||
|
||||
typedef uint32_t t_pixel;
|
||||
typedef uint8_t t_component;
|
||||
|
||||
typedef struct s_asset
|
||||
typedef struct s_assetmeta
|
||||
{
|
||||
t_const_string src;
|
||||
int limit_left;
|
||||
|
@ -29,9 +23,9 @@ typedef struct s_asset
|
|||
int limit_up;
|
||||
int limit_down;
|
||||
bool opaque;
|
||||
} t_assetinfo;
|
||||
} t_assetmeta;
|
||||
|
||||
extern const t_assetinfo g_assetsmap[NB_ASSETS];
|
||||
extern const t_assetmeta g_assetsmap[NB_ASSETS];
|
||||
|
||||
/**
|
||||
* Index for each asset. Must be in the same order than g_assetsmap.
|
||||
|
@ -39,7 +33,7 @@ extern const t_assetinfo g_assetsmap[NB_ASSETS];
|
|||
* The images of an object with directions must be in this order:
|
||||
* down, up, left, right
|
||||
*/
|
||||
typedef enum e_assetid
|
||||
typedef enum e_assetsmap_id
|
||||
{
|
||||
FLOOR_1,
|
||||
FLOOR_2,
|
||||
|
@ -77,16 +71,7 @@ typedef enum e_assetid
|
|||
OBJECT_EXIT_USING2_5,
|
||||
OBJECT_EXIT_USING2_6,
|
||||
OBJECT_EXIT_USING2_7
|
||||
} t_assetid;
|
||||
|
||||
typedef enum e_direction
|
||||
{
|
||||
DOWN,
|
||||
UP,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
NO_DIRECTION
|
||||
} t_direction;
|
||||
} t_assetsmap_id;
|
||||
|
||||
# define OBJECT_SNAS OBJECT_SNAS_DOWN
|
||||
# define OBJECT_FIRSK OBJECT_FIRSK_DOWN
|
|
@ -6,35 +6,33 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 15:56:31 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:43:24 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:38:37 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DATA_SPRITES_H
|
||||
# define DATA_SPRITES_H
|
||||
|
||||
# include "data_assets.h"
|
||||
|
||||
# define NB_SPRITES 9
|
||||
|
||||
typedef enum e_assettype
|
||||
typedef enum e_spritetype
|
||||
{
|
||||
ANIMATION, // loops through all the sprites
|
||||
CHARACTER_STILL, // down up left and right positions
|
||||
} t_assettype;
|
||||
} t_spritetype;
|
||||
|
||||
typedef struct s_spriteinfo
|
||||
typedef struct s_spritemeta
|
||||
{
|
||||
t_assetid first_frame;
|
||||
int nb_frames;
|
||||
int origin_x;
|
||||
int origin_y;
|
||||
t_assettype type;
|
||||
} t_spriteinfo;
|
||||
t_assetsmap_id first_frame;
|
||||
int nb_frames;
|
||||
int origin_x;
|
||||
int origin_y;
|
||||
t_spritetype type;
|
||||
} t_spritemeta;
|
||||
|
||||
extern const t_spriteinfo g_spritesmap[NB_SPRITES];
|
||||
extern const t_spritemeta g_spritesmap[NB_SPRITES];
|
||||
|
||||
typedef enum e_spriteid
|
||||
typedef enum e_spritesmap_id
|
||||
{
|
||||
CASE_WALL,
|
||||
CASE_FLOOR_1,
|
||||
|
@ -45,6 +43,6 @@ typedef enum e_spriteid
|
|||
SPR_SNAS_LEFT,
|
||||
SPR_SNAS_RIGHT,
|
||||
SPR_WALL,
|
||||
} t_spriteid;
|
||||
} t_spritesmap_id;
|
||||
|
||||
#endif
|
|
@ -6,22 +6,18 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 14:32:08 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/11 15:53:57 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:26:51 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DISPLAY_H
|
||||
# define DISPLAY_H
|
||||
|
||||
# include <stdint.h>
|
||||
# include "libtf.h"
|
||||
# include "data_assets.h"
|
||||
|
||||
typedef struct s_image
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
t_assetinfo asset;
|
||||
t_assetmeta asset;
|
||||
void *img;
|
||||
t_pixel *data;
|
||||
} t_image;
|
||||
|
@ -41,7 +37,7 @@ void display_erase(void);
|
|||
* You must call display_flush() after drawing all images.
|
||||
* x,y is the top-left position of the image.
|
||||
*/
|
||||
void display_draw(int x, int y, t_assetid asset);
|
||||
void display_draw(int x, int y, t_assetsmap_id asset);
|
||||
|
||||
/**
|
||||
* Draw all the screen in the buffer.
|
19
includes/display/pixel.h
Normal file
19
includes/display/pixel.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pixel.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:17:44 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:18:22 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PIXEL_H
|
||||
# define PIXEL_H
|
||||
|
||||
typedef uint32_t t_pixel;
|
||||
typedef uint8_t t_component;
|
||||
|
||||
#endif
|
|
@ -6,23 +6,20 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 22:13:20 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/28 15:59:30 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:37:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SPRITE_H
|
||||
# define SPRITE_H
|
||||
|
||||
# include "data_assets.h"
|
||||
# include "data_sprites.h"
|
||||
|
||||
typedef struct s_sprite
|
||||
{
|
||||
t_spriteinfo *info;
|
||||
t_spritemeta *meta;
|
||||
int index;
|
||||
} t_sprite;
|
||||
|
||||
t_sprite sprite_init(t_spriteid spr);
|
||||
t_sprite sprite_init(t_spritesmap_id spr);
|
||||
|
||||
void sprite_draw(int x, int y, t_sprite *spr);
|
||||
|
49
includes/includes.h
Normal file
49
includes/includes.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* includes.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 13:53:41 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 18:26:03 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INCLUDES_H
|
||||
# define INCLUDES_H
|
||||
|
||||
# include <fcntl.h>
|
||||
# include <time.h>
|
||||
# include <stdbool.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <stddef.h>
|
||||
# include <stdint.h>
|
||||
# include <X11/keysym.h>
|
||||
# include <X11/Xlib.h>
|
||||
# include <errno.h>
|
||||
# include "libtf.h"
|
||||
# include "mlx.h"
|
||||
|
||||
# include "utils/direction.h"
|
||||
# include "utils/point.h"
|
||||
|
||||
# include "display/pixel.h"
|
||||
# include "display/data_assets.h"
|
||||
# include "display/data_sprites.h"
|
||||
# include "display/display.h"
|
||||
# include "display/sprite.h"
|
||||
|
||||
# include "room/object.h"
|
||||
# include "room/character.h"
|
||||
# include "room/objects.h"
|
||||
# include "room/room.h"
|
||||
|
||||
# include "main/env.h"
|
||||
# include "main/error.h"
|
||||
# include "main/input.h"
|
||||
# include "main/timedloop.h"
|
||||
# include "main/main.h"
|
||||
|
||||
#endif
|
|
@ -6,16 +6,13 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:26:13 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 18:27:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:39:26 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ENV_H
|
||||
# define ENV_H
|
||||
|
||||
# include "libtf.h"
|
||||
# include "room.h"
|
||||
|
||||
# define WINDOW_WIDTH 600
|
||||
# define WINDOW_HEIGHT 400
|
||||
# define WINDOW_TITLE "undretale"
|
|
@ -6,18 +6,16 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 16:04:31 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/11 13:23:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:04:00 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ERROR_H
|
||||
# define ERROR_H
|
||||
|
||||
# include "libtf.h"
|
||||
|
||||
void err(t_const_string msg);
|
||||
void err_perror(t_const_string s);
|
||||
void err_perror_str(t_const_string s, t_const_string msg);
|
||||
void finish(void);
|
||||
void error_err(t_const_string msg);
|
||||
void error_perror(t_const_string s);
|
||||
void error_str(t_const_string s, t_const_string msg);
|
||||
void success(void);
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/26 12:16:32 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 18:32:38 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:39:38 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
18
includes/main/main.h
Normal file
18
includes/main/main.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 13:39:54 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 14:39:40 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
|
||||
int main(void);
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/26 15:02:16 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/26 15:02:50 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:39:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
|
@ -1,50 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* object.h :+: :+: :+: */
|
||||
/* character.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 14:58:25 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 15:29:58 by mcolonna ### ########.fr */
|
||||
/* Created: 2024/04/02 17:46:05 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:46:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef OBJECT_H
|
||||
# define OBJECT_H
|
||||
#ifndef CHARACTER_H
|
||||
# define CHARACTER_H
|
||||
|
||||
# include "point.h"
|
||||
# include "data_assets.h"
|
||||
# include "libtf.h"
|
||||
# include "display.h"
|
||||
# include "sprite.h"
|
||||
|
||||
/**** OBJECT ****/
|
||||
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);
|
||||
|
||||
/**** 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_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
|
||||
|
@ -60,20 +35,4 @@ 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);
|
||||
|
||||
/**** WALL ****/
|
||||
typedef struct s_wall_data
|
||||
{
|
||||
t_sprite spr;
|
||||
} t_wall_data;
|
||||
|
||||
t_object wall_init(t_memclass mc);
|
||||
|
||||
#endif
|
33
includes/room/object.h
Normal file
33
includes/room/object.h
Normal 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
32
includes/room/objects.h
Normal 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
|
|
@ -6,17 +6,13 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:00:45 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:42:52 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:50:58 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ROOM_H
|
||||
# define ROOM_H
|
||||
|
||||
# include "sprite.h"
|
||||
# include "libtf.h"
|
||||
# include "object.h"
|
||||
|
||||
typedef struct s_room
|
||||
{
|
||||
int width;
|
||||
|
@ -26,12 +22,6 @@ typedef struct s_room
|
|||
t_memclass mc;
|
||||
} t_room;
|
||||
|
||||
typedef struct s_roomcase
|
||||
{
|
||||
char c;
|
||||
t_object_init object;
|
||||
} t_roomcase;
|
||||
|
||||
t_room room_fromfile(t_const_string path);
|
||||
|
||||
void room_loop(t_room room);
|
25
includes/utils/direction.h
Normal file
25
includes/utils/direction.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* direction.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:28:40 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 17:28:56 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DIRECTION_H
|
||||
# define DIRECTION_H
|
||||
|
||||
typedef enum e_direction
|
||||
{
|
||||
DOWN,
|
||||
UP,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
NO_DIRECTION
|
||||
} t_direction;
|
||||
|
||||
#endif
|
|
@ -6,15 +6,13 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:05:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/27 18:22:51 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:39:41 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINT_H
|
||||
# define POINT_H
|
||||
|
||||
# include "data_assets.h"
|
||||
|
||||
typedef struct s_point
|
||||
{
|
||||
int x;
|
|
@ -6,16 +6,16 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 16:27:06 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/11 15:54:15 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:27:27 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "data_assets.h"
|
||||
#include "includes.h"
|
||||
|
||||
/**
|
||||
* Path of each asset relative to assets/, without extension.
|
||||
*/
|
||||
const t_assetinfo g_assetsmap[NB_ASSETS] = {
|
||||
const t_assetmeta g_assetsmap[NB_ASSETS] = {
|
||||
{"floor/1", 50, 100, 50, 100, true},
|
||||
{"floor/2", 50, 100, 50, 100, true},
|
||||
// WALL
|
|
@ -6,13 +6,13 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/11 16:02:29 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:39:30 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:37:34 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "data_sprites.h"
|
||||
#include "includes.h"
|
||||
|
||||
const t_spriteinfo g_spritesmap[NB_SPRITES] = {
|
||||
const t_spritemeta g_spritesmap[NB_SPRITES] = {
|
||||
{WALL_BORDER, 1, 50, 50, ANIMATION},
|
||||
{FLOOR_1, 1, 50, 50, ANIMATION},
|
||||
{FLOOR_2, 1, 50, 50, ANIMATION},
|
|
@ -6,17 +6,12 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/11 13:03:37 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:03:21 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "display.h"
|
||||
#include "includes.h"
|
||||
#include "display_utils.h"
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "mlx.h"
|
||||
#include "libtf.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void display_init(void)
|
||||
{
|
||||
|
@ -30,7 +25,7 @@ void display_init(void)
|
|||
}
|
||||
g_screenbuf.img = mlx_new_image(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
if (!g_screenbuf.img)
|
||||
err("on mlx_new_image()");
|
||||
error_err("on mlx_new_image()");
|
||||
g_screenbuf.width = WINDOW_WIDTH;
|
||||
g_screenbuf.height = WINDOW_HEIGHT;
|
||||
g_screenbuf.data = get_data_addr(g_screenbuf.img);
|
|
@ -6,17 +6,12 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/06 13:40:18 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:43:34 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "display.h"
|
||||
#include "includes.h"
|
||||
#include "display_utils.h"
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "mlx.h"
|
||||
#include "libtf.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline void add_color(t_pixel *dest, t_pixel src)
|
||||
{
|
||||
|
@ -98,7 +93,7 @@ static inline void display_draw_opaque(int x, int y, t_image img)
|
|||
}
|
||||
}
|
||||
|
||||
void display_draw(int x, int y, t_assetid asset)
|
||||
void display_draw(int x, int y, t_assetsmap_id asset)
|
||||
{
|
||||
const t_image img = g_allassets[asset];
|
||||
|
|
@ -6,14 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/06 13:03:30 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/06 13:48:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:03:15 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "display_utils.h"
|
||||
#include "mlx.h"
|
||||
#include "error.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
t_image g_allassets[NB_ASSETS];
|
||||
t_image g_screenbuf;
|
||||
|
@ -27,7 +24,7 @@ t_pixel *get_data_addr(void *img)
|
|||
|
||||
r = (t_pixel *)mlx_get_data_addr(img, &bpp, &size_line, &endian);
|
||||
if (!r || bpp != 32 || endian != 0)
|
||||
err("wrong image format");
|
||||
error_err("wrong image format");
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
@ -50,17 +47,17 @@ void load_xpm_file_with_alpha(int i)
|
|||
t_string src_mask;
|
||||
void *mask;
|
||||
|
||||
tmp = str_join(err, g_env.mc, "assets/", g_assetsmap[i].src);
|
||||
src = str_join(err, g_env.mc, tmp, ".xpm");
|
||||
src_mask = str_join(err, g_env.mc, tmp, ".alpha.xpm");
|
||||
tmp = str_join(error_err, g_env.mc, "assets/", g_assetsmap[i].src);
|
||||
src = str_join(error_err, g_env.mc, tmp, ".xpm");
|
||||
src_mask = str_join(error_err, g_env.mc, tmp, ".alpha.xpm");
|
||||
g_allassets[i].img = mlx_xpm_file_to_image(g_env.mlx, src,
|
||||
&(g_allassets[i].width), &g_allassets[i].height);
|
||||
if (!g_allassets[i].img)
|
||||
err("image loading failed");
|
||||
error_err("image loading failed");
|
||||
mask = mlx_xpm_file_to_image(g_env.mlx, src_mask,
|
||||
&(g_allassets[i].width), &g_allassets[i].height);
|
||||
if (!mask)
|
||||
err("image loading failed");
|
||||
error_err("image loading failed");
|
||||
apply_mask_to_image(g_allassets[i].img, mask,
|
||||
g_allassets[i].width * g_allassets[i].height);
|
||||
mlx_destroy_image(g_env.mlx, mask);
|
|
@ -6,15 +6,13 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/06 12:59:24 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/06 13:47:02 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:39:19 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DISPLAY_UTILS_H
|
||||
# define DISPLAY_UTILS_H
|
||||
|
||||
# include "display.h"
|
||||
|
||||
extern t_image g_allassets[NB_ASSETS];
|
||||
extern t_image g_screenbuf;
|
||||
|
|
@ -6,19 +6,17 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 22:28:52 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/28 16:02:01 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:02:35 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "sprite.h"
|
||||
#include "display.h"
|
||||
#include "error.h"
|
||||
#include "includes.h"
|
||||
|
||||
t_sprite sprite_init(t_spriteid id)
|
||||
t_sprite sprite_init(t_spritesmap_id id)
|
||||
{
|
||||
t_sprite r;
|
||||
|
||||
r.info = (t_spriteinfo *)(g_spritesmap + id);
|
||||
r.meta = (t_spritemeta *)(g_spritesmap + id);
|
||||
r.index = 0;
|
||||
return (r);
|
||||
}
|
||||
|
@ -26,19 +24,19 @@ t_sprite sprite_init(t_spriteid id)
|
|||
void sprite_draw(int x, int y, t_sprite *spr)
|
||||
{
|
||||
display_draw(
|
||||
x - spr->info->origin_x, y - spr->info->origin_y,
|
||||
spr->info->first_frame + spr->index);
|
||||
if (spr->info->type == ANIMATION)
|
||||
x - spr->meta->origin_x, y - spr->meta->origin_y,
|
||||
spr->meta->first_frame + spr->index);
|
||||
if (spr->meta->type == ANIMATION)
|
||||
{
|
||||
spr->index++;
|
||||
if (spr->index >= spr->info->nb_frames)
|
||||
if (spr->index >= spr->meta->nb_frames)
|
||||
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.");
|
||||
if (spr->meta->type != CHARACTER_STILL)
|
||||
error_err("the sprite must be a CHARACTER_STILL sprite.");
|
||||
spr->index = value;
|
||||
}
|
|
@ -6,10 +6,10 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 16:32:36 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/02/27 16:42:22 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:41:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
t_env g_env;
|
|
@ -6,17 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 16:05:21 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/11 13:37:12 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:56:31 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "error.h"
|
||||
#include "libtf.h"
|
||||
#include "display.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
static void end(int no)
|
||||
{
|
||||
|
@ -25,7 +19,7 @@ static void end(int no)
|
|||
exit(no);
|
||||
}
|
||||
|
||||
void err(t_const_string msg)
|
||||
void error_err(t_const_string msg)
|
||||
{
|
||||
print_line(err_remember, 2, "Error");
|
||||
if (str_eq(msg, "errno"))
|
||||
|
@ -35,7 +29,7 @@ void err(t_const_string msg)
|
|||
end(1);
|
||||
}
|
||||
|
||||
void err_perror(t_const_string s)
|
||||
void error_perror(t_const_string s)
|
||||
{
|
||||
print_line(err_remember, 2, "Error");
|
||||
print_str(err_remember, 2, s);
|
||||
|
@ -44,7 +38,7 @@ void err_perror(t_const_string s)
|
|||
end(1);
|
||||
}
|
||||
|
||||
void err_perror_str(t_const_string s, t_const_string msg)
|
||||
void error_str(t_const_string s, t_const_string msg)
|
||||
{
|
||||
print_line(err_remember, 2, "Error");
|
||||
print_str(err_remember, 2, s);
|
||||
|
@ -53,7 +47,7 @@ void err_perror_str(t_const_string s, t_const_string msg)
|
|||
end(1);
|
||||
}
|
||||
|
||||
void finish(void)
|
||||
void success(void)
|
||||
{
|
||||
end(0);
|
||||
}
|
|
@ -6,14 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/26 12:26:17 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 18:32:27 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:41:14 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "error.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include <X11/keysym.h>
|
||||
#include "includes.h"
|
||||
|
||||
static int g_input_i = 0;
|
||||
static bool g_to_unpress[4] = {false, false, false, false};
|
|
@ -6,19 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/26 15:28:34 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 18:33:10 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:04:18 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "mlx.h"
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "display.h"
|
||||
#include "data_assets.h"
|
||||
#include "room.h"
|
||||
#include "input.h"
|
||||
#include "timedloop.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include "includes.h"
|
||||
|
||||
int expose_hook(void)
|
||||
{
|
||||
|
@ -29,7 +21,7 @@ int expose_hook(void)
|
|||
int close_hook(void)
|
||||
{
|
||||
mlx_do_key_autorepeaton(g_env.mlx);
|
||||
finish();
|
||||
success();
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -50,15 +42,15 @@ int loop_hook(void)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
g_env.mc = mem_newclass(err);
|
||||
g_env.mc = mem_newclass(error_err);
|
||||
g_env.mlx = mlx_init();
|
||||
if (!g_env.mlx)
|
||||
err("mlx_init() failed");
|
||||
error_err("mlx_init() failed");
|
||||
display_init();
|
||||
g_env.win = mlx_new_window(g_env.mlx, WINDOW_WIDTH, WINDOW_HEIGHT,
|
||||
WINDOW_TITLE);
|
||||
if (!g_env.win)
|
||||
err("mlx_new_window() failed");
|
||||
error_err("mlx_new_window() failed");
|
||||
g_env.room = room_fromfile("room/room.ber");
|
||||
room_draw(g_env.room);
|
||||
mlx_expose_hook(g_env.win, expose_hook, NULL);
|
|
@ -6,12 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/26 14:54:49 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/26 15:51:04 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:41:31 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <time.h>
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
static long get_nanos(void)
|
||||
{
|
|
@ -6,19 +6,15 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 15:51:38 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:35:56 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "object.h"
|
||||
#include "error.h"
|
||||
#include "sprite.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
static void character_initstate(t_character *character)
|
||||
{
|
||||
const t_spriteid walk_sprites[] = {
|
||||
const t_spritesmap_id walk_sprites[] = {
|
||||
character->sprites->walk_down,
|
||||
character->sprites->walk_up,
|
||||
character->sprites->walk_left,
|
|
@ -6,15 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 18:29:12 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:02:48 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "object.h"
|
||||
#include "error.h"
|
||||
#include "sprite.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
static t_direction snas_brain(void)
|
||||
{
|
||||
|
@ -55,7 +51,7 @@ t_object snas_init(t_memclass mc)
|
|||
t_snas_data *data;
|
||||
|
||||
r.type = type;
|
||||
data = mem_alloc(err, mc, sizeof(t_snas_data));
|
||||
data = mem_alloc(error_err, mc, sizeof(t_snas_data));
|
||||
data->character = character_init((t_character_sprites *)&sprites);
|
||||
r.data = data;
|
||||
r.solid = true;
|
|
@ -6,15 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:27:03 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 15:52:32 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:02:25 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "object.h"
|
||||
#include "error.h"
|
||||
#include "sprite.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
|
||||
static t_point wall_loop(t_object *obj, t_point pos)
|
||||
{
|
||||
|
@ -36,7 +32,7 @@ t_object wall_init(t_memclass mc)
|
|||
t_wall_data *data;
|
||||
|
||||
r.type = type;
|
||||
data = mem_alloc(err, mc, sizeof(t_wall_data));
|
||||
data = mem_alloc(error_err, mc, sizeof(t_wall_data));
|
||||
data->spr = sprite_init(SPR_WALL);
|
||||
r.data = data;
|
||||
r.solid = true;
|
|
@ -6,15 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:42:18 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 18:28:28 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "room.h"
|
||||
#include "error.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
#include "room_utils.h"
|
||||
|
||||
static bool room_fromfile2(
|
||||
|
@ -22,11 +18,11 @@ static bool room_fromfile2(
|
|||
{
|
||||
t_const_string line;
|
||||
t_roomcase *roomcase;
|
||||
const t_memclass mc = mem_subclass(err, g_env.mc);
|
||||
const t_memclass mc = mem_subclass(error_err, g_env.mc);
|
||||
|
||||
line = read_line(err_remember, mc, fd);
|
||||
if (err_get())
|
||||
err_perror(path);
|
||||
error_perror(path);
|
||||
if (!line)
|
||||
return (false);
|
||||
while (*line && *line != '\n')
|
||||
|
@ -34,7 +30,8 @@ static bool room_fromfile2(
|
|||
roomcase = getroomcase(path, *line);
|
||||
if (roomcase->object)
|
||||
{
|
||||
room->objects[*i] = mem_alloc(err, room->mc, sizeof(t_object));
|
||||
room->objects[*i] = mem_alloc(error_err, room->mc,
|
||||
sizeof(t_object));
|
||||
*(room->objects[*i]) = roomcase->object(room->mc);
|
||||
}
|
||||
else
|
||||
|
@ -50,16 +47,18 @@ t_room room_fromfile(t_const_string path)
|
|||
{
|
||||
t_room r;
|
||||
int fd;
|
||||
const t_memclass mc = mem_subclass(err, g_env.mc);
|
||||
const t_memclass mc = mem_subclass(error_err, g_env.mc);
|
||||
int i;
|
||||
|
||||
room_getsize(mc, &r, path);
|
||||
r.mc = mem_subclass(err, g_env.mc);
|
||||
r.mc = mem_subclass(error_err, g_env.mc);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
err_perror(path);
|
||||
r.surfaces = mem_alloc(err, r.mc, r.width * r.height * sizeof(t_sprite));
|
||||
r.objects = mem_alloc(err, r.mc, r.width * r.height * sizeof(t_object *));
|
||||
error_perror(path);
|
||||
r.surfaces = mem_alloc(error_err, r.mc, r.width * r.height
|
||||
* sizeof(t_sprite));
|
||||
r.objects = mem_alloc(error_err, r.mc, r.width * r.height
|
||||
* sizeof(t_object *));
|
||||
i = 0;
|
||||
while (room_fromfile2(fd, path, &i, &r))
|
||||
;
|
||||
|
@ -99,7 +98,7 @@ 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);
|
||||
const t_memclass mc = mem_subclass(error_err, g_env.mc);
|
||||
t_list objects_done;
|
||||
|
||||
objects_done = list_createempty(mc);
|
||||
|
@ -114,7 +113,7 @@ void room_loop(t_room room)
|
|||
{
|
||||
move = object->type.loop(object, pos);
|
||||
moveobject(room, pos, move);
|
||||
list_add(err, &objects_done, object);
|
||||
list_add(error_err, &objects_done, object);
|
||||
}
|
||||
pos.y++;
|
||||
}
|
|
@ -6,15 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/07 23:31:22 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/29 17:32:47 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:44:12 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "room.h"
|
||||
#include "error.h"
|
||||
#include "libtf.h"
|
||||
#include "env.h"
|
||||
#include "includes.h"
|
||||
#include "room_utils.h"
|
||||
|
||||
t_object *room_getobjectfaced(
|
|
@ -6,15 +6,18 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/13 16:34:01 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:32:46 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:51:05 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ROOM_UTILS_H
|
||||
# define ROOM_UTILS_H
|
||||
|
||||
# include "libtf.h"
|
||||
# include "room.h"
|
||||
typedef struct s_roomcase
|
||||
{
|
||||
char c;
|
||||
t_object_init object;
|
||||
} t_roomcase;
|
||||
|
||||
int getlinelen(t_const_string line);
|
||||
void room_getsize(t_memclass mc, t_room *r, t_const_string path);
|
|
@ -6,14 +6,12 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/13 16:26:28 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:44:30 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:58:59 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "includes.h"
|
||||
#include "room_utils.h"
|
||||
#include "error.h"
|
||||
#include "object.h"
|
||||
|
||||
static t_roomcase g_roomcases[] = {
|
||||
{c: '0', object: NULL},
|
||||
|
@ -39,23 +37,23 @@ void room_getsize(t_memclass mc, t_room *r, t_const_string path)
|
|||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
err_perror(path);
|
||||
error_perror(path);
|
||||
line = read_line(err_remember, mc, fd);
|
||||
if (err_get())
|
||||
err_perror(path);
|
||||
error_perror(path);
|
||||
if (!line)
|
||||
err_perror_str(path, "room is empty");
|
||||
error_str(path, "room is empty");
|
||||
r->width = getlinelen(line);
|
||||
r->height = 1;
|
||||
while (true)
|
||||
{
|
||||
line = read_line(err_remember, mc, fd);
|
||||
if (err_get())
|
||||
err_perror(path);
|
||||
error_perror(path);
|
||||
if (!line)
|
||||
break ;
|
||||
if (getlinelen(line) != r->width)
|
||||
err_perror_str(path, "the lines have different lengths");
|
||||
error_str(path, "the lines have different lengths");
|
||||
r->height++;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +68,7 @@ t_roomcase *getroomcase(t_const_string path, char c)
|
|||
if (g_roomcases[i].c == c)
|
||||
return (&g_roomcases[i]);
|
||||
}
|
||||
err_perror_str(path, "unknown char");
|
||||
error_str(path, "unknown char");
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -6,12 +6,12 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 12:33:48 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/04/02 12:51:20 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 17:52:14 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes.h"
|
||||
#include "room_utils.h"
|
||||
#include "data_sprites.h"
|
||||
|
||||
void room_patch(t_room *room)
|
||||
{
|
|
@ -6,11 +6,11 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/15 15:24:37 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/03/27 18:23:24 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/04/02 14:41:19 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "point.h"
|
||||
#include "includes.h"
|
||||
|
||||
t_point point_init(int x, int y)
|
||||
{
|
Loading…
Add table
Reference in a new issue