Intro :
Im a computer engineer student and we have to make in a group of 2 students a game like Wolfeinstein3D with our own raycasting code, in C and with the theme we want, of course we chose the best game of all time AKA Minecraft for theme, and we have to do this with a garbage-tier graphic library (it's a thing like openGL but 100 time worse). And because we are young and stupid we wanted to make much more than the result expected from the subject. Items, GUI, Blocks, Action bar, crafting.. We are working on the project since 2 months, but we have finished the 'normal' and wanted by subject part in 2 weeks and we are enjoying a lot.
Context: Our project are built like this : A core struct who have all things
typedef struct s_core
{
mlx_t *mlx; //its like core of the graph libs
t_player player; //all the player infos (move speed, position, health..)
t_imgs imgs; //all our images
t_sounds sounds; //all our sounds
t_item items[7]; //all our items
t_animation animations[7]; //all our anims
t_block blocks[2]; //all our blocks
t_map *maps; //all informations about maps (the char **maps, height, weidth..)
int screen_size[2];
} t_core;
And we try as much as possible to respect the principle of encapsulation..
problem:
What is a Block ? A block is a think with a name, with an image to draw in a world, but also an item because you can have it in your hand, build think with him, craft.. And a block has a special song, and maybe an animation, because the block can by animated (for exemple a nether portal..)
So for create a Block, i have to set a item, so i have to acces to core->items[the_wanted](knowing that the items are created before blocks), but i have to get the sound so i have to acces to core->sounds[the_wanted], but i also need a image and more and more and more..
Its the same probleme for lot of think, sounds, items, blocks, maps, players, animation, imgs.. they are all interdependent and I have no idea how to do otherwise.
We therefore find ourselves sending either the entire core as a parameter, or more than 4 elements of the core to a function to do the necessary..
Debat:
I think that we have to delete core struct and allowing the acces of all thinks in it by making them global, my teammate think we have to create a pointer in each of them to the core, exemple
typedef struct s_item
{
{...variables}
t_core *core;
} t_item;
Questions:
- What is encapulsation in C, does the concept of encapulsation exist and is it relevant in C as there is no POO ?
- In theory, how to manager a project like this ?
- In our case, how should we do ?
- Have we reached a certain limit of the C possiblity ?
- Any others advice to us, we want to be elegant coders.
We try to be elegant and good at coding but we are not