├── saves └── .gitkeep ├── .gitignore ├── assets ├── gui.png ├── items.png ├── tiles.png └── entities.png ├── screenshots ├── game.png └── main_menu.png ├── lib ├── Makefile └── hsy │ ├── .gitignore │ ├── sources │ ├── hsy_putchar.c │ ├── hsy_putnbr.c │ ├── hsy_putstr.c │ ├── hsy_fd_putchar.c │ ├── hsy_int_swap.c │ ├── hsy_strtol.c │ ├── hsy_strcmp.c │ ├── hsy_strcpy.c │ ├── hsy_fd_putstr.c │ ├── hsy_find_prime_sup.c │ ├── hsy_chrstr.c │ ├── hsy_isneg.c │ ├── hsy_strlen.c │ ├── hsy_isspace.c │ ├── hsy_strlowcase.c │ ├── hsy_strcat.c │ ├── hsy_strncmp.c │ ├── hsy_is_prime.c │ ├── hsy_compute_square_root.c │ ├── hsy_strupcase.c │ ├── hsy_str_isupper.c │ ├── hsy_strncpy.c │ ├── hsy_str_islower.c │ ├── hsy_strncat.c │ ├── hsy_str_isalpha.c │ ├── hsy_str_isprintable.c │ ├── hsy_str_isnum.c │ ├── hsy_revstr.c │ ├── hsy_strdup.c │ ├── hsy_sort_int_array.c │ ├── hsy_atoi.c │ ├── hsy_strndup.c │ ├── hsy_compute_power_rec.c │ ├── hsy_fd_putnbr.c │ ├── hsy_strcapitalize.c │ ├── hsy_getnbr.c │ ├── hsy_strstr.c │ └── hsy_strtoul.c │ └── .gitrepo ├── sources ├── menus │ ├── menu_tick.c │ ├── menu_draw.c │ ├── menu_init.c │ ├── crafting_menu │ │ ├── crafting_menu_destroy.c │ │ └── crafting_menu.c │ ├── title_menu │ │ ├── title_menu_destroy.c │ │ └── title_menu.c │ ├── menu_destroy.c │ ├── menu.c │ ├── text_input_menu │ │ ├── text_input_menu_destroy.c │ │ ├── text_input_menu.c │ │ └── text_input_menu_tick.c │ ├── about_menu │ │ ├── about_menu.c │ │ ├── about_menu_tick.c │ │ └── about_menu_create.c │ ├── death_menu │ │ ├── death_menu.c │ │ └── death_menu_create.c │ ├── pause_menu │ │ ├── pause_menu.c │ │ └── pause_menu_create.c │ ├── floor_change_menu │ │ ├── floor_change_menu_draw.c │ │ ├── floor_change_menu.c │ │ └── floor_change_menu_create.c │ ├── options_menu │ │ ├── options_menu.c │ │ └── options_menu_create.c │ ├── inventory_menu │ │ ├── inventory_menu.c │ │ └── inventory_menu_draw.c │ └── world_select_menu │ │ ├── world_select_menu_destroy.c │ │ └── world_select.c ├── entities │ ├── entity_tick.c │ ├── entity_create.c │ ├── entity_heal.c │ ├── entity_can_swim.c │ ├── entity_do_hurt.c │ ├── entity_blocks.c │ ├── entity_die.c │ ├── entity_init.c │ ├── entity_touch_item.c │ ├── entity_touched_by.c │ ├── mob │ │ ├── player │ │ │ ├── player_can_swim.c │ │ │ ├── player_hurt_tile.c │ │ │ ├── player_change_floor.c │ │ │ ├── player_pay_stamina.c │ │ │ ├── player_funcs.c │ │ │ ├── player_destroy.c │ │ │ ├── player_get_attack_damage.c │ │ │ ├── player_hurt_pos.c │ │ │ ├── player_touch_item.c │ │ │ ├── player_start_pos.c │ │ │ ├── player_use_pos.c │ │ │ └── player_interact_pos.c │ │ ├── slime │ │ │ ├── slime_funcs.c │ │ │ ├── slime_touched_by.c │ │ │ └── slime_save.c │ │ ├── zombie │ │ │ ├── zombie_funcs.c │ │ │ ├── zombie_touched_by.c │ │ │ └── zombie_save.c │ │ ├── mob_hurt_tile.c │ │ ├── mob_hurt.c │ │ ├── mob_funcs.c │ │ ├── mob_is_swimming.c │ │ ├── mob_save.c │ │ ├── mob_tick.c │ │ └── mob_do_hurt.c │ ├── entity_destroy.c │ ├── entity_hurt.c │ ├── entity_use.c │ ├── entity_is_block_by.c │ ├── furniture │ │ ├── furniture_blocks.c │ │ ├── workbench │ │ │ ├── workbench_funcs.c │ │ │ └── workbench_use.c │ │ ├── furniture_take.c │ │ ├── furniture_destroy.c │ │ ├── furniture_init.c │ │ ├── furniture_funcs.c │ │ ├── furniture_save.c │ │ ├── furniture_touched_by.c │ │ ├── furniture_draw.c │ │ └── furnitures_types.c │ ├── entity_draw.c │ ├── entity_instance_of.c │ ├── entity_interact.c │ ├── text_particle │ │ ├── text_particle_funcs.c │ │ └── text_particle_draw.c │ ├── entity_hurt_tile.c │ ├── entities_count.c │ ├── item_entity │ │ ├── item_entity_funcs.c │ │ ├── item_entity_touched_by.c │ │ ├── item_entity_take.c │ │ ├── item_entity_destroy.c │ │ └── item_entity_save.c │ ├── entities_draw.c │ ├── entity_start_pos.c │ ├── entities_add.c │ ├── entities_add_all.c │ ├── entities_funcs.c │ ├── entity_intersects.c │ └── entities_remove_all.c ├── items │ ├── item_get_tex.c │ ├── item_can_attack.c │ ├── item_is_depleted.c │ ├── item_on_take.c │ ├── item_attack_bonus.c │ ├── item_destroy.c │ ├── tool_item │ │ ├── tool_item_can_attack.c │ │ ├── tool_item_attack_bonus.c │ │ ├── tool_item_get_tex.c │ │ ├── tool_item_get_name.c │ │ ├── tool_item_draw_icon.c │ │ ├── tool_item_funcs.c │ │ ├── tool_item_save.c │ │ ├── tool_item_draw_inventory.c │ │ └── tool_item_create.c │ ├── furniture_item │ │ ├── furniture_item_can_attack.c │ │ ├── furniture_item_is_depleted.c │ │ ├── furniture_item_get_name.c │ │ ├── furniture_item_get_tex.c │ │ ├── furniture_item_draw_icon.c │ │ ├── furniture_item_save.c │ │ ├── furniture_item_destroy.c │ │ ├── furniture_item_create.c │ │ ├── furniture_item_draw_inventory.c │ │ └── furniture_item_funcs.c │ ├── item_get_name.c │ ├── item_interact.c │ ├── resource_item │ │ ├── resource_item_get_tex.c │ │ ├── resource_item_get_name.c │ │ ├── resource_item_is_depleted.c │ │ ├── resource_item_draw_icon.c │ │ ├── resource_item_save.c │ │ ├── resource_item_interact_tile.c │ │ ├── resource_item_funcs.c │ │ ├── resource_item_draw_inventory.c │ │ └── resource_item_create.c │ ├── item_draw_icon.c │ ├── resource_interact.c │ ├── item_draw_inventory.c │ ├── item_interact_tile.c │ ├── item_list_size.c │ ├── food_interact.c │ ├── resource_get.c │ ├── item_list_remove.c │ ├── item_list_add.c │ ├── item_save.c │ ├── item_funcs.c │ └── plant_interact.c ├── random │ ├── random_int.c │ ├── random_float.c │ └── random_gaussian.c ├── main_menu │ ├── main_menu_event.c │ ├── main_menu_draw.c │ ├── main_menu_destroy.c │ ├── main_menu_init.c │ └── main_menu_update.c ├── screen │ ├── screen_set_offset.c │ ├── screen_destroy.c │ └── screen_sprite_flip.c ├── recipes │ ├── recipe_craft.c │ ├── recipe_init.c │ ├── tool_recipe │ │ ├── tool_recipe_funcs.c │ │ ├── tool_recipe_craft.c │ │ └── tool_recipe_create.c │ ├── resource_recipe │ │ ├── resource_recipe_funcs.c │ │ ├── resource_recipe_craft.c │ │ └── resource_recipe_create.c │ ├── furniture_recipe │ │ ├── furniture_recipe_funcs.c │ │ ├── furniture_recipe_craft.c │ │ └── furniture_recipe_create.c │ ├── craft_destroy.c │ ├── recipe_add.c │ ├── recipe_list_size.c │ ├── recipe_funcs.c │ ├── recipe_list_destroy.c │ ├── recipe_add_cost.c │ ├── recipe_list_delink.c │ ├── recipe_list_get.c │ ├── recipe_destroy.c │ ├── craft_create.c │ ├── recipe_deduct_cost.c │ └── recipe_funcs_combine.c ├── inventory │ ├── inventory_add.c │ ├── inventory_destroy.c │ ├── inventory_create.c │ ├── inventory_has_resources.c │ ├── inventory_remove_item.c │ ├── inventory_find_resource.c │ ├── inventory_save.c │ ├── inventory_remove_resource.c │ ├── inventory_count.c │ └── inventory_add_pos.c ├── engine │ ├── engine_update.c │ ├── engine_internal_events.c │ ├── engine_internal_resized.c │ ├── engine_usage.c │ ├── engine_draw.c │ ├── engine_destroy.c │ ├── engine_init.c │ └── engine_events.c ├── input │ ├── input_release_all.c │ ├── mkey_toggle.c │ ├── mkey_tick.c │ ├── mkey_init.c │ ├── mkey_release.c │ └── input_tick.c ├── loader │ ├── parse_atoi.c │ └── get_line.c ├── window │ └── window_destroy.c ├── level_gen │ ├── level_gen_sample.c │ ├── level_gen_destroy.c │ ├── level_gen_set_sample.c │ └── level_gen_create_top_map │ │ └── top_map_generate_cactus.c ├── tiles │ ├── cactus │ │ ├── cactus_may_pass.c │ │ ├── cactus_bump.c │ │ ├── cactus.c │ │ └── cactus_render.c │ ├── sand │ │ └── sand.c │ ├── wheat │ │ ├── wheat.c │ │ └── wheat_render.c │ ├── carrot │ │ ├── carrot.c │ │ └── carrot_render.c │ ├── flower │ │ └── flower.c │ ├── hole │ │ ├── hole.c │ │ └── hole_may_pass.c │ ├── dirt │ │ ├── dirt.c │ │ └── dirt_render.c │ ├── grass │ │ └── grass.c │ ├── tree │ │ ├── tree_hurt.c │ │ ├── tree.c │ │ └── tree_may_pass.c │ ├── lava │ │ ├── lava.c │ │ ├── lava_may_pass.c │ │ └── lava_tick.c │ ├── water │ │ ├── water.c │ │ ├── water_may_pass.c │ │ └── water_tick.c │ ├── rock │ │ ├── rock_hurt.c │ │ ├── rock.c │ │ └── rock_may_pass.c │ ├── farmland │ │ ├── farmland.c │ │ ├── farmland_tick.c │ │ ├── farmland_step.c │ │ └── farmland_render.c │ ├── stair │ │ └── stair.c │ └── ore │ │ └── ore_render.c ├── floor │ ├── floor_entities_row_clear.c │ ├── floor_set_data.c │ ├── floor_set_tile.c │ ├── floor_get_data.c │ ├── floor_add.c │ ├── floor_destroy.c │ ├── floor_get_tile.c │ └── floor_insert_entity.c ├── universe │ ├── universe_set_menu.c │ └── universe_destroy.c ├── game │ ├── game_event.c │ ├── game_draw.c │ ├── game_destroy.c │ └── game_init.c ├── asset_manager │ ├── asset_manager_init.c │ └── asset_manager_destroy.c ├── main.c ├── consts.c ├── gui │ └── gui_num_draw.c └── view │ └── view_ratio.c ├── include ├── tiles.h ├── entities_id.h ├── items_id.h ├── recipes_id.h ├── random.h ├── tiles │ ├── sand.h │ ├── wheat.h │ ├── carrot.h │ ├── flower.h │ ├── stair.h │ ├── dirt.h │ ├── hole.h │ ├── grass.h │ ├── lava.h │ ├── water.h │ ├── cactus.h │ ├── farmland.h │ ├── ore.h │ ├── rock.h │ └── tree.h ├── entities.h ├── entity_list.h ├── menus_id.h ├── csfml_version.h ├── game.h ├── resources │ ├── plant_resource.h │ ├── food_resource.h │ ├── resources.h │ ├── resource.h │ └── item.h ├── gui.h ├── entities │ ├── workbench.h │ ├── zombie.h │ ├── slime.h │ └── text_particle.h ├── menus │ ├── about_menu.h │ ├── floor_change_menu.h │ ├── inventory_menu.h │ ├── death_menu.h │ ├── title_menu.h │ ├── options_menu.h │ ├── pause_menu.h │ ├── text_input_menu.h │ └── crafting_menu.h ├── resources_id.h ├── recipes │ ├── craft.h │ ├── resource_recipe.h │ ├── furniture_recipe.h │ └── tool_recipe.h ├── menu_funcs.h ├── recipe_funcs.h └── scenes.h └── LICENSE /saves/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | my_rpg 2 | *.a 3 | *.o 4 | memo 5 | dev 6 | .vscode 7 | .clang_complete -------------------------------------------------------------------------------- /assets/gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/assets/gui.png -------------------------------------------------------------------------------- /assets/items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/assets/items.png -------------------------------------------------------------------------------- /assets/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/assets/tiles.png -------------------------------------------------------------------------------- /assets/entities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/assets/entities.png -------------------------------------------------------------------------------- /screenshots/game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/screenshots/game.png -------------------------------------------------------------------------------- /screenshots/main_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hollowshiroyuki/minitek/HEAD/screenshots/main_menu.png -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo -n 3 | @make -C ./hsy 4 | clean: 5 | @echo -n 6 | @make -C ./hsy clean 7 | fclean: 8 | @echo -n 9 | @make -C ./hsy fclean 10 | -------------------------------------------------------------------------------- /lib/hsy/.gitignore: -------------------------------------------------------------------------------- 1 | ######################## 2 | ### LIB_HSY GITIGNORE### 3 | ######################## 4 | 5 | # Do not commit the compiled lib. 6 | libhsy.a 7 | 8 | # Do not commit the object files. 9 | objects/ 10 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_putchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_putchar 4 | ** File description: 5 | ** man man 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | void hsy_putchar(char c) 11 | { 12 | hsy_fd_putchar(1, c); 13 | } 14 | -------------------------------------------------------------------------------- /sources/menus/menu_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | 10 | void menu_tick(menu_t *self) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_putnbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_put_nbr 4 | ** File description: 5 | ** vim > emacs 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | ssize_t hsy_putnbr(int i) 11 | { 12 | return (hsy_fd_putnbr(1, i)); 13 | } 14 | -------------------------------------------------------------------------------- /sources/entities/entity_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_tick(entity_t *self) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/items/item_get_tex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int item_get_tex(item_t *self) 11 | { 12 | return (0); 13 | } -------------------------------------------------------------------------------- /sources/random/random_int.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | 10 | int random_int(int bound) 11 | { 12 | return (rand() % bound); 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | entity_t *entity_create(void) 11 | { 12 | return (0); 13 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_putstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_putstr 4 | ** File description: 5 | ** M-x doctor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | ssize_t hsy_putstr(char const *str) 11 | { 12 | return (hsy_fd_putstr(1, str)); 13 | } 14 | -------------------------------------------------------------------------------- /sources/entities/entity_heal.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_heal(entity_t *self, int heal) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/items/item_can_attack.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool item_can_attack(item_t *self) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/items/item_is_depleted.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool item_is_depleted(item_t *self) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/items/item_on_take.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | void item_on_take(item_t *self, entity_t *item) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/main_menu/main_menu_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | void main_menu_event(engine_t *engine, sfEvent *event) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /include/tiles.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TILES_H_ 9 | #define TILES_H_ 10 | 11 | #include "tiles_id.h" 12 | 13 | extern const tile_t *tiles[T_COUNT]; 14 | 15 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_fd_putchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_putchar 4 | ** File description: 5 | ** man man 6 | */ 7 | 8 | #include 9 | #include "hsy.h" 10 | 11 | void hsy_fd_putchar(int fd, char c) 12 | { 13 | write(fd, &c, 1); 14 | } 15 | -------------------------------------------------------------------------------- /sources/entities/entity_can_swim.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_can_swim(entity_t *self) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_do_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_do_hurt(entity_t *self, int dmg, int dir) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/items/item_attack_bonus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int item_attack_bonus(item_t *self, entity_t *e) 11 | { 12 | return (0); 13 | } -------------------------------------------------------------------------------- /sources/items/item_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "resources/item.h" 10 | 11 | void item_destroy(item_t *self) 12 | { 13 | free(self); 14 | } -------------------------------------------------------------------------------- /sources/entities/entity_blocks.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_blocks(entity_t *self, entity_t *entity) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_die.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void entity_die(entity_t *self) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /sources/entities/entity_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_init(entity_t *self, floor_t *floor) 11 | { 12 | self->floor = floor; 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_touch_item.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_touch_item(entity_t *self, entity_t *item) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_touched_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_touched_by(entity_t *self, entity_t *entity) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_can_swim.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool player_can_swim(entity_t *self) 11 | { 12 | return (true); 13 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_can_attack.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool tool_item_can_attack(item_t *self) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/menus/menu_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "screen.h" 10 | 11 | void menu_draw(menu_t *self, screen_t *screen) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /sources/entities/entity_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void entity_destroy(entity_t *self) 12 | { 13 | free(self); 14 | } -------------------------------------------------------------------------------- /sources/entities/entity_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_hurt(entity_t *self, entity_t *mob, int dmg, int dir) 11 | { 12 | return; 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_use.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_use(entity_t *self, entity_t *player, int dir) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/random/random_float.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | 10 | float random_float(void) 11 | { 12 | return ((float)((double)rand() / (double)(RAND_MAX / 1))); 13 | } -------------------------------------------------------------------------------- /sources/screen/screen_set_offset.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "screen.h" 9 | 10 | void screen_set_offset(screen_t *self, sfVector2i offset) 11 | { 12 | self->offset = offset; 13 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_int_swap.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_swap 4 | ** File description: 5 | ** r/ProgrammerHumor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | void hsy_int_swap(int *a, int *b) 11 | { 12 | *a = *a ^ *b; 13 | *b = *b ^ *a; 14 | *a = *a ^ *b; 15 | } 16 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strtol.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** my_strtol 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_strtol(char const *str, char **endptr) 11 | { 12 | return (hsy_strtoul(str, endptr)); 13 | } 14 | -------------------------------------------------------------------------------- /sources/entities/entity_is_block_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_is_block_by(entity_t *self, entity_t *entity) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_blocks.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool furniture_blocks(entity_t *self, entity_t *entity) 11 | { 12 | return (true); 13 | } -------------------------------------------------------------------------------- /sources/entities/furniture/workbench/workbench_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/workbench.h" 9 | 10 | const entity_funcs_t workbench_funcs = { 11 | .use = workbench_use 12 | }; -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_can_attack.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool furniture_item_can_attack(item_t *self) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_attack_bonus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int tool_item_attack_bonus(item_t *self, entity_t *e) 11 | { 12 | return (0); 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void entity_draw(entity_t *self, screen_t *scr) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_take.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entity_take(entity_t *self, entity_t *player) 11 | { 12 | self->fur.player = player; 13 | } -------------------------------------------------------------------------------- /sources/items/item_get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | char *item_get_name(item_t *self) 11 | { 12 | static char *str = "NULL"; 13 | 14 | return (str); 15 | } -------------------------------------------------------------------------------- /sources/items/item_interact.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool item_interact(item_t *self, entity_t *play, entity_t *item, int dir) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /include/entities_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ENTITIES_ID_H_ 9 | #define ENTITIES_ID_H_ 10 | 11 | enum { 12 | E_MOB, 13 | E_ITEM, 14 | E_FURNITURE, 15 | E_COUNT 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /include/items_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ITEMS_ID_H_ 9 | #define ITEMS_ID_H_ 10 | 11 | enum { 12 | I_TOOL, 13 | I_FURNITURE, 14 | I_RESOURCE, 15 | I_COUNT 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_get_tex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int resource_item_get_tex(item_t *self) 11 | { 12 | return (self->res.resource->tex); 13 | } -------------------------------------------------------------------------------- /sources/entities/entity_instance_of.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities_id.h" 9 | #include "entities/entity.h" 10 | 11 | bool entity_instance_of(entity_t *self, int id) 12 | { 13 | return (false); 14 | } -------------------------------------------------------------------------------- /sources/entities/entity_interact.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_interact(entity_t *self, entity_t *entity, item_t *item, int dir) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_is_depleted.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool furniture_item_is_depleted(item_t *self) 11 | { 12 | return (self->fur.placed); 13 | } -------------------------------------------------------------------------------- /sources/items/item_draw_icon.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "screen.h" 10 | 11 | void item_draw_icon(item_t *self, screen_t *screen, sfVector2i pos) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | char *resource_item_get_name(item_t *self) 11 | { 12 | return (self->res.resource->name); 13 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_is_depleted.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool resource_item_is_depleted(item_t *self) 11 | { 12 | return (self->res.count <= 0); 13 | } -------------------------------------------------------------------------------- /include/recipes_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RECIPES_ID_H_ 9 | #define RECIPES_ID_H_ 10 | 11 | typedef enum 12 | { 13 | R_TOOL, 14 | R_FURNITURE, 15 | R_RESOURCE 16 | } recipe_id_t; 17 | 18 | #endif -------------------------------------------------------------------------------- /sources/items/resource_interact.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/resource.h" 9 | 10 | bool resource_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla) 11 | { 12 | return (false); 13 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_get_tex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int tool_item_get_tex(item_t *self) 11 | { 12 | return (self->tool.type->tex + self->tool.level * 32); 13 | } -------------------------------------------------------------------------------- /sources/items/item_draw_inventory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "screen.h" 10 | 11 | void item_draw_inventory(item_t *self, screen_t *screen, sfVector2i pos) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | char *tool_item_get_name(item_t *self) 11 | { 12 | static char *str = "NULL"; 13 | 14 | return (str); 15 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_craft.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void recipe_craft(recipe_t *self, entity_t *player) 13 | { 14 | return; 15 | } -------------------------------------------------------------------------------- /include/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RANDOM_H_ 9 | #define RANDOM_H_ 10 | 11 | float random_float(void); 12 | int random_int(int bound); 13 | int randomize_seed(void); 14 | float random_gaussian(void); 15 | 16 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strcmp 4 | ** File description: 5 | ** hello world? 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_strcmp(char const *s1, char const *s2) 11 | { 12 | size_t s1_len = hsy_strlen(s1); 13 | 14 | return (hsy_strncmp(s1, s2, s1_len)); 15 | } 16 | -------------------------------------------------------------------------------- /sources/inventory/inventory_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | 10 | void inventory_add(inventory_t *self, item_t *item) 11 | { 12 | inventory_add_pos(self, item, item_list_size(self->items) + 1); 13 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void recipe_init(recipe_t *self, item_t *item) 13 | { 14 | self->result = item; 15 | } -------------------------------------------------------------------------------- /sources/recipes/tool_recipe/tool_recipe_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "recipe_funcs.h" 9 | #include "recipes/recipe.h" 10 | 11 | const recipe_funcs_t tool_recipe_funcs = { 12 | .craft = tool_recipe_craft 13 | }; -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_draw_icon.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "screen.h" 10 | 11 | void tool_item_draw_icon(item_t *self, screen_t *screen, sfVector2i pos) 12 | { 13 | return; 14 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strcpy 4 | ** File description: 5 | ** example of bad code: 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strcpy(char *dest, char const *src) 11 | { 12 | size_t len = hsy_strlen(src); 13 | 14 | return (hsy_strncpy(dest, src, len + 1)); 15 | } 16 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_fd_putstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_putstr 4 | ** File description: 5 | ** M-x doctor 6 | */ 7 | 8 | #include 9 | #include "hsy.h" 10 | 11 | ssize_t hsy_fd_putstr(int fd, char const *str) 12 | { 13 | size_t len = hsy_strlen(str); 14 | 15 | return (write(fd, str, len)); 16 | } 17 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_find_prime_sup.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_find_prime_sup 4 | ** File description: 5 | ** example of bad code: 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_find_prime_sup(int nb) 11 | { 12 | if (hsy_is_prime(nb)) 13 | return (nb); 14 | return (hsy_find_prime_sup(nb + 1)); 15 | } 16 | -------------------------------------------------------------------------------- /sources/items/item_interact_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "tiles/tile.h" 10 | 11 | bool item_interact_tile(item_t *self, tile_t til, sfVector2i p, entity_t *pla) 12 | { 13 | return (false); 14 | } -------------------------------------------------------------------------------- /sources/recipes/resource_recipe/resource_recipe_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "recipe_funcs.h" 9 | #include "recipes/recipe.h" 10 | 11 | const recipe_funcs_t resource_recipe_funcs = { 12 | .craft = resource_recipe_craft 13 | }; -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void furniture_destroy(entity_t *self) 12 | { 13 | free(self->fur.name); 14 | entity_destroy(self); 15 | } -------------------------------------------------------------------------------- /sources/entities/text_particle/text_particle_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/text_particle.h" 9 | 10 | const entity_funcs_t text_particle_funcs = { 11 | .draw = text_particle_draw, 12 | .tick = text_particle_tick 13 | }; -------------------------------------------------------------------------------- /sources/recipes/furniture_recipe/furniture_recipe_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "recipe_funcs.h" 9 | #include "recipes/recipe.h" 10 | 11 | const recipe_funcs_t furniture_recipe_funcs = { 12 | .craft = furniture_recipe_craft 13 | }; -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "entities/entity.h" 10 | 11 | char *furniture_item_get_name(item_t *self) 12 | { 13 | return (self->fur.furniture->fur.name); 14 | } -------------------------------------------------------------------------------- /include/tiles/sand.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef SAND_H_ 9 | #define SAND_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t sand; 14 | 15 | void sand_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | 17 | #endif -------------------------------------------------------------------------------- /sources/recipes/craft_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void craft_destroy(craft_t *self) 13 | { 14 | recipe_list_destroy(self->workbench); 15 | free(self); 16 | } -------------------------------------------------------------------------------- /include/entities.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ENTITIES_H_ 9 | #define ENTITIES_H_ 10 | 11 | #include "entity_funcs.h" 12 | 13 | extern const entity_funcs_t *entities_funcs[]; 14 | 15 | void entities_draw(entity_t *list, screen_t *screen); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/tiles/wheat.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef WHEAT_H_ 9 | #define WHEAT_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t wheat; 14 | 15 | void wheat_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | 17 | #endif -------------------------------------------------------------------------------- /sources/engine/engine_update.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "scenes.h" 10 | 11 | void engine_update(engine_t *engine) 12 | { 13 | if (scenes[engine->active_scene].update) 14 | (scenes[engine->active_scene].update)(engine); 15 | } -------------------------------------------------------------------------------- /sources/entities/entity_hurt_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | void entity_hurt_tile(entity_t *self, tile_t tile, sfVector2i pos, int dmg) 13 | { 14 | return; 15 | } -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_get_tex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "entities/entity.h" 10 | 11 | int furniture_item_get_tex(item_t *self) 12 | { 13 | return (self->fur.furniture->fur.tex + 26 * 32); 14 | } -------------------------------------------------------------------------------- /include/tiles/carrot.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef CARROT_H_ 9 | #define CARROT_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t carrot; 14 | 15 | void carrot_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/tiles/flower.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef FLOWER_H_ 9 | #define FLOWER_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t flower; 14 | 15 | void flower_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | 17 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_chrstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_chrstr 4 | ** File description: 5 | ** r/ProgrammerHumor 6 | */ 7 | 8 | char *hsy_chrstr(char c, char const *str) 9 | { 10 | for (int i = 0; str[i]; i++) { 11 | if (str[i] == c) { 12 | return ((char *)(str + i)); 13 | } 14 | } 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_isneg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_isneg 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_isneg(int n) 11 | { 12 | if (n < 0) 13 | hsy_putchar('N'); 14 | else 15 | hsy_putchar('P'); 16 | hsy_putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strlen 4 | ** File description: 5 | ** xkcd.com/378 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | size_t hsy_strlen(char const *str) 11 | { 12 | size_t i = 0; 13 | 14 | if (!str) 15 | return (0); 16 | while (str[i]) { 17 | i++; 18 | } 19 | return (i); 20 | } 21 | -------------------------------------------------------------------------------- /sources/input/input_release_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "input.h" 10 | 11 | void input_release_all(input_t *input) 12 | { 13 | for (int i = 0; i < C_COUNT; i++) { 14 | mkey_release(&input->keys[i]); 15 | } 16 | } -------------------------------------------------------------------------------- /sources/items/item_list_size.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | int item_list_size(item_t *list) 11 | { 12 | int i = 0; 13 | 14 | while (list) { 15 | list = list->next; 16 | i++; 17 | }; 18 | return (i); 19 | } -------------------------------------------------------------------------------- /sources/entities/mob/slime/slime_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/slime.h" 9 | 10 | const entity_funcs_t slime_funcs = { 11 | .draw = slime_draw, 12 | .tick = slime_tick, 13 | .die = slime_die, 14 | .touched_by = slime_touched_by 15 | }; -------------------------------------------------------------------------------- /sources/loader/parse_atoi.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | int parse_atoi(char **str) 9 | { 10 | int res = 0; 11 | 12 | while (**str && '0' <= **str && **str <= '9') { 13 | res = res * 10 + **str - '0'; 14 | (*str)++; 15 | } 16 | return (res); 17 | } -------------------------------------------------------------------------------- /sources/entities/mob/zombie/zombie_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/zombie.h" 9 | 10 | const entity_funcs_t zombie_funcs = { 11 | .draw = zombie_draw, 12 | .tick = zombie_tick, 13 | .die = zombie_die, 14 | .touched_by = zombie_touched_by 15 | }; -------------------------------------------------------------------------------- /sources/menus/menu_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "input.h" 10 | #include "universe.h" 11 | 12 | void menu_init(menu_t *self, universe_t *universe, input_t *input) 13 | { 14 | self->universe = universe; 15 | self->input = input; 16 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_isspace.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_isspace 4 | ** File description: 5 | ** xkcd.com/378 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_isspace(char c) 11 | { 12 | if (c == ' ') 13 | return (1); 14 | if (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r') 15 | return (1); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "hsy.h" 10 | 11 | void furniture_init(entity_t *self, char *name) 12 | { 13 | self->fur.name = hsy_strdup(name); 14 | self->box.x = 3; 15 | self->box.y = 3; 16 | } -------------------------------------------------------------------------------- /sources/window/window_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | void window_destroy(engine_t *engine) 11 | { 12 | if (engine->window) 13 | sfRenderWindow_destroy(engine->window); 14 | if (engine->view) 15 | sfView_destroy(engine->view); 16 | } -------------------------------------------------------------------------------- /sources/input/mkey_toggle.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "input.h" 10 | 11 | void mkey_toggle(mkey_t *key, bool pressed) 12 | { 13 | if (pressed != key->down) 14 | key->down = pressed; 15 | if (pressed) 16 | key->presses++; 17 | } -------------------------------------------------------------------------------- /sources/level_gen/level_gen_sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "level_gen.h" 9 | 10 | double level_gen_sample(level_gen_t *lg, int x, int y) 11 | { 12 | int w = lg->size.x; 13 | int h = lg->size.y; 14 | 15 | return (lg->values[(x & (w - 1)) + (y & (h - 1)) * w]); 16 | } -------------------------------------------------------------------------------- /sources/entities/mob/mob_hurt_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | void mob_hurt_tile(entity_t *self, tile_t tile, sfVector2i pos, int dmg) 13 | { 14 | mob_do_hurt(self, dmg, self->mob.dir); 15 | } -------------------------------------------------------------------------------- /sources/tiles/cactus/cactus_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "entities/entity.h" 10 | #include "floor.h" 11 | #include 12 | 13 | bool cactus_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 14 | { 15 | return (false); 16 | } -------------------------------------------------------------------------------- /sources/menus/crafting_menu/crafting_menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "menus/menu.h" 10 | #include "recipes/recipe.h" 11 | 12 | void crafting_menu_destroy(menu_t *self) 13 | { 14 | recipe_list_delink(self->craft.recipes); 15 | menu_destroy(self); 16 | } -------------------------------------------------------------------------------- /include/tiles/stair.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef STAIRUP_H_ 9 | #define STAIRUP_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t stair_up; 14 | extern const tile_t stair_down; 15 | 16 | void stair_render(tile_t self, screen_t *scr, floor_t *flr, sfVector2i p); 17 | 18 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strlowcase.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strupcase 4 | ** File description: 5 | ** M-x doctor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strlowcase(char *str) 11 | { 12 | for (int i = 0; str[i]; i++) { 13 | if ('A' <= str[i] && str[i] <= 'Z') { 14 | str[i] += 'a' - 'A'; 15 | } 16 | } 17 | return (str); 18 | } 19 | -------------------------------------------------------------------------------- /sources/recipes/recipe_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void recipe_add(recipe_t **old, recipe_t *new) 13 | { 14 | new->next = *old; 15 | new->result->next = (*old) ? (*old)->result : 0; 16 | *old = new; 17 | } -------------------------------------------------------------------------------- /sources/entities/mob/mob_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | 13 | void mob_hurt(entity_t *self, entity_t *mob, int damage, int dir) 14 | { 15 | (self->funcs.do_hurt)(self, damage, dir); 16 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_hurt_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | void player_hurt_tile(entity_t *self, tile_t tile, sfVector2i pos, int dmg) 13 | { 14 | player_do_hurt(self, dmg, self->mob.dir); 15 | } -------------------------------------------------------------------------------- /sources/level_gen/level_gen_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "level_gen.h" 10 | 11 | void level_gen_destroy(level_gen_t *lg) 12 | { 13 | if (!lg) 14 | return; 15 | if (lg->values) 16 | free(lg->values); 17 | if (lg) 18 | free(lg); 19 | } -------------------------------------------------------------------------------- /sources/level_gen/level_gen_set_sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "level_gen.h" 9 | 10 | void level_gen_set_sample(level_gen_t *lg, int x, int y, double value) 11 | { 12 | int w = lg->size.x; 13 | int h = lg->size.y; 14 | 15 | lg->values[(x & (w - 1)) + (y & (h - 1)) * w] = value; 16 | } -------------------------------------------------------------------------------- /sources/menus/title_menu/title_menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "menus/menu.h" 10 | 11 | void title_menu_destroy(menu_t *self) 12 | { 13 | sfTexture_destroy(self->title.texture); 14 | sfSprite_destroy(self->title.background); 15 | menu_destroy(self); 16 | } -------------------------------------------------------------------------------- /sources/menus/menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "menus/menu.h" 10 | 11 | void menu_destroy(menu_t *self) 12 | { 13 | if (self->name) 14 | free(self->name); 15 | if (self->child) 16 | (self->child->funcs.destroy)(self->child); 17 | free(self); 18 | } -------------------------------------------------------------------------------- /sources/entities/entities_count.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | int entities_count(entity_t *list) 11 | { 12 | int i = 0; 13 | 14 | if (!list) 15 | return (0); 16 | while (list) { 17 | i++; 18 | list = list->next; 19 | } 20 | return (i); 21 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_change_floor.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/player.h" 11 | #include "universe.h" 12 | 13 | void player_change_floor(entity_t *self, int dir) 14 | { 15 | self->mob.pla.universe->floor_change = dir; 16 | } -------------------------------------------------------------------------------- /sources/floor/floor_entities_row_clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "consts.h" 10 | #include "floor.h" 11 | #include "entities/entity.h" 12 | 13 | void floor_entities_row_clear(entity_t **row, int len) 14 | { 15 | memset(row, 0, sizeof(entity_t *) * ((entities_per_tile) * len)); 16 | } -------------------------------------------------------------------------------- /sources/menus/menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = menu_tick, 15 | .draw = menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/tiles/sand/sand.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/sand.h" 11 | 12 | const tile_t sand = { 13 | .id = T_SAND, 14 | .water = false, 15 | .sand = true, 16 | .grass = false, 17 | .lava = false, 18 | .render = sand_render 19 | }; -------------------------------------------------------------------------------- /sources/entities/item_entity/item_entity_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/item_entity.h" 9 | 10 | const entity_funcs_t item_entity_funcs = { 11 | .draw = item_entity_draw, 12 | .destroy = item_entity_destroy, 13 | .tick = item_entity_tick, 14 | .touched_by = item_entity_touched_by 15 | }; -------------------------------------------------------------------------------- /sources/entities/item_entity/item_entity_touched_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void item_entity_touched_by(entity_t *self, entity_t *entity) 12 | { 13 | if (self->itm.time > 30 && !self->removed) 14 | (*entity->funcs.touch_item)(entity, self); 15 | } -------------------------------------------------------------------------------- /sources/entities/mob/mob_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/mob.h" 9 | 10 | const entity_funcs_t mob_funcs = { 11 | .tick = mob_tick, 12 | .hurt = mob_hurt, 13 | .do_hurt = mob_do_hurt, 14 | .move = mob_move, 15 | .hurt_tile = mob_hurt_tile, 16 | .start_pos = mob_start_pos 17 | }; -------------------------------------------------------------------------------- /sources/input/mkey_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "input.h" 10 | 11 | void mkey_tick(mkey_t *key) 12 | { 13 | if (key->absorbs < key->presses) { 14 | key->absorbs++; 15 | key->clicked = true; 16 | } else { 17 | key->clicked = false; 18 | } 19 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_draw_icon.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "screen.h" 10 | #include 11 | 12 | void resource_item_draw_icon(item_t *self, screen_t *screen, sfVector2i pos) 13 | { 14 | screen_render_item(screen, pos, self->res.resource->tex, 0); 15 | } -------------------------------------------------------------------------------- /sources/menus/text_input_menu/text_input_menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "menus/menu.h" 10 | 11 | void text_input_menu_destroy(menu_t *self) 12 | { 13 | self->input->buf = 0; 14 | self->input->buf_len = 0; 15 | self->input->buf_pos = 0; 16 | menu_destroy(self); 17 | } -------------------------------------------------------------------------------- /sources/tiles/cactus/cactus_bump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "entities/entity.h" 10 | #include "floor.h" 11 | #include 12 | 13 | void cactus_bump(tile_t self, floor_t *floor, sfVector2i pos, entity_t *entity) 14 | { 15 | (entity->funcs.hurt_tile)(entity, self, pos, 1); 16 | } -------------------------------------------------------------------------------- /sources/universe/universe_set_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "universe.h" 9 | #include "menus/menu.h" 10 | #include "menu_funcs.h" 11 | 12 | void universe_set_menu(universe_t *self, menu_t *menu) 13 | { 14 | self->menu = menu; 15 | if (menu) 16 | (menu->funcs.init)(menu, self, self->input); 17 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strcat 4 | ** File description: 5 | ** :wq 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strcat(char *dest, char const *src) 11 | { 12 | int dest_len = hsy_strlen(dest); 13 | int i = 0; 14 | 15 | for (i = 0; src[i]; i++) 16 | dest[i + dest_len] = src[i]; 17 | dest[i + dest_len] = '\0'; 18 | return (dest); 19 | } 20 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strncmp 4 | ** File description: 5 | ** r/ProgrammerHumor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_strncmp(char const *s1, char const *s2, int n) 11 | { 12 | for (int i = 0; i < n; i++) { 13 | if (s1[i] != s2[i] || !s1[i] || !s2[i]) { 14 | return (s1[i] - s2[i]); 15 | } 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /sources/engine/engine_internal_events.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | void engine_internal_events(engine_t *engine) 11 | { 12 | if (engine->event.type == sfEvtClosed) 13 | engine->state = EN_STOP; 14 | if (engine->event.type == sfEvtResized) 15 | engine_internal_resized(engine); 16 | } -------------------------------------------------------------------------------- /sources/game/game_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "universe.h" 10 | 11 | void game_event(engine_t *engine, sfEvent *event) 12 | { 13 | game_data_t *data = &engine->game_data; 14 | 15 | if (engine->game_data.universe->input) 16 | input_tick(engine->game_data.universe->input); 17 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_list_size.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | int recipe_list_size(recipe_t *list) 13 | { 14 | int i = 0; 15 | 16 | while (list) { 17 | list = list->next; 18 | i++; 19 | } 20 | return (i); 21 | } -------------------------------------------------------------------------------- /sources/tiles/wheat/wheat.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/wheat.h" 11 | 12 | const tile_t wheat = { 13 | .id = T_WHEAT, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = wheat_render 19 | }; -------------------------------------------------------------------------------- /include/entity_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ENTITY_LIST_H_ 9 | #define ENTITY_LIST_H_ 10 | 11 | #include "entities.h" 12 | 13 | typedef struct entity_list_s entity_list_t; 14 | typedef struct entity_list_s 15 | { 16 | int type; 17 | void *data; 18 | entity_list_t *next; 19 | } entity_list_t; 20 | 21 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_is_prime.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_is_prime 4 | ** File description: 5 | ** vim-epitech made by x4m3 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_is_prime(int nb) 11 | { 12 | if (nb <= 1) 13 | return (0); 14 | for (int i = nb - 1; i > 1; i--) { 15 | if (nb / i * i == nb) { 16 | return (0); 17 | } 18 | } 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /sources/entities/entities_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void entities_draw(entity_t *list, screen_t *screen) 12 | { 13 | while (list) { 14 | if (list->funcs.draw) { 15 | (*list->funcs.draw)(list, screen); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /sources/entities/item_entity/item_entity_take.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | 11 | void item_entity_take(entity_t *self, entity_t *player) 12 | { 13 | (self->itm.item->funcs.on_take)(self->itm.item, self); 14 | self->itm.picked_up = true; 15 | self->removed = true; 16 | } -------------------------------------------------------------------------------- /sources/tiles/carrot/carrot.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/carrot.h" 11 | 12 | const tile_t carrot = { 13 | .id = T_CARROT, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = carrot_render 19 | }; -------------------------------------------------------------------------------- /sources/tiles/flower/flower.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/flower.h" 11 | 12 | const tile_t flower = { 13 | .id = T_FLOWER, 14 | .water = false, 15 | .sand = false, 16 | .grass = true, 17 | .lava = false, 18 | .render = flower_render 19 | }; -------------------------------------------------------------------------------- /include/menus_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef MENUS_ID_H_ 9 | #define MENUS_ID_H_ 10 | 11 | enum { 12 | M_TITLE, 13 | M_INVENTORY, 14 | M_CRAFTING, 15 | M_DEATH, 16 | M_FLOOR_CHANGE, 17 | M_OPTIONS, 18 | M_WORLD_SELECT, 19 | M_TEXT_INPUT, 20 | M_PAUSE, 21 | M_ABOUT 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_compute_square_root.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_compute_square_root 4 | ** File description: 5 | ** don't forget to free at the end 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_compute_square_root(int nb) 11 | { 12 | if (nb <= 0) 13 | return (0); 14 | for (int i = 0; i * i <= nb; i++) 15 | if (i * i == nb) 16 | return (i); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_draw_icon.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "screen.h" 10 | 11 | void furniture_item_draw_icon(item_t *self, screen_t *screen, sfVector2i pos) 12 | { 13 | int tex = (self->funcs.get_tex)(self); 14 | 15 | screen_render_item(screen, pos, tex, 0); 16 | } -------------------------------------------------------------------------------- /include/csfml_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef CSFML_VERSION_H_ 9 | #define CSFML_VERSION_H_ 10 | 11 | 12 | #include 13 | 14 | #if CSFML_VERSION_MAJOR != 2 15 | #if CSFML_VERSION_MINOR != 5 16 | #error "ERROR ! This project can only be built with CSFML 2.5\n" 17 | #endif 18 | #endif 19 | 20 | #endif -------------------------------------------------------------------------------- /include/tiles/dirt.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef DIRT_H_ 9 | #define DIRT_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t dirt; 14 | 15 | void dirt_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool dirt_interact(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | 18 | #endif -------------------------------------------------------------------------------- /include/tiles/hole.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef HOLE_H_ 9 | #define HOLE_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t hole; 14 | 15 | void hole_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool hole_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | 18 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strupcase.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strupcase 4 | ** File description: 5 | ** M-x doctor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strupcase(char *str) 11 | { 12 | if (!str) 13 | return (0); 14 | for (int i = 0; str[i]; i++) { 15 | if ('a' <= str[i] && str[i] <= 'z') { 16 | str[i] -= 'a' - 'A'; 17 | } 18 | } 19 | return (str); 20 | } 21 | -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/furniture.h" 9 | 10 | const entity_funcs_t furniture_funcs = { 11 | .tick = furniture_tick, 12 | .draw = furniture_draw, 13 | .blocks = furniture_blocks, 14 | .touched_by = furniture_touched_by, 15 | .destroy = furniture_destroy 16 | }; -------------------------------------------------------------------------------- /sources/input/mkey_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "input.h" 11 | 12 | void mkey_init(mkey_t *key, int code, int id) 13 | { 14 | mkey_t empty = {0}; 15 | 16 | if (!key) 17 | return; 18 | *key = empty; 19 | key->code = code; 20 | key->id = id; 21 | } -------------------------------------------------------------------------------- /include/tiles/grass.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef GRASS_H_ 9 | #define GRASS_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t grass; 14 | 15 | void grass_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool grass_interact(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | 18 | #endif -------------------------------------------------------------------------------- /sources/engine/engine_internal_resized.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | void engine_internal_resized(engine_t *engine) 11 | { 12 | sfVector2u size = {engine->event.size.width, engine->event.size.height}; 13 | view_ratio(engine->view, size.x, size.y); 14 | sfRenderWindow_setView(engine->window, engine->view); 15 | } -------------------------------------------------------------------------------- /sources/entities/entity_start_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "entities/entity.h" 11 | #include "entities/player.h" 12 | #include "floor.h" 13 | #include "random.h" 14 | #include "tiles_id.h" 15 | 16 | bool entity_start_pos(entity_t *self, floor_t *floor) 17 | { 18 | return (false); 19 | } -------------------------------------------------------------------------------- /sources/main_menu/main_menu_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "universe.h" 10 | 11 | void main_menu_draw(engine_t *engine, sfRenderWindow *window) 12 | { 13 | menu_data_t *data = &engine->menu_data; 14 | game_data_t *game = &engine->game_data; 15 | 16 | title_menu_draw(data->menu, &data->screen); 17 | } 18 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_str_isupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_str_isupper 4 | ** File description: 5 | ** r/ProgrammerHumor 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_str_isupper(char const *str) 11 | { 12 | if (!str[0]) 13 | return (1); 14 | for (int i = 0; str[i]; i++) { 15 | if (!('A' <= str[i] && str[i] <= 'Z')) { 16 | return (0); 17 | } 18 | } 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strncpy 4 | ** File description: 5 | ** https://github.com/x4m3/vim-epitech 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strncpy(char *dest, char const *src, int n) 11 | { 12 | int i = 0; 13 | 14 | for (i = 0; i < n && src[i]; i++) 15 | dest[i] = src[i]; 16 | for (int j = i; j < n; j++) 17 | dest[i] = '\0'; 18 | return (dest); 19 | } 20 | -------------------------------------------------------------------------------- /sources/menus/about_menu/about_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t about_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = about_menu_tick, 15 | .draw = about_menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/menus/death_menu/death_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t death_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = death_menu_tick, 15 | .draw = death_menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/menus/pause_menu/pause_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t pause_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = pause_menu_tick, 15 | .draw = pause_menu_draw, 16 | .draw_item_list = menu_draw_item_list, 17 | .destroy = menu_destroy 18 | }; -------------------------------------------------------------------------------- /sources/tiles/hole/hole.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles/hole.h" 10 | #include "tiles_id.h" 11 | 12 | const tile_t hole = { 13 | .id = T_HOLE, 14 | .water = true, 15 | .sand = false, 16 | .grass = false, 17 | .lava = true, 18 | .render = hole_render, 19 | .may_pass = hole_may_pass 20 | }; -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_str_islower.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_str_islower 4 | ** File description: 5 | ** example of bad code: 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_str_islower(char const *str) 11 | { 12 | if (!str[0]) 13 | return (1); 14 | for (int i = 0; str[i]; i++) { 15 | if (!('a' <= str[i] && str[i] <= 'z')) { 16 | return (0); 17 | } 18 | } 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strncat 4 | ** File description: 5 | ** epitech > 42 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_strncat(char *dest, char const *src, int nb) 11 | { 12 | int dest_len = hsy_strlen(dest); 13 | int i = 0; 14 | 15 | for (i = 0; i < nb && src[i]; i++) 16 | dest[dest_len + i] = src[i]; 17 | dest[dest_len + i] = '\0'; 18 | return (dest); 19 | } 20 | -------------------------------------------------------------------------------- /sources/menus/floor_change_menu/floor_change_menu_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "universe.h" 10 | #include "menus/menu.h" 11 | #include "resources/item.h" 12 | #include "screen.h" 13 | 14 | void floor_change_menu_draw(menu_t *self, screen_t *screen) 15 | { 16 | screen_render_gui(screen, (sfVector2i){0, 0}, 54, 0); 17 | } -------------------------------------------------------------------------------- /sources/menus/title_menu/title_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t title_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = title_menu_tick, 15 | .draw = title_menu_draw, 16 | .destroy = title_menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/tiles/dirt/dirt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/dirt.h" 11 | 12 | const tile_t dirt = { 13 | .id = T_DIRT, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = dirt_render, 19 | .interact = dirt_interact 20 | }; -------------------------------------------------------------------------------- /include/game.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef GAME_H_ 9 | #define GAME_H_ 10 | 11 | #include 12 | 13 | typedef struct engine_s engine_t; 14 | 15 | void game_init(engine_t *engine); 16 | void game_update(engine_t *engine); 17 | void game_draw(engine_t *engine, sfRenderWindow *win); 18 | void game_destroy(engine_t *engine); 19 | 20 | #endif -------------------------------------------------------------------------------- /sources/entities/entities_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | void entities_add(entity_t **self, entity_t *entity) 11 | { 12 | entity_t *tmp = *self; 13 | 14 | if (!tmp) { 15 | *self = entity; 16 | return; 17 | } 18 | while (tmp->next) 19 | tmp = tmp->next; 20 | tmp->next = entity; 21 | } -------------------------------------------------------------------------------- /sources/input/mkey_release.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "input.h" 12 | 13 | void mkey_release(mkey_t *key) 14 | { 15 | int code = key->code; 16 | int id = key->id; 17 | 18 | memset(key, 0, sizeof(mkey_t)); 19 | key->code = code; 20 | key->id = id; 21 | } -------------------------------------------------------------------------------- /sources/menus/options_menu/options_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t options_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = options_menu_tick, 15 | .draw = options_menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/tiles/grass/grass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/grass.h" 11 | 12 | const tile_t grass = { 13 | .id = T_GRASS, 14 | .water = false, 15 | .sand = false, 16 | .grass = true, 17 | .lava = false, 18 | .render = grass_render, 19 | .interact = grass_interact 20 | }; -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_str_isalpha.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_str_is_aplha 4 | ** File description: 5 | ** epitech > epita 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_str_isalpha(char const *str) 11 | { 12 | if (!str[0]) 13 | return (1); 14 | for (int i = 0; str[i]; i++) { 15 | if (str[i] < 'A' || ('Z' < str[i] && str[i] < 'a') || 'z' < str[i]) 16 | return (0); 17 | } 18 | return (1); 19 | } 20 | -------------------------------------------------------------------------------- /sources/entities/entities_add_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "consts.h" 10 | 11 | void entities_add_all(entity_t **dest, entity_t **src) 12 | { 13 | int i = 0; 14 | 15 | while (*dest) 16 | i++; 17 | for (int j = 0; j < entities_per_tile && src[j]; j++) { 18 | dest[i + j] = src[j]; 19 | } 20 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_pay_stamina.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | bool player_pay_stamina(entity_t *self, int cost) 13 | { 14 | if (cost > self->mob.pla.stamina) 15 | return (false); 16 | self->mob.pla.stamina -= cost; 17 | return (true); 18 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_str_isprintable.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_str_isprintable 4 | ** File description: 5 | ** well, real programmers use ed 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_str_isprintable(char const *str) 11 | { 12 | if (!str[0]) 13 | return (1); 14 | for (int i = 0; str[i]; i++) { 15 | if (str[i] < ' ' || str[i] == 127) { 16 | return (0); 17 | } 18 | } 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /sources/entities/item_entity/item_entity_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "entities/entity.h" 11 | 12 | void item_entity_destroy(entity_t *self) 13 | { 14 | if (self->itm.item && !self->itm.picked_up) { 15 | (*self->itm.item->funcs.destroy)(self->itm.item); 16 | } 17 | entity_destroy(self); 18 | } -------------------------------------------------------------------------------- /sources/menus/inventory_menu/inventory_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t inventory_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = inventory_menu_tick, 15 | .draw = inventory_menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/recipes/recipe_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "recipe_funcs.h" 9 | #include "recipes/recipe.h" 10 | 11 | const recipe_funcs_t recipe_funcs = 12 | { 13 | .add_cost = recipe_add_cost, 14 | .check_can_craft = recipe_check_can_craft, 15 | .craft = recipe_craft, 16 | .deduct_cost = recipe_deduct_cost, 17 | .destroy = recipe_destroy 18 | }; -------------------------------------------------------------------------------- /sources/tiles/tree/tree_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/tree.h" 16 | 17 | void tree_hurt(floor_t *floor, sfVector2i pos, entity_t *entity, int dmg) 18 | { 19 | tree_damage(floor, pos, dmg); 20 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_str_isnum.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_str_isnum 4 | ** File description: 5 | ** if you code on paper, you're not a real programmer 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_str_isnum(char const *str) 11 | { 12 | if (!str[0]) 13 | return (1); 14 | for (int i = 0; str[i]; i++) { 15 | if (str[i] < '0' || '9' < str[i]) { 16 | return (0); 17 | } 18 | } 19 | return (1); 20 | } 21 | -------------------------------------------------------------------------------- /sources/menus/crafting_menu/crafting_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t crafting_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = crafting_menu_tick, 15 | .draw = crafting_menu_draw, 16 | .destroy = crafting_menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/game/game_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include 10 | #include "scenes.h" 11 | #include "universe.h" 12 | 13 | void game_draw(engine_t *engine, sfRenderWindow *win) 14 | { 15 | if (engine->game_data.universe && engine->game_data.screen) { 16 | universe_draw(engine->game_data.universe, engine->game_data.screen); 17 | } 18 | } -------------------------------------------------------------------------------- /sources/menus/world_select_menu/world_select_menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "menus/menu.h" 10 | 11 | void world_select_menu_destroy(menu_t *self) 12 | { 13 | for (int i = 0; i < 20 && self->wsm.worlds[i]; i++) { 14 | free(self->wsm.worlds[i]); 15 | } 16 | self->wsm.parent->child = 0; 17 | menu_destroy(self); 18 | } -------------------------------------------------------------------------------- /sources/tiles/lava/lava.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/lava.h" 11 | 12 | const tile_t lava = { 13 | .id = T_LAVA, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = true, 18 | .render = lava_render, 19 | .may_pass = lava_may_pass, 20 | .tick = lava_tick 21 | }; -------------------------------------------------------------------------------- /lib/hsy/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = git@github.com:hollowshiroyuki/libhsy.git 8 | branch = master 9 | commit = f6835668f8a44ffcfa4d914c8054c4ec5abc7950 10 | parent = 43a9c1067ab3190a1174b4f507179b0a2c92f4ce 11 | method = merge 12 | cmdver = 0.4.3 13 | -------------------------------------------------------------------------------- /sources/engine/engine_usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "hsy.h" 10 | #include "consts.h" 11 | 12 | static void print_usage(void) 13 | { 14 | hsy_putstr(USAGE_MSG); 15 | } 16 | 17 | bool engine_usage(engine_t *engine) 18 | { 19 | if (engine->argc > 1) { 20 | print_usage(); 21 | return (true); 22 | } 23 | return (false); 24 | } -------------------------------------------------------------------------------- /sources/menus/floor_change_menu/floor_change_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t floor_change_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = floor_change_menu_tick, 15 | .draw = floor_change_menu_draw, 16 | .destroy = menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/menus/text_input_menu/text_input_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t text_input_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = text_input_menu_tick, 15 | .draw = text_input_menu_draw, 16 | .destroy = text_input_menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/recipes/recipe_list_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "recipes/craft.h" 12 | 13 | void recipe_list_destroy(recipe_t *list) 14 | { 15 | recipe_t *tmp; 16 | 17 | while (list) { 18 | tmp = list->next; 19 | (list->funcs.destroy)(list); 20 | list = tmp; 21 | } 22 | } -------------------------------------------------------------------------------- /include/resources/plant_resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef PLANTABLE_RESOURCE_H_ 9 | #define PLANTABLE_RESOURCE_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | typedef struct plant_resource_s 14 | { 15 | tile_t *sources[5]; 16 | tile_t *target; 17 | } plant_resource_t; 18 | 19 | bool plant_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla); 20 | 21 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_revstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_revstr 4 | ** File description: 5 | ** code on paper! 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | char *hsy_revstr(char *str) 11 | { 12 | int len = hsy_strlen(str); 13 | 14 | for (int i = 0; i < len / 2; i++) { 15 | str[i] = str[i] ^ str[len - 1 - i]; 16 | str[len - 1 - i] = str[len - 1 - i] ^ str[i]; 17 | str[i] = str[i] ^ str[len - 1 - i]; 18 | } 19 | return (str); 20 | } 21 | -------------------------------------------------------------------------------- /sources/engine/engine_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "scenes.h" 10 | 11 | void engine_draw(engine_t *engine) 12 | { 13 | sfRenderWindow_clear(engine->window, sfBlack); 14 | if (scenes[engine->active_scene].draw) { 15 | (*scenes[engine->active_scene].draw)(engine, engine->window); 16 | } 17 | sfRenderWindow_display(engine->window); 18 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_add_cost.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/recipe.h" 11 | #include "resources/item.h" 12 | 13 | void recipe_add_cost(recipe_t *self, resource_t *res, int count) 14 | { 15 | item_t *cost = resource_item_create(res, count); 16 | 17 | item_list_add(&self->cost, cost, item_list_size(self->cost)); 18 | } -------------------------------------------------------------------------------- /sources/tiles/water/water.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/water.h" 11 | 12 | const tile_t water = { 13 | .id = T_WATER, 14 | .water = true, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = water_render, 19 | .may_pass = water_may_pass, 20 | .tick = water_tick 21 | }; -------------------------------------------------------------------------------- /sources/menus/world_select_menu/world_select.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "menus/menu.h" 9 | #include "menu_funcs.h" 10 | 11 | const menu_funcs_t world_select_menu_funcs = 12 | { 13 | .init = menu_init, 14 | .tick = world_select_menu_tick, 15 | .draw = world_select_menu_draw, 16 | .destroy = world_select_menu_destroy, 17 | .draw_item_list = menu_draw_item_list 18 | }; -------------------------------------------------------------------------------- /sources/tiles/cactus/cactus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/cactus.h" 11 | 12 | const tile_t cactus = { 13 | .id = T_CACTUS, 14 | .water = false, 15 | .sand = true, 16 | .grass = false, 17 | .lava = false, 18 | .render = cactus_render, 19 | .bump = cactus_bump, 20 | .may_pass = cactus_may_pass 21 | }; -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void furniture_item_save(item_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, " "); 18 | hsy_fd_putnbr(fd, self->fur.furniture->id); 19 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_list_delink.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "recipes/craft.h" 12 | 13 | void recipe_list_delink(recipe_t *list) 14 | { 15 | recipe_t *tmp; 16 | 17 | while (list) { 18 | tmp = list->next; 19 | free(list->result); 20 | free(list); 21 | list = tmp; 22 | } 23 | } -------------------------------------------------------------------------------- /sources/tiles/rock/rock_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/rock.h" 16 | 17 | void rock_hurt(floor_t *floor, sfVector2i pos, entity_t *entity, int dmg) 18 | { 19 | printf("ocuh\n"); 20 | rock_damage(floor, pos, dmg); 21 | } -------------------------------------------------------------------------------- /include/gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef GUI_H_ 9 | #define GUI_H_ 10 | 11 | #include 12 | #include "screen.h" 13 | 14 | void gui_text_draw(char *text, screen_t *screen, sfVector2i pos, sfColor color); 15 | void gui_frame_draw(screen_t *self, char *name, sfVector2i p1, sfVector2i p2); 16 | void gui_num_draw(int num, screen_t *screen, sfVector2i pos, sfColor color); 17 | 18 | #endif -------------------------------------------------------------------------------- /include/tiles/lava.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef LAVA_H_ 9 | #define LAVA_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t lava; 14 | 15 | void lava_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool lava_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | void lava_tick(tile_t self, floor_t *floor, sfVector2i pos); 18 | 19 | #endif -------------------------------------------------------------------------------- /sources/tiles/farmland/farmland.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/farmland.h" 11 | 12 | const tile_t farmland = { 13 | .id = T_FARMLAND, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = farmland_render, 19 | .step = farmland_step, 20 | .tick = farmland_tick 21 | }; -------------------------------------------------------------------------------- /include/tiles/water.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef WATER_H_ 9 | #define WATER_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t water; 14 | 15 | void water_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool water_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | void water_tick(tile_t self, floor_t *floor, sfVector2i pos); 18 | 19 | #endif -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "resources/item.h" 11 | #include "entities/entity.h" 12 | 13 | void furniture_item_destroy(item_t *self) 14 | { 15 | if (!(self->funcs.is_depleted)(self)) { 16 | (self->fur.furniture->funcs.destroy)(self->fur.furniture); 17 | } 18 | item_destroy(self); 19 | } -------------------------------------------------------------------------------- /sources/entities/mob/mob_is_swimming.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | bool mob_is_swimming(entity_t *self) 13 | { 14 | sfVector2i tile_pos = (sfVector2i){self->pos.x >> 4, self->pos.y >> 4}; 15 | tile_t tile = floor_get_tile(self->floor, tile_pos); 16 | 17 | return (tile.id == T_LAVA || tile.id == T_WATER); 18 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "inventory.h" 11 | 12 | void inventory_destroy(inventory_t *self) 13 | { 14 | item_t *tmp = self->items; 15 | item_t *next = 0; 16 | 17 | while (tmp) { 18 | next = tmp->next; 19 | (*tmp->funcs.destroy)(tmp); 20 | tmp = next; 21 | } 22 | free(self); 23 | } -------------------------------------------------------------------------------- /sources/tiles/rock/rock.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/rock.h" 11 | 12 | const tile_t rock = { 13 | .id = T_ROCK, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = rock_render, 19 | .may_pass = rock_may_pass, 20 | .hurt = rock_hurt, 21 | .interact = rock_interact 22 | }; -------------------------------------------------------------------------------- /sources/tiles/tree/tree.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/tree.h" 11 | 12 | const tile_t tree = { 13 | .id = T_TREE, 14 | .water = false, 15 | .sand = false, 16 | .grass = true, 17 | .lava = false, 18 | .may_pass = tree_may_pass, 19 | .render = tree_render, 20 | .hurt = tree_hurt, 21 | .interact = tree_interact 22 | }; -------------------------------------------------------------------------------- /sources/inventory/inventory_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "inventory.h" 11 | 12 | inventory_t *inventory_create(int capacity) 13 | { 14 | inventory_t *new = malloc(sizeof(inventory_t)); 15 | 16 | memset(new, 0, sizeof(inventory_t)); 17 | new->capacity = capacity; 18 | new->item_count = 0; 19 | new->items = 0; 20 | return (new); 21 | } -------------------------------------------------------------------------------- /include/tiles/cactus.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef CACTUS_H_ 9 | #define CACTUS_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t cactus; 14 | bool cactus_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 15 | void cactus_bump(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 16 | void cactus_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 17 | 18 | #endif -------------------------------------------------------------------------------- /include/tiles/farmland.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef FARMLAND_H_ 9 | #define FARMLAND_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t farmland; 14 | 15 | void farmland_tick(tile_t self, floor_t *floor, sfVector2i pos); 16 | void farmland_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p); 17 | void farmland_step(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 18 | 19 | #endif -------------------------------------------------------------------------------- /sources/entities/entities_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/zombie.h" 9 | #include "entities/mob.h" 10 | #include "entities/slime.h" 11 | #include "entities/workbench.h" 12 | #include "entities/entity.h" 13 | #include "entity_funcs.h" 14 | 15 | const entity_funcs_t *entities_funcs[] = { 16 | &entity_funcs, 17 | &mob_funcs, 18 | &slime_funcs, 19 | &zombie_funcs, 20 | &workbench_funcs 21 | }; -------------------------------------------------------------------------------- /sources/main_menu/main_menu_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "rpg.h" 10 | #include "menus/menu.h" 11 | 12 | void main_menu_destroy(engine_t *engine) 13 | { 14 | menu_data_t *data = &engine->menu_data; 15 | 16 | if (data->menu) 17 | (data->menu->funcs.destroy)(data->menu); 18 | if (data->input) 19 | free(data->input); 20 | screen_destroy(&data->screen); 21 | } -------------------------------------------------------------------------------- /sources/menus/about_menu/about_menu_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "universe.h" 10 | #include "menus/menu.h" 11 | #include "resources/item.h" 12 | 13 | void about_menu_tick(menu_t *self) 14 | { 15 | if (self->input->menu.clicked || self->input->escape.clicked) { 16 | self->about.parent->child = NULL; 17 | (self->funcs.destroy)(self); 18 | return; 19 | } 20 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_list_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | recipe_t *recipe_list_get(recipe_t *recipe, int pos) 13 | { 14 | int i = 0; 15 | 16 | while (recipe) { 17 | if (i == pos) { 18 | return (recipe); 19 | } 20 | i++; 21 | recipe = recipe->next; 22 | } 23 | return (0); 24 | } -------------------------------------------------------------------------------- /sources/tiles/farmland/farmland_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "random.h" 13 | #include "screen.h" 14 | #include 15 | 16 | void farmland_tick(tile_t self, floor_t *floor, sfVector2i pos) 17 | { 18 | int age = floor_get_data(floor, pos); 19 | 20 | if (age < 5) 21 | floor_set_data(floor, pos, age + 1); 22 | } -------------------------------------------------------------------------------- /sources/tiles/rock/rock_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/water.h" 16 | #include "entities/entity.h" 17 | #include 18 | 19 | bool rock_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 20 | { 21 | return (false); 22 | } -------------------------------------------------------------------------------- /sources/tiles/tree/tree_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/water.h" 16 | #include "entities/entity.h" 17 | #include 18 | 19 | bool tree_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 20 | { 21 | return (false); 22 | } -------------------------------------------------------------------------------- /sources/floor/floor_set_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "floor.h" 9 | #include "tiles/tile.h" 10 | #include "tiles.h" 11 | #include "tiles_id.h" 12 | 13 | void floor_set_data(floor_t *self, sfVector2i pos, int data) 14 | { 15 | if (pos.x < 0 || pos.y < 0) 16 | return; 17 | if (pos.x >= self->size.x || pos.y >= self->size.y) 18 | return; 19 | self->data[self->size.x * pos.y + pos.x] = data; 20 | } -------------------------------------------------------------------------------- /sources/items/food_interact.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/resource.h" 9 | #include "entities/entity.h" 10 | 11 | bool food_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla) 12 | { 13 | int c = s->food.stamina_cost; 14 | 15 | if (pla->mob.health < pla->mob.max_health && player_pay_stamina(pla, c)) { 16 | (pla->funcs.heal)(pla, s->food.heal); 17 | } 18 | return (false); 19 | } -------------------------------------------------------------------------------- /sources/recipes/tool_recipe/tool_recipe_craft.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void tool_recipe_craft(recipe_t *self, entity_t *player) 13 | { 14 | tool_type_t *tool_type = self->result->tool.type; 15 | item_t *result = tool_item_create(tool_type, self->result->tool.level); 16 | 17 | inventory_add(player->mob.pla.inventory, result); 18 | } -------------------------------------------------------------------------------- /include/tiles/ore.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ORE_H_ 9 | #define ORE_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t iron_ore; 14 | extern const tile_t lapis_ore; 15 | extern const tile_t gold_ore; 16 | extern const tile_t gem_ore; 17 | 18 | void ore_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 19 | bool ore_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 20 | 21 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strdup 4 | ** File description: 5 | ** echo $? 6 | */ 7 | 8 | #include 9 | #include "hsy.h" 10 | 11 | char *hsy_strdup(char const *str) 12 | { 13 | int len = hsy_strlen(str); 14 | char *dup; 15 | 16 | if (!str) 17 | return (0); 18 | if (!(dup = malloc(sizeof(char) * (len + 1)))) 19 | return (0); 20 | for (int i = 0; str[i]; i++) 21 | dup[i] = str[i]; 22 | dup[len] = '\0'; 23 | return (dup); 24 | } 25 | -------------------------------------------------------------------------------- /sources/entities/mob/player/player_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/player.h" 9 | 10 | const entity_funcs_t player_funcs = { 11 | .draw = player_draw, 12 | .start_pos = player_start_pos, 13 | .tick = player_tick, 14 | .hurt_tile = player_hurt_tile, 15 | .can_swim = player_can_swim, 16 | .destroy = player_destroy, 17 | .touch_item = player_touch_item, 18 | .do_hurt = player_do_hurt 19 | }; -------------------------------------------------------------------------------- /sources/items/resource_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/resources.h" 9 | #include "resources_id.h" 10 | 11 | resource_t *resource_get(int resource_id) 12 | { 13 | int tile_id = 0; 14 | 15 | for (int i = 0; i < R_COUNT && resources[i]; i++) { 16 | if (resources[i] && resources[i]->id == resource_id) 17 | return ((resource_t *)resources[i]); 18 | } 19 | return ((resource_t *)&r_dirt); 20 | } -------------------------------------------------------------------------------- /sources/tiles/hole/hole_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/water.h" 16 | #include "entities/entity.h" 17 | #include 18 | 19 | bool hole_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 20 | { 21 | return ((*e->funcs.can_swim)(e)); 22 | } -------------------------------------------------------------------------------- /sources/tiles/lava/lava_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/water.h" 16 | #include "entities/entity.h" 17 | #include 18 | 19 | bool lava_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 20 | { 21 | return ((*e->funcs.can_swim)(e)); 22 | } -------------------------------------------------------------------------------- /sources/input/input_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "input.h" 11 | 12 | bool input_tick(input_t *input) 13 | { 14 | for (int i = 0; i < C_COUNT; i++) { 15 | mkey_tick(&input->keys[i]); 16 | } 17 | mkey_tick(&input->tmp); 18 | if (!input->has_focus) { 19 | input_release_all(input); 20 | return (true); 21 | } 22 | return (false); 23 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "item_funcs.h" 9 | #include "resources/tool_item.h" 10 | 11 | const item_funcs_t tool_item_funcs = 12 | { 13 | .matches = item_matches, 14 | .attack_bonus = tool_item_attack_bonus, 15 | .can_attack = tool_item_can_attack, 16 | .draw_inventory = tool_item_draw_inventory, 17 | .draw_icon = tool_item_draw_icon, 18 | .get_tex = tool_item_get_tex 19 | }; -------------------------------------------------------------------------------- /sources/tiles/water/water_may_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "tiles/tile.h" 10 | #include "tiles_id.h" 11 | 12 | #include "floor.h" 13 | #include "screen.h" 14 | #include "random.h" 15 | #include "tiles/water.h" 16 | #include "entities/entity.h" 17 | #include 18 | 19 | bool water_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 20 | { 21 | return ((*e->funcs.can_swim)(e)); 22 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_sort_int_array.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_sort_int_array 4 | ** File description: 5 | ** xkcd.com/378 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | void hsy_sort_int_array(int *array, int size) 11 | { 12 | int swaps = 0; 13 | 14 | for (int i = 0; i < size - 1; i++) { 15 | if (array[i] > array[i + 1]) { 16 | hsy_int_swap(&array[i], &array[i + 1]); 17 | swaps += 1; 18 | } 19 | } 20 | if (swaps != 0) 21 | hsy_sort_int_array(array, size); 22 | } 23 | -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "entities_id.h" 13 | #include "hsy.h" 14 | #include "entities/furniture.h" 15 | #include "entities/workbench.h" 16 | 17 | void furniture_save(entity_t *self, int fd) 18 | { 19 | if (self->fur.id == F_WORKBENCH) 20 | workbench_save(self, fd); 21 | } -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_touched_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "entities_id.h" 10 | 11 | void furniture_touched_by(entity_t *self, entity_t *entity) 12 | { 13 | bool is_player = entity->id == E_MOB && entity->mob.id == MB_PLAYER; 14 | 15 | if (is_player && self->fur.push_time == 0) { 16 | self->fur.push_dir = entity->mob.dir; 17 | self->fur.push_time = 10; 18 | } 19 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_has_resources.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | #include "items_id.h" 10 | #include "resources/resource.h" 11 | 12 | bool inventory_has_resources(inventory_t *self, resource_t *res, int count) 13 | { 14 | item_t *has = inventory_find_resource(self, res); 15 | 16 | if (!has) 17 | return (false); 18 | if (has->res.count < count) 19 | return (false); 20 | return (true); 21 | } -------------------------------------------------------------------------------- /sources/recipes/resource_recipe/resource_recipe_craft.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | #include "entities/entity.h" 12 | 13 | void resource_recipe_craft(recipe_t *self, entity_t *player) 14 | { 15 | resource_t *res = self->res.res; 16 | item_t *result = resource_item_create(res, self->res.count); 17 | 18 | inventory_add(player->mob.pla.inventory, result); 19 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "inventory.h" 11 | 12 | void player_destroy(entity_t *self) 13 | { 14 | if (self->mob.pla.inventory) 15 | inventory_destroy(self->mob.pla.inventory); 16 | if (self->mob.pla.active_item) 17 | (self->mob.pla.active_item->funcs.destroy)(self->mob.pla.active_item); 18 | entity_destroy(self); 19 | } -------------------------------------------------------------------------------- /sources/entities/mob/mob_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "entities_id.h" 13 | #include "entities/zombie.h" 14 | #include "hsy.h" 15 | 16 | void mob_save(entity_t *self, int fd) 17 | { 18 | if (self->mob.id == MB_ZOMBIE) 19 | zombie_save(self, fd); 20 | if (self->mob.id == MB_SLIME) 21 | slime_save(self, fd); 22 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void tool_item_save(item_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, " "); 18 | hsy_fd_putnbr(fd, self->tool.type->id); 19 | hsy_fd_putstr(fd, " "); 20 | hsy_fd_putnbr(fd, self->tool.level); 21 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | 12 | void recipe_destroy(recipe_t *self) 13 | { 14 | item_t *tmp = 0; 15 | 16 | (self->result->funcs.destroy)(self->result); 17 | while (self->cost) { 18 | tmp = self->cost->next; 19 | (self->cost->funcs.destroy)(self->cost); 20 | self->cost = tmp; 21 | } 22 | free(self); 23 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2020 hollow <35398794+hollowshiroyuki@users.noreply.github.com> 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /sources/recipes/furniture_recipe/furniture_recipe_craft.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/craft.h" 11 | #include "entities/entity.h" 12 | 13 | void furniture_recipe_craft(recipe_t *self, entity_t *player) 14 | { 15 | entity_t *furniture = (*self->fur.create_furniture)(); 16 | item_t *result = furniture_item_create(furniture); 17 | 18 | inventory_add(player->mob.pla.inventory, result); 19 | } -------------------------------------------------------------------------------- /sources/asset_manager/asset_manager_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "consts.h" 10 | 11 | void asset_manager_init(engine_t *engine) 12 | { 13 | engine->assets.entities = sfTexture_createFromFile(TEX_ENTITIES, NULL); 14 | engine->assets.gui = sfTexture_createFromFile(TEX_GUI, NULL); 15 | engine->assets.items = sfTexture_createFromFile(TEX_ITEMS, NULL); 16 | engine->assets.tiles = sfTexture_createFromFile(TEX_TILES, NULL); 17 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void resource_item_save(item_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, " "); 18 | hsy_fd_putnbr(fd, self->res.resource->id); 19 | hsy_fd_putstr(fd, " "); 20 | hsy_fd_putnbr(fd, self->res.count); 21 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_atoi.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** libhsy [WSL: Ubuntu-20.04] 4 | ** File description: 5 | ** hsy_atoi 6 | */ 7 | 8 | int hsy_atoi(char const *str) 9 | { 10 | int res = 0; 11 | int sign = 1; 12 | int i = 0; 13 | 14 | if (str[0] == '-') { 15 | sign = -1; 16 | i++; 17 | } 18 | for (int j = i; str[j] != '\0'; ++j) { 19 | if ('0' <= str[j] && str[j] <= '9') 20 | res = res * 10 + str[j] - '0'; 21 | else 22 | return (0); 23 | } 24 | return (sign * res); 25 | } -------------------------------------------------------------------------------- /sources/engine/engine_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "scenes.h" 10 | 11 | void engine_destroy(engine_t *engine) 12 | { 13 | for (int i = 0; i < S_COUNT; i++) { 14 | if (scenes[i].destroy) { 15 | (*scenes[i].destroy)(engine); 16 | } 17 | } 18 | sfClock_destroy(engine->tick_clk); 19 | sfClock_destroy(engine->second_clk); 20 | window_destroy(engine); 21 | asset_manager_destroy(engine); 22 | } -------------------------------------------------------------------------------- /sources/floor/floor_set_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "floor.h" 9 | #include "tiles/tile.h" 10 | #include "tiles.h" 11 | #include "tiles_id.h" 12 | 13 | void floor_set_tile(floor_t *self, sfVector2i pos, const tile_t tile, int data) 14 | { 15 | if (!pos.x || !pos.y || pos.x >= self->size.x || pos.y >= self->size.y) 16 | return; 17 | self->tiles[self->size.x * pos.y + pos.x] = tile.id; 18 | self->data[self->size.x * pos.y + pos.x] = data; 19 | } -------------------------------------------------------------------------------- /sources/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "csfml_version.h" 9 | #include "rpg.h" 10 | #include "scenes.h" 11 | #include "entities.h" 12 | 13 | int main(int ac, char **av, char **env) 14 | { 15 | engine_t engine = {.argc = ac, .argv = av, .envp = env}; 16 | 17 | if (engine_usage(&engine)) 18 | return (engine.ret); 19 | engine_init(&engine); 20 | if (engine.state == EN_RUN) 21 | engine_start(&engine); 22 | return (engine.ret); 23 | } -------------------------------------------------------------------------------- /include/entities/workbench.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef WORKBENCH_H_ 9 | #define WORKBENCH_H_ 10 | 11 | #include "entity_funcs.h" 12 | 13 | typedef struct entity_s entity_t; 14 | 15 | extern const entity_funcs_t workbench_funcs; 16 | 17 | typedef struct workbench_s 18 | { 19 | } workbench_t; 20 | 21 | entity_t *workbench_create(void); 22 | bool workbench_use(entity_t *self, entity_t *player, int dir); 23 | void workbench_save(entity_t *self, int fd); 24 | 25 | #endif -------------------------------------------------------------------------------- /sources/floor/floor_get_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "floor.h" 9 | #include "tiles/tile.h" 10 | #include "tiles.h" 11 | #include "tiles_id.h" 12 | 13 | int floor_get_data(floor_t *self, sfVector2i pos) 14 | { 15 | int data = 0; 16 | 17 | if (pos.x < 0 || pos.y < 0) 18 | return (0); 19 | if (pos.x >= self->size.x || pos.y >= self->size.y) 20 | return (0); 21 | data = self->data[self->size.x * pos.y + pos.x]; 22 | return (data); 23 | } -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_draw_inventory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "gui.h" 10 | #include "screen.h" 11 | 12 | void tool_item_draw_inventory(item_t *self, screen_t *screen, sfVector2i pos) 13 | { 14 | sfVector2i off_pos = (sfVector2i){pos.x + 8, pos.y}; 15 | int tex = (self->funcs.get_tex)(self); 16 | 17 | screen_render_item(screen, pos, tex, 0); 18 | gui_text_draw(self->tool.name, screen, off_pos, sfWhite); 19 | } -------------------------------------------------------------------------------- /include/resources/food_resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef FOOD_RESOURCE_H_ 9 | #define FOOD_RESOURCE_H_ 10 | 11 | #include 12 | typedef struct resource_s resource_t; 13 | typedef struct entity_s entity_t; 14 | typedef struct tile_s tile_t; 15 | 16 | typedef struct food_resource_s 17 | { 18 | int heal; 19 | int stamina_cost; 20 | } food_resource_t; 21 | 22 | bool food_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla); 23 | 24 | #endif -------------------------------------------------------------------------------- /sources/entities/mob/slime/slime_touched_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "entities/slime.h" 10 | #include "screen.h" 11 | #include 12 | #include "entities_id.h" 13 | 14 | void slime_touched_by(entity_t *self, entity_t *entity) 15 | { 16 | int dmg = self->mob.sli.level + 1; 17 | 18 | if (entity->id == E_MOB && entity->mob.id == MB_PLAYER) { 19 | (entity->funcs.hurt)(entity, self, dmg, self->mob.dir); 20 | } 21 | } -------------------------------------------------------------------------------- /sources/entities/mob/zombie/zombie_touched_by.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "entities/slime.h" 10 | #include "screen.h" 11 | #include 12 | #include "entities_id.h" 13 | 14 | void zombie_touched_by(entity_t *self, entity_t *entity) 15 | { 16 | int dmg = self->mob.zom.level + 2; 17 | 18 | if (entity->id == E_MOB && entity->mob.id == MB_PLAYER) { 19 | (entity->funcs.hurt)(entity, self, dmg, self->mob.dir); 20 | } 21 | } -------------------------------------------------------------------------------- /sources/game/game_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "rpg.h" 11 | #include "scenes.h" 12 | #include "universe.h" 13 | 14 | void game_destroy(engine_t *engine) 15 | { 16 | game_data_t *data = &engine->game_data; 17 | menu_data_t *menu = &engine->menu_data; 18 | 19 | if (data->universe) { 20 | universe_destroy(data->universe); 21 | data->universe = 0; 22 | menu->universe = 0; 23 | } 24 | } -------------------------------------------------------------------------------- /sources/random/random_gaussian.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "random.h" 10 | #include "math.h" 11 | 12 | float random_gaussian(void) 13 | { 14 | double u; 15 | double v; 16 | double s; 17 | double fac; 18 | 19 | do { 20 | u = 2.0 * random_float() - 1; 21 | v = 2.0 * random_float() - 1; 22 | s = u * u + v * v; 23 | } while (s >= 1.0); 24 | fac = sqrt(-2.0 * log(s) / s); 25 | return (u * fac); 26 | } -------------------------------------------------------------------------------- /sources/tiles/farmland/farmland_step.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "random.h" 13 | #include "screen.h" 14 | #include "tiles/dirt.h" 15 | 16 | void farmland_step(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e) 17 | { 18 | if (random_int(60) != 0) 19 | return; 20 | if (floor_get_data(floor, pos) < 5) 21 | return; 22 | floor_set_tile(floor, pos, dirt, 0); 23 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strndup.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** libhsy [WSL: Ubuntu-20.04] 4 | ** File description: 5 | ** hsy_strndup 6 | */ 7 | 8 | #include "hsy.h" 9 | #include 10 | 11 | char *hsy_strndup(char const *str, size_t n) 12 | { 13 | size_t len = hsy_strlen(str) + 1; 14 | char *dup = 0; 15 | 16 | len = (len > n) ? n + 1 : len; 17 | if (!(dup = malloc(sizeof(char) * len))) 18 | return (0); 19 | dup[len - 1] = '\0'; 20 | for (size_t i = 0; i < len; i++) { 21 | dup[i] = str[i]; 22 | } 23 | return (dup); 24 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_get_attack_damage.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "random.h" 9 | #include "entities/entity.h" 10 | #include "entities_id.h" 11 | #include "resources/item.h" 12 | 13 | int player_get_attack_damage(entity_t *self, entity_t *entity) 14 | { 15 | int dmg = random_int(3) + 1; 16 | item_t *item = self->mob.pla.active_item; 17 | 18 | if (item) { 19 | dmg += (item->funcs.attack_bonus)(item, entity); 20 | } 21 | return (dmg); 22 | } -------------------------------------------------------------------------------- /sources/game/game_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include 10 | #include "scenes.h" 11 | #include "universe.h" 12 | #include "entities/workbench.h" 13 | #include "resources/resources.h" 14 | 15 | void game_init(engine_t *engine) 16 | { 17 | game_data_t *data = &engine->game_data; 18 | menu_data_t *menu = &engine->menu_data; 19 | 20 | data->universe = menu->universe; 21 | data->input = menu->input; 22 | data->screen = &menu->screen; 23 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_interact_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | bool resource_item_interact_tile(item_t *self, tile_t t, sfVector2i p, 11 | entity_t *player) 12 | { 13 | resource_t *res = self->res.resource; 14 | bool interact = (*res->interact)(res, t, p, player); 15 | 16 | if (interact) { 17 | self->res.count--; 18 | return (true); 19 | } 20 | return (false); 21 | } -------------------------------------------------------------------------------- /sources/engine/engine_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "scenes.h" 10 | 11 | void engine_init(engine_t *engine) 12 | { 13 | window_init(engine); 14 | asset_manager_init(engine); 15 | engine->second_clk = sfClock_create(); 16 | engine->tick_clk = sfClock_create(); 17 | engine->fps = 0; 18 | engine->tick_count = 0; 19 | engine->ticks = 0; 20 | engine->active_scene = 0; 21 | (*scenes[0].init)(engine); 22 | engine->state = EN_RUN; 23 | } -------------------------------------------------------------------------------- /sources/entities/furniture/workbench/workbench_use.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/workbench.h" 9 | #include "universe.h" 10 | #include 11 | 12 | bool workbench_use(entity_t *self, entity_t *player, int dir) 13 | { 14 | universe_t *uni = player->mob.pla.universe; 15 | recipe_t *recipes = uni->craft->workbench; 16 | menu_t *craft_menu = crafting_menu_create(recipes, player, "Crafting"); 17 | 18 | universe_set_menu(uni, craft_menu); 19 | return (true); 20 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "item_funcs.h" 9 | #include "resources/resource_item.h" 10 | 11 | const item_funcs_t resource_item_funcs = 12 | { 13 | .draw_inventory = resource_item_draw_inventory, 14 | .draw_icon = resource_item_draw_icon, 15 | .get_tex = resource_item_get_tex, 16 | .interact_tile = resource_item_interact_tile, 17 | .is_depleted = resource_item_is_depleted, 18 | .get_name = resource_item_get_name 19 | }; -------------------------------------------------------------------------------- /include/menus/about_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ABOUT_MENU_H_ 9 | #define ABOUT_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include 13 | 14 | extern const menu_funcs_t about_menu_funcs; 15 | 16 | typedef struct about_menu_s 17 | { 18 | int page; 19 | menu_t *parent; 20 | } about_menu_t; 21 | 22 | menu_t *about_menu_create(input_t *input, menu_t *ptr); 23 | void about_menu_tick(menu_t *self); 24 | void about_menu_draw(menu_t *self, screen_t *screen); 25 | 26 | #endif -------------------------------------------------------------------------------- /sources/items/item_list_remove.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | 10 | void item_list_remove(item_t **list, item_t *item) 11 | { 12 | item_t *tmp = *list; 13 | item_t *prv = NULL; 14 | 15 | if (tmp == item) { 16 | *list = tmp->next; 17 | } else { 18 | while (tmp && tmp != item) { 19 | prv = tmp; 20 | tmp = tmp->next; 21 | } 22 | if (tmp) { 23 | prv->next = tmp->next; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /sources/asset_manager/asset_manager_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | void asset_manager_destroy(engine_t *engine) 11 | { 12 | if (engine->assets.entities) 13 | sfTexture_destroy(engine->assets.entities); 14 | if (engine->assets.gui) 15 | sfTexture_destroy(engine->assets.gui); 16 | if (engine->assets.items) 17 | sfTexture_destroy(engine->assets.items); 18 | if (engine->assets.tiles) 19 | sfTexture_destroy(engine->assets.tiles); 20 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_remove_item.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | #include "items_id.h" 10 | #include "resources/resource.h" 11 | 12 | item_t *inventory_remove_item(inventory_t *self, int pos) 13 | { 14 | item_t *to_remove = self->items; 15 | 16 | if (pos > item_list_size(self->items)) 17 | return (0); 18 | for (int i = 0; i < pos; i++) 19 | to_remove = to_remove->next; 20 | item_list_remove(&self->items, to_remove); 21 | return (to_remove); 22 | } -------------------------------------------------------------------------------- /sources/items/item_list_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "resources/item.h" 10 | 11 | void item_list_add(item_t **list, item_t *new, int pos) 12 | { 13 | item_t *tmp; 14 | 15 | if (pos < 1 || pos > item_list_size(*list) + 1) 16 | pos = item_list_size(*list) + 1; 17 | while (pos--) { 18 | if (pos == 0) { 19 | new->next = *list; 20 | *list = new; 21 | } else { 22 | list = &(*list)->next; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /sources/screen/screen_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "screen.h" 10 | #include "consts.h" 11 | 12 | void screen_destroy(screen_t *self) 13 | { 14 | if (!self) 15 | return; 16 | if (self->e_sprite) 17 | sfSprite_destroy(self->e_sprite); 18 | if (self->t_sprite) 19 | sfSprite_destroy(self->t_sprite); 20 | if (self->i_sprite) 21 | sfSprite_destroy(self->i_sprite); 22 | if (self->g_sprite) 23 | sfSprite_destroy(self->g_sprite); 24 | } -------------------------------------------------------------------------------- /include/resources_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RESOURCES_ID_H_ 9 | #define RESOURCES_ID_H_ 10 | 11 | typedef enum 12 | { 13 | R_FLOWER, 14 | R_WHEAT, 15 | R_BREAD, 16 | R_LEATHER, 17 | R_CLOTH, 18 | R_RAW_PORK, 19 | R_CKD_PORK, 20 | R_RAW_BEEF, 21 | R_CKD_BEEF, 22 | R_RAW_FISH, 23 | R_CKD_FISH, 24 | R_WOOD, 25 | R_STONE, 26 | R_ACORN, 27 | R_DIRT, 28 | R_APPLE, 29 | R_SLIME, 30 | R_SEEDS, 31 | R_COUNT 32 | } resources_id_t; 33 | 34 | #endif -------------------------------------------------------------------------------- /sources/entities/entity_intersects.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | 10 | bool entity_intersects(entity_t *self, sfVector2i pos1, sfVector2i pos2) 11 | { 12 | sfVector2i p; 13 | bool faces[4]; 14 | 15 | faces[0] = self->pos.x + self->box.x < pos1.x; 16 | faces[1] = self->pos.y + self->box.y < pos1.y; 17 | faces[2] = self->pos.x - self->box.x > pos2.x; 18 | faces[3] = self->pos.y - self->box.y > pos2.y; 19 | return (!(faces[0] || faces[1] || faces[2] || faces[3])); 20 | } -------------------------------------------------------------------------------- /sources/menus/death_menu/death_menu_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "menus/menu.h" 11 | #include "menus_id.h" 12 | #include "universe.h" 13 | #include "hsy.h" 14 | #include 15 | 16 | menu_t *death_menu_create(entity_t *player) 17 | { 18 | menu_t *new = malloc(sizeof(menu_t)); 19 | 20 | memset(new, 0, sizeof(menu_t)); 21 | new->id = M_DEATH; 22 | new->dea.player = player; 23 | new->funcs = death_menu_funcs; 24 | return (new); 25 | } -------------------------------------------------------------------------------- /sources/menus/pause_menu/pause_menu_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "menus/menu.h" 11 | #include "menus_id.h" 12 | #include "universe.h" 13 | #include "hsy.h" 14 | #include 15 | 16 | menu_t *pause_menu_create(entity_t *player) 17 | { 18 | menu_t *new = malloc(sizeof(menu_t)); 19 | 20 | memset(new, 0, sizeof(menu_t)); 21 | new->id = M_PAUSE; 22 | new->dea.player = player; 23 | new->funcs = pause_menu_funcs; 24 | return (new); 25 | } -------------------------------------------------------------------------------- /sources/recipes/craft_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "recipes/craft.h" 12 | 13 | craft_t *craft_create(void) 14 | { 15 | craft_t *new = malloc(sizeof(craft_t)); 16 | 17 | memset(new, 0, sizeof(craft_t)); 18 | new->workbench = workbench_recipes_create(); 19 | //new->anvil = anvil_recipes_create(); 20 | //new->oven = oven_recipes_create(); 21 | //new->furnace = furnace_recipes_create(); 22 | return (new); 23 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_find_resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | #include "items_id.h" 10 | #include "resources/resource.h" 11 | 12 | item_t *inventory_find_resource(inventory_t *self, resource_t *res) 13 | { 14 | item_t *tmp = self->items; 15 | 16 | while (tmp) { 17 | if (tmp->id == I_RESOURCE) { 18 | if (tmp->res.resource->id == res->id) { 19 | return (tmp); 20 | } 21 | } 22 | tmp = tmp->next; 23 | } 24 | return (0); 25 | } -------------------------------------------------------------------------------- /sources/items/item_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "items_id.h" 13 | #include "resources/item.h" 14 | #include "hsy.h" 15 | 16 | void item_save(item_t *self, int fd) 17 | { 18 | if (self->id == I_FURNITURE) 19 | furniture_item_save(self, fd); 20 | if (self->id == I_TOOL) 21 | tool_item_save(self, fd); 22 | if (self->id == I_RESOURCE) 23 | resource_item_save(self, fd); 24 | } -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_compute_power_rec.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_compute_power_rec 4 | ** File description: 5 | ** well, real programmers use ed 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_compute_power_rec(int nb, int p) 11 | { 12 | int ret = 0; 13 | int old = nb; 14 | 15 | if (p < 0) 16 | return (0); 17 | if (p == 1) 18 | return (nb); 19 | if (p == 0) 20 | return (1); 21 | ret = nb * hsy_compute_power_rec(nb, p - 1); 22 | if (!((ret <= 0) ^ (old > 0)) && nb > 0) 23 | return (0); 24 | return (nb * hsy_compute_power_rec(nb, p - 1)); 25 | } 26 | -------------------------------------------------------------------------------- /sources/level_gen/level_gen_create_top_map/top_map_generate_cactus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "level_gen.h" 9 | #include "tiles_id.h" 10 | #include "random.h" 11 | 12 | void generate_cactus(int *m, sfVector2i s) 13 | { 14 | for (int i = 0; i < s.x * s.y / 50; i++) { 15 | int x = random_int(s.x); 16 | int y = random_int(s.y); 17 | if (x < 0 || y < 0 || x >= s.x || y >= s.y) 18 | continue; 19 | if (m[x + y * s.x] == T_SAND) 20 | m[x + y * s.x] = T_CACTUS; 21 | } 22 | } -------------------------------------------------------------------------------- /sources/main_menu/main_menu_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "universe.h" 10 | 11 | void main_menu_init(engine_t *engine) 12 | { 13 | menu_data_t *data = &engine->menu_data; 14 | game_data_t *game = &engine->game_data; 15 | 16 | screen_init(&data->screen, &engine->assets, engine->window); 17 | data->input = input_create(); 18 | data->menu = title_menu_create(data); 19 | menu_init(data->menu, game->universe, data->input); 20 | data->init = true; 21 | data->stop = false; 22 | } 23 | -------------------------------------------------------------------------------- /sources/recipes/recipe_deduct_cost.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "items_id.h" 11 | #include "recipes/craft.h" 12 | 13 | void recipe_deduct_cost(recipe_t *self, entity_t *player) 14 | { 15 | item_t *cur = self->cost; 16 | inventory_t *inv = player->mob.pla.inventory; 17 | 18 | while (cur) { 19 | if (cur->id == I_RESOURCE) { 20 | inventory_remove_resource(inv, cur->res.resource, cur->res.count); 21 | } 22 | cur = cur->next; 23 | } 24 | } -------------------------------------------------------------------------------- /sources/recipes/recipe_funcs_combine.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "recipe_funcs.h" 9 | #include "recipes/recipe.h" 10 | 11 | void recipe_funcs_combine(recipe_funcs_t *d, const recipe_funcs_t *r_f) 12 | { 13 | d->add_cost = r_f->add_cost ?: recipe_funcs.add_cost; 14 | d->check_can_craft = r_f->check_can_craft ?: recipe_funcs.check_can_craft; 15 | d->craft = r_f->craft ?: recipe_funcs.craft; 16 | d->deduct_cost = r_f->deduct_cost ?: recipe_funcs.deduct_cost; 17 | d->destroy = r_f->destroy ?: recipe_funcs.destroy; 18 | } -------------------------------------------------------------------------------- /sources/items/item_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "item_funcs.h" 9 | 10 | const item_funcs_t item_funcs = 11 | { 12 | .get_tex = item_get_tex, 13 | .on_take = item_on_take, 14 | .draw_inventory = item_draw_inventory, 15 | .interact = item_interact, 16 | .interact_tile = item_interact_tile, 17 | .is_depleted = item_is_depleted, 18 | .can_attack = item_can_attack, 19 | .attack_bonus = item_attack_bonus, 20 | .get_name = item_get_name, 21 | .matches = item_matches, 22 | .destroy = item_destroy 23 | }; -------------------------------------------------------------------------------- /include/menus/floor_change_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef FLOOR_CHANGE_MENU_H_ 9 | #define FLOOR_CHANGE_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | 13 | extern const menu_funcs_t floor_change_menu_funcs; 14 | 15 | typedef struct entity_s entity_t; 16 | 17 | typedef struct floor_change_menu_s 18 | { 19 | int time; 20 | int dir; 21 | } floor_change_menu_t; 22 | 23 | menu_t *floor_change_menu_create(int dir); 24 | void floor_change_menu_tick(menu_t *self); 25 | void floor_change_menu_draw(menu_t *self, screen_t *screen); 26 | 27 | #endif -------------------------------------------------------------------------------- /include/recipes/craft.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef CRAFT_H_ 9 | #define CRAFT_H_ 10 | 11 | #include "recipes/recipe.h" 12 | 13 | typedef struct craft_s 14 | { 15 | recipe_t *workbench; 16 | recipe_t *anvil; 17 | recipe_t *oven; 18 | recipe_t *furnace; 19 | } craft_t; 20 | 21 | craft_t *craft_create(void); 22 | recipe_t *workbench_recipes_create(void); 23 | recipe_t *anvil_recipes_create(void); 24 | recipe_t *oven_recipes_create(void); 25 | recipe_t *furnace_recipes_create(void); 26 | void craft_destroy(craft_t *self); 27 | 28 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_fd_putnbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_put_nbr 4 | ** File description: 5 | ** vim > emacs 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | ssize_t hsy_fd_putnbr(int fd, int i) 11 | { 12 | ssize_t ret = 0; 13 | 14 | if (i == -2147483648) { 15 | hsy_fd_putnbr(fd, -214748364); 16 | hsy_fd_putchar(fd, '8'); 17 | return (11); 18 | } 19 | if (i < 0) { 20 | i *= -1; 21 | ret += 1; 22 | hsy_fd_putchar(fd, '-'); 23 | } 24 | if (i > 9) 25 | ret += hsy_fd_putnbr(fd, i / 10); 26 | hsy_fd_putchar(fd, '0' + i % 10); 27 | return (ret + 1); 28 | } 29 | -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "resources/item.h" 11 | #include "items_id.h" 12 | #include "entities/entity.h" 13 | #include "hsy.h" 14 | 15 | item_t *furniture_item_create(entity_t *furniture) 16 | { 17 | item_t *new = malloc(sizeof(item_t)); 18 | 19 | memset(new, 0, sizeof(item_t)); 20 | new->id = I_FURNITURE; 21 | new->fur.furniture = furniture; 22 | item_funcs_combine(&new->funcs, &furniture_item_funcs); 23 | return (new); 24 | } -------------------------------------------------------------------------------- /sources/screen/screen_sprite_flip.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "screen.h" 10 | #include "consts.h" 11 | 12 | void screen_sprite_flip(sfSprite *sprite, int m) 13 | { 14 | sfIntRect r = sfSprite_getTextureRect(sprite); 15 | sfVector2f s = (sfVector2f){r.width, r.height}; 16 | sfVector2f sc = (sfVector2f){(m & HOR_F) ? -1 : 1, (m & VER_F) ? -1 : 1}; 17 | sfVector2f o = (sfVector2f){(m & HOR_F) ? s.x : 0, (m & VER_F) ? s.y : 0}; 18 | 19 | sfSprite_setOrigin(sprite, o); 20 | sfSprite_setScale(sprite, sc); 21 | } -------------------------------------------------------------------------------- /include/resources/resources.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RESOURCES_H_ 9 | #define RESOURCES_H_ 10 | 11 | #include "resources/resource.h" 12 | 13 | extern const resource_t r_dirt; 14 | extern const resource_t r_bread; 15 | extern const resource_t r_wood; 16 | extern const resource_t r_stone; 17 | extern const resource_t r_apple; 18 | extern const resource_t r_slime; 19 | extern const resource_t r_cloth; 20 | extern const resource_t r_seeds; 21 | 22 | extern const resource_t *resources[]; 23 | 24 | resource_t *resource_get(int resource_id); 25 | 26 | #endif -------------------------------------------------------------------------------- /include/tiles/rock.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ROCK_H_ 9 | #define ROCK_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t rock; 14 | 15 | void rock_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool rock_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | void rock_damage(floor_t *floor, sfVector2i pos, int dmg); 18 | void rock_hurt(floor_t *floor, sfVector2i pos, entity_t *entity, int dmg); 19 | bool rock_interact(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 20 | 21 | #endif -------------------------------------------------------------------------------- /include/tiles/tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TREE_H_ 9 | #define TREE_H_ 10 | 11 | #include "tiles/tile.h" 12 | 13 | extern const tile_t tree; 14 | 15 | void tree_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i pos); 16 | bool tree_may_pass(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 17 | void tree_damage(floor_t *floor, sfVector2i pos, int dmg); 18 | bool tree_interact(tile_t self, floor_t *floor, sfVector2i pos, entity_t *e); 19 | void tree_hurt(floor_t *floor, sfVector2i pos, entity_t *entity, int dmg); 20 | 21 | #endif -------------------------------------------------------------------------------- /include/menus/inventory_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef INVENTORY_MENU_H_ 9 | #define INVENTORY_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | 13 | extern const menu_funcs_t inventory_menu_funcs; 14 | 15 | typedef struct entity_s entity_t; 16 | 17 | typedef struct inventory_menu_s 18 | { 19 | int selection; 20 | entity_t *player; 21 | } inventory_menu_t; 22 | 23 | menu_t *inventory_menu_create(entity_t *player, char *name); 24 | void inventory_menu_tick(menu_t *self); 25 | void inventory_menu_draw(menu_t *self, screen_t *screen); 26 | 27 | #endif -------------------------------------------------------------------------------- /sources/engine/engine_events.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | #include "scenes.h" 10 | #include "input.h" 11 | 12 | void engine_events(engine_t *engine) 13 | { 14 | while (sfRenderWindow_pollEvent(engine->window, &engine->event)) { 15 | engine_internal_events(engine); 16 | if (engine->menu_data.input) 17 | input_event(engine->menu_data.input, &engine->event); 18 | if (scenes[engine->active_scene].event) { 19 | (scenes[engine->active_scene].event)(engine, &engine->event); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /sources/tiles/dirt/dirt_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "floor.h" 11 | #include "screen.h" 12 | 13 | void dirt_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 14 | { 15 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, 76, 0); 16 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, 77, 0); 17 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, 109, 0); 18 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, 108, 0); 19 | } -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_draw_inventory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "gui.h" 10 | #include "screen.h" 11 | #include "entities/entity.h" 12 | 13 | void furniture_item_draw_inventory(item_t *self, screen_t *scr, sfVector2i p) 14 | { 15 | sfVector2i off_pos = (sfVector2i){p.x + 8, p.y}; 16 | char *furniture_name = self->fur.furniture->fur.name; 17 | int tex = (self->funcs.get_tex)(self); 18 | 19 | furniture_item_draw_icon(self, scr, p); 20 | gui_text_draw(furniture_name, scr, off_pos, sfWhite); 21 | } -------------------------------------------------------------------------------- /sources/tiles/stair/stair.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | #include "tiles/stair.h" 11 | 12 | const tile_t stair_up = { 13 | .id = T_STAIRUP, 14 | .water = false, 15 | .sand = false, 16 | .grass = false, 17 | .lava = false, 18 | .render = stair_render, 19 | .variant = 1 20 | }; 21 | 22 | const tile_t stair_down = { 23 | .id = T_STAIRDOWN, 24 | .water = false, 25 | .sand = false, 26 | .grass = false, 27 | .lava = false, 28 | .render = stair_render, 29 | .variant = 0 30 | }; -------------------------------------------------------------------------------- /sources/inventory/inventory_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void inventory_save(inventory_t *inventory, int fd) 15 | { 16 | hsy_fd_putstr(fd, "I|"); 17 | hsy_fd_putnbr(fd, inventory->capacity); 18 | if (inventory->items) 19 | hsy_fd_putstr(fd, "|"); 20 | for (item_t *i = inventory->items; i; i = i->next) { 21 | item_save(i, fd); 22 | if (i->next) 23 | hsy_fd_putstr(fd, "|"); 24 | } 25 | } -------------------------------------------------------------------------------- /sources/menus/floor_change_menu/floor_change_menu_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "menus/menu.h" 11 | #include "menus_id.h" 12 | #include "menus/title_menu.h" 13 | #include "universe.h" 14 | #include "hsy.h" 15 | 16 | menu_t *floor_change_menu_create(int dir) 17 | { 18 | menu_t *new = malloc(sizeof(menu_t)); 19 | 20 | memset(new, 0, sizeof(menu_t)); 21 | new->id = M_FLOOR_CHANGE; 22 | new->flc.time = 0; 23 | new->flc.dir = dir; 24 | new->funcs = floor_change_menu_funcs; 25 | return (new); 26 | } -------------------------------------------------------------------------------- /sources/tiles/farmland/farmland_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "screen.h" 13 | 14 | void farmland_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 15 | { 16 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, 12, 0); 17 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, 12, 0); 18 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, 12, 0); 19 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, 12, 0); 20 | } -------------------------------------------------------------------------------- /sources/floor/floor_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "floor.h" 9 | #include "entities_id.h" 10 | #include "entities/entity.h" 11 | #include 12 | 13 | void floor_add(floor_t *self, entity_t *entity) 14 | { 15 | sfVector2i e_pos = (sfVector2i){entity->pos.x >> 4, entity->pos.y >> 4}; 16 | 17 | if (entity->id == E_MOB && entity->mob.id == MB_PLAYER) 18 | self->player = entity; 19 | entity->removed = false; 20 | entities_add(&self->entities, entity); 21 | (entity->funcs.init)(entity, self); 22 | floor_insert_entity(self, e_pos, entity); 23 | } -------------------------------------------------------------------------------- /include/menus/death_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef DEATH_MENU_H_ 9 | #define DEATH_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include "recipes/recipe.h" 13 | 14 | extern const menu_funcs_t death_menu_funcs; 15 | 16 | typedef struct entity_s entity_t; 17 | 18 | typedef struct death_menu_s 19 | { 20 | int selection; 21 | entity_t *player; 22 | } death_menu_t; 23 | 24 | menu_t *death_menu_create(entity_t *player); 25 | void death_menu_tick(menu_t *self); 26 | void death_menu_draw(menu_t *self, screen_t *screen); 27 | void death_menu_destroy(menu_t *self); 28 | 29 | #endif -------------------------------------------------------------------------------- /sources/items/furniture_item/furniture_item_funcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "item_funcs.h" 9 | #include "resources/furniture_item.h" 10 | 11 | const item_funcs_t furniture_item_funcs = 12 | { 13 | .draw_inventory = furniture_item_draw_inventory, 14 | .draw_icon = furniture_item_draw_icon, 15 | .get_tex = furniture_item_get_tex, 16 | .interact_tile = furniture_item_interact_tile, 17 | .is_depleted = furniture_item_is_depleted, 18 | .get_name = furniture_item_get_name, 19 | .can_attack = furniture_item_can_attack, 20 | .destroy = furniture_item_destroy 21 | }; -------------------------------------------------------------------------------- /include/menus/title_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TITLE_MENU_H_ 9 | #define TITLE_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include "rpg.h" 13 | 14 | extern const menu_funcs_t title_menu_funcs; 15 | 16 | typedef struct title_menu_s 17 | { 18 | int selection; 19 | sfSprite *background; 20 | sfTexture *texture; 21 | menu_data_t *data; 22 | } title_menu_t; 23 | 24 | menu_t *title_menu_create(menu_data_t *data); 25 | void title_menu_tick(menu_t *self); 26 | void title_menu_draw(menu_t *self, screen_t *screen); 27 | void title_menu_destroy(menu_t *self); 28 | 29 | #endif -------------------------------------------------------------------------------- /sources/entities/text_particle/text_particle_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "entities/slime.h" 10 | #include "screen.h" 11 | #include 12 | #include "entities_id.h" 13 | #include "gui.h" 14 | 15 | void text_particle_draw(entity_t *self, screen_t *scr) 16 | { 17 | sfVector2i pos = (sfVector2i){self->pos.x, 0}; 18 | 19 | pos.y = self->pos.y - self->tpart.b.z + 1; 20 | gui_num_draw(self->tpart.msg, scr, pos, sfBlack); 21 | pos.y = self->pos.y - self->tpart.b.z; 22 | gui_num_draw(self->tpart.msg, scr, pos, self->tpart.color); 23 | } -------------------------------------------------------------------------------- /sources/menus/about_menu/about_menu_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "menus/menu.h" 11 | #include "menus_id.h" 12 | #include "universe.h" 13 | #include "hsy.h" 14 | #include 15 | 16 | menu_t *about_menu_create(input_t *input, menu_t *parent) 17 | { 18 | menu_t *new = malloc(sizeof(menu_t)); 19 | 20 | memset(new, 0, sizeof(menu_t)); 21 | new->id = M_ABOUT; 22 | new->input = input; 23 | new->about.parent = parent; 24 | new->name = hsy_strdup(""); 25 | new->funcs = about_menu_funcs; 26 | return (new); 27 | } -------------------------------------------------------------------------------- /sources/tiles/lava/lava_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "random.h" 13 | #include "screen.h" 14 | #include "tiles/lava.h" 15 | #include 16 | 17 | void lava_tick(tile_t self, floor_t *floor, sfVector2i pos) 18 | { 19 | sfVector2i npos = pos; 20 | 21 | if (random_int(1)) { 22 | npos.x += random_int(2) * 2 - 1; 23 | } else { 24 | npos.y += random_int(2) * 2 - 1; 25 | } 26 | if (floor_get_tile(floor, npos).id == T_HOLE) 27 | floor_set_tile(floor, npos, lava, 0); 28 | } -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_draw_inventory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/item.h" 9 | #include "gui.h" 10 | #include "screen.h" 11 | 12 | void resource_item_draw_inventory(item_t *self, screen_t *screen, sfVector2i p) 13 | { 14 | sfVector2i off_pos = (sfVector2i){p.x + 32, p.y}; 15 | sfVector2i num_pos = (sfVector2i){p.x + 8, p.y}; 16 | int tex = (self->funcs.get_tex)(self); 17 | 18 | resource_item_draw_icon(self, screen, p); 19 | gui_num_draw(self->res.count, screen, num_pos, sfWhite); 20 | gui_text_draw(self->res.resource->name, screen, off_pos, sfWhite); 21 | } -------------------------------------------------------------------------------- /sources/tiles/water/water_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "random.h" 13 | #include "screen.h" 14 | #include "tiles/water.h" 15 | #include 16 | 17 | void water_tick(tile_t self, floor_t *floor, sfVector2i pos) 18 | { 19 | sfVector2i npos = pos; 20 | 21 | if (random_int(2)) { 22 | npos.x += random_int(2) * 2 - 1; 23 | } else { 24 | npos.y += random_int(2) * 2 - 1; 25 | } 26 | if (floor_get_tile(floor, npos).id == T_HOLE) 27 | floor_set_tile(floor, npos, water, 0); 28 | } -------------------------------------------------------------------------------- /include/recipes/resource_recipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RESOURCE_RECIPE_H_ 9 | #define RESOURCE_RECIPE_H_ 10 | 11 | #include "recipe_funcs.h" 12 | 13 | extern const recipe_funcs_t resource_recipe_funcs; 14 | 15 | typedef struct recipe_s recipe_t; 16 | typedef struct entity_s entity_t; 17 | 18 | typedef struct resource_recipe_s 19 | { 20 | int count; 21 | resource_t *res; 22 | } resource_recipe_t; 23 | 24 | recipe_t *resource_recipe_create(resource_t *res, int count); 25 | void resource_recipe_craft(recipe_t *self, entity_t *player); 26 | void resource_recipe_destroy(recipe_t *self); 27 | 28 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strcapitalize.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strcapitalize 4 | ** File description: 5 | ** man man 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | static int isalphanum(char c) 11 | { 12 | if ('a' <= c && c <= 'z') 13 | return (3); 14 | if ('A' <= c && c <= 'Z') 15 | return (2); 16 | if ('0' <= c && c <= '9') 17 | return (1); 18 | return (0); 19 | } 20 | 21 | char *hsy_strcapitalize(char *str) 22 | { 23 | hsy_strlowcase(str); 24 | for (int i = 0; str[i]; i++) { 25 | if ((isalphanum(str[i]) > 1) && (i == 0 || !isalphanum(str[i - 1]))) { 26 | str[i] -= 'a' - 'A'; 27 | } 28 | } 29 | return (str); 30 | } 31 | -------------------------------------------------------------------------------- /sources/items/resource_item/resource_item_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "resources/item.h" 11 | #include "resources/resource_item.h" 12 | #include "items_id.h" 13 | #include "hsy.h" 14 | 15 | item_t *resource_item_create(const resource_t *res, int count) 16 | { 17 | item_t *new = malloc(sizeof(item_t)); 18 | 19 | memset(new, 0, sizeof(item_t)); 20 | new->id = I_RESOURCE; 21 | new->res.count = (count) ? count : 1; 22 | new->res.resource = (resource_t *)res; 23 | item_funcs_combine(&new->funcs, &resource_item_funcs); 24 | return (new); 25 | } -------------------------------------------------------------------------------- /sources/loader/get_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | char *get_line(FILE *file, bool fre) 13 | { 14 | static char *str = 0; 15 | static size_t b_len = 0; 16 | static ssize_t len = 0; 17 | 18 | if (fre && str) { 19 | free(str); 20 | str = 0; 21 | return (0); 22 | } 23 | len = getline(&str, &b_len, file); 24 | if (len == -1) { 25 | free(str); 26 | str = 0; 27 | return (0); 28 | } 29 | if (str[len - 1] == '\n') 30 | str[len - 1] = '\0'; 31 | return (str); 32 | } -------------------------------------------------------------------------------- /include/menu_funcs.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef MENU_FUNCS_H_ 9 | #define MENU_FUNCS_H_ 10 | 11 | #include "screen.h" 12 | #include "input.h" 13 | #include "resources/item.h" 14 | 15 | typedef struct menu_s menu_t; 16 | typedef struct universe_s universe_t; 17 | 18 | typedef struct menu_funcs_s 19 | { 20 | void (*init)(menu_t *self, universe_t *universe, input_t *input); 21 | void (*tick)(menu_t *self); 22 | void (*draw)(menu_t *self, screen_t *screen); 23 | void (*destroy)(menu_t *self); 24 | void (*draw_item_list)(menu_t *self, screen_t *scr, int v[5], item_t *l); 25 | } menu_funcs_t; 26 | 27 | #endif -------------------------------------------------------------------------------- /sources/menus/text_input_menu/text_input_menu_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "universe.h" 10 | #include "menus/menu.h" 11 | 12 | void text_input_menu_tick(menu_t *self) 13 | { 14 | if (self->input->accept.clicked) { 15 | self->ti.parent->child = 0; 16 | self->ti.parent->ti_status = 0; 17 | (self->funcs.destroy)(self); 18 | return; 19 | } 20 | if (self->input->escape.clicked) { 21 | self->ti.buf[0] = '\0'; 22 | self->ti.parent->child = 0; 23 | self->ti.parent->ti_status = 1; 24 | (self->funcs.destroy)(self); 25 | } 26 | } -------------------------------------------------------------------------------- /sources/recipes/tool_recipe/tool_recipe_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/tool_recipe.h" 11 | #include "recipes/recipe.h" 12 | #include "recipes_id.h" 13 | 14 | recipe_t *tool_recipe_create(tool_type_t *type, int level) 15 | { 16 | recipe_t *new = malloc(sizeof(recipe_t)); 17 | 18 | memset(new, 0, sizeof(recipe_t)); 19 | new->id = R_TOOL; 20 | new->tool.type = type; 21 | new->tool.level = level; 22 | recipe_init(new, tool_item_create(type, level)); 23 | recipe_funcs_combine(&new->funcs, &tool_recipe_funcs); 24 | return (new); 25 | } -------------------------------------------------------------------------------- /include/menus/options_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef OPTIONS_MENU_H_ 9 | #define OPTIONS_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include 13 | 14 | extern const menu_funcs_t options_menu_funcs; 15 | extern const char *keys_strings[]; 16 | extern const char *controls_strings[]; 17 | 18 | typedef struct options_menu_s 19 | { 20 | menu_t *parent; 21 | int selection; 22 | bool save_next; 23 | } options_menu_t; 24 | 25 | menu_t *options_menu_create(input_t *input, menu_t *ptr); 26 | void options_menu_tick(menu_t *self); 27 | void options_menu_draw(menu_t *self, screen_t *screen); 28 | 29 | #endif -------------------------------------------------------------------------------- /include/menus/pause_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef PAUSE_MENU_H_ 9 | #define PAUSE_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include "recipes/recipe.h" 13 | 14 | extern const menu_funcs_t pause_menu_funcs; 15 | 16 | typedef struct entity_s entity_t; 17 | 18 | typedef struct pause_menu_s 19 | { 20 | int selection; 21 | entity_t *player; 22 | bool will_save; 23 | int timer; 24 | } pause_menu_t; 25 | 26 | menu_t *pause_menu_create(entity_t *player); 27 | void pause_menu_tick(menu_t *self); 28 | void pause_menu_draw(menu_t *self, screen_t *screen); 29 | void pause_enu_destroy(menu_t *self); 30 | 31 | #endif -------------------------------------------------------------------------------- /sources/entities/mob/mob_tick.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | void mob_tick(entity_t *self) 13 | { 14 | mob_t *mob = &self->mob; 15 | sfVector2i tile = (sfVector2i){self->pos.x >> 4, self->pos.y >> 4}; 16 | 17 | mob->tick_time++; 18 | if (floor_get_tile(self->floor, tile).id == T_LAVA) { 19 | mob_hurt(self, self, 4, mob->dir); 20 | } 21 | if (self->mob.health <= 0) { 22 | self->removed = true; 23 | (self->funcs.die)(self); 24 | } 25 | if (mob->hurt_time) 26 | mob->hurt_time--; 27 | } -------------------------------------------------------------------------------- /include/menus/text_input_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TEXT_INPUT_MENU_H_ 9 | #define TEXT_INPUT_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include 13 | 14 | extern const menu_funcs_t text_input_menu_funcs; 15 | 16 | typedef struct text_input_menu_s 17 | { 18 | menu_t *parent; 19 | char *buf; 20 | int buf_len; 21 | } text_input_menu_t; 22 | 23 | menu_t *text_input_menu_create(char *dest, int len, char *name, menu_t *parent); 24 | void text_input_menu_tick(menu_t *self); 25 | void text_input_menu_draw(menu_t *self, screen_t *screen); 26 | void text_input_menu_destroy(menu_t *self); 27 | 28 | #endif -------------------------------------------------------------------------------- /sources/consts.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "consts.h" 9 | 10 | // Ratio must be 4 : 3 11 | const int scale = 69; 12 | const sfVector2i render_size = {4 * scale , 3 * scale}; 13 | // Max number of entities per tile, more will require more memory ! 14 | // If there's more entities on one tile, only the fist n entities will be 15 | // updated on player action. 16 | const int entities_per_tile = 10; 17 | const char *window_name = "MiniTek | MyRPG"; 18 | // Only ^2 numbers, otherwise generation will behave wierd 19 | // 128x128 gives good performances on map loading and are big enough 20 | const sfVector2i map_size = (sfVector2i){128, 128}; -------------------------------------------------------------------------------- /sources/tiles/cactus/cactus_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "screen.h" 13 | #include "tiles/sand.h" 14 | 15 | void cactus_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 16 | { 17 | sand_render(self, scr, floor, p); 18 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, 6, 0); 19 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, 7, 0); 20 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, 38, 0); 21 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, 39, 0); 22 | } -------------------------------------------------------------------------------- /include/recipe_funcs.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RECIPE_FUNCS_H_ 9 | #define RECIPE_FUNCS_H_ 10 | 11 | #include "entities/entity.h" 12 | 13 | typedef struct recipe_s recipe_t; 14 | 15 | typedef struct recipe_funcs_s 16 | { 17 | void (*add_cost)(recipe_t *self, resource_t *res, int count); 18 | void (*check_can_craft)(recipe_t *self, entity_t *player); 19 | void (*craft)(recipe_t *self, entity_t *player); 20 | void (*deduct_cost)(recipe_t *self, entity_t *player); 21 | void (*destroy)(recipe_t *self); 22 | } recipe_funcs_t; 23 | 24 | void recipe_funcs_combine(recipe_funcs_t *d, const recipe_funcs_t *r_f); 25 | 26 | #endif -------------------------------------------------------------------------------- /sources/entities/mob/player/player_hurt_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "entities_id.h" 11 | #include 12 | 13 | void player_hurt_pos(entity_t *self, sfVector2i pos1, sfVector2i pos2) 14 | { 15 | entity_t **es = floor_get_entities(self->floor, pos1, pos2); 16 | int dir = self->mob.dir; 17 | int dmg = 0; 18 | 19 | for (int i = 0; es[i]; i++) { 20 | if (es[i]->mob.id != MB_PLAYER) { 21 | dmg = player_get_attack_damage(self, es[i]); 22 | (*es[i]->funcs.hurt)(es[i], self, dmg, dir); 23 | } 24 | } 25 | free(es); 26 | } -------------------------------------------------------------------------------- /sources/recipes/resource_recipe/resource_recipe_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/furniture_recipe.h" 11 | #include "recipes/recipe.h" 12 | #include "recipes_id.h" 13 | 14 | recipe_t *resource_recipe_create(resource_t *res, int count) 15 | { 16 | recipe_t *new = malloc(sizeof(recipe_t)); 17 | 18 | memset(new, 0, sizeof(recipe_t)); 19 | new->id = R_RESOURCE; 20 | new->res.count = count; 21 | new->res.res = res; 22 | recipe_init(new, resource_item_create(res, count)); 23 | recipe_funcs_combine(&new->funcs, &furniture_recipe_funcs); 24 | return (new); 25 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_remove_resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | #include "items_id.h" 10 | #include "resources/resource.h" 11 | 12 | bool inventory_remove_resource(inventory_t *self, resource_t *res, int count) 13 | { 14 | item_t *has = inventory_find_resource(self, res); 15 | 16 | if (!has) 17 | return (false); 18 | if (has->res.count < count) 19 | return (false); 20 | has->res.count -= count; 21 | if (has->res.count <= 0) { 22 | item_list_remove(&self->items, has); 23 | (has->funcs.destroy)(has); 24 | self->item_count--; 25 | } 26 | return (true); 27 | } -------------------------------------------------------------------------------- /include/entities/zombie.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ZOMBIE_H_ 9 | #define ZOMBIE_H_ 10 | 11 | #include "entity_funcs.h" 12 | 13 | extern const entity_funcs_t zombie_funcs; 14 | 15 | typedef struct mob_s mob_t; 16 | 17 | typedef struct zombie_s 18 | { 19 | mob_t *mob; 20 | sfVector2i off; 21 | int walk_time; 22 | int level; 23 | } zombie_t; 24 | 25 | void zombie_draw(entity_t *self, screen_t *scr); 26 | void zombie_die(entity_t *self); 27 | void zombie_touched_by(entity_t *self, entity_t *e); 28 | void zombie_tick(entity_t *self); 29 | entity_t *zombie_create(int level); 30 | void zombie_save(entity_t *self, int fd); 31 | 32 | #endif -------------------------------------------------------------------------------- /sources/entities/mob/player/player_touch_item.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "items_id.h" 10 | #include "entities/entity.h" 11 | 12 | void player_touch_item(entity_t *self, entity_t *item) 13 | { 14 | inventory_t *inv = self->mob.pla.inventory; 15 | bool full = item_list_size(inv->items) >= inv->capacity; 16 | item_t *has; 17 | 18 | if (full && item->itm.item->id != I_RESOURCE) 19 | return; 20 | has = inventory_find_resource(inv, item->itm.item->res.resource); 21 | if (full && !has) 22 | return; 23 | item_entity_take(item, self); 24 | inventory_add(self->mob.pla.inventory, item->itm.item); 25 | } -------------------------------------------------------------------------------- /sources/floor/floor_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "floor.h" 10 | #include "entities/entity.h" 11 | 12 | void floor_destroy(floor_t *self) 13 | { 14 | if (!self) 15 | return; 16 | if (self->data) 17 | free(self->data); 18 | if (self->tiles) 19 | free(self->tiles); 20 | if (self->entities) 21 | while (self->entities) 22 | entities_remove(&self->entities, self->entities); 23 | for (int i = 0; i < self->size.x * self->size.y; i++) 24 | free(self->entities_in_tiles[i]); 25 | free(self->entities_in_tiles); 26 | free(self->entities_row); 27 | free(self); 28 | } -------------------------------------------------------------------------------- /sources/floor/floor_get_tile.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "floor.h" 9 | #include "tiles/tile.h" 10 | #include "tiles.h" 11 | #include "tiles_id.h" 12 | 13 | tile_t floor_get_tile(floor_t *self, sfVector2i pos) 14 | { 15 | int tile_id = 0; 16 | 17 | if (pos.x < 0 || pos.y < 0) 18 | return (*tiles[T_DIRT]); 19 | if (pos.x >= self->size.x || pos.y >= self->size.y) 20 | return (*tiles[T_DIRT]); 21 | tile_id = self->tiles[self->size.x * pos.y + pos.x]; 22 | for (int i = 0; i < T_COUNT; i++) { 23 | if (tiles[i] && tiles[i]->id == tile_id) 24 | return (*tiles[i]); 25 | } 26 | return (*tiles[T_DIRT]); 27 | } -------------------------------------------------------------------------------- /sources/menus/inventory_menu/inventory_menu_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "gui.h" 10 | #include "menus/menu.h" 11 | #include "entities/entity.h" 12 | #include "screen.h" 13 | #include "hsy.h" 14 | 15 | void inventory_menu_draw(menu_t *self, screen_t *screen) 16 | { 17 | sfVector2i pos1 = (sfVector2i){1, 1}; 18 | sfVector2i pos2 = (sfVector2i){14, 16}; 19 | int val[5] = {pos1.x, pos1.y, pos2.x, pos2.y, self->inv.selection}; 20 | item_t *items = self->inv.player->mob.pla.inventory->items; 21 | 22 | gui_frame_draw(screen, "Inventory", pos1, pos2); 23 | (*self->funcs.draw_item_list)(self, screen, val, items); 24 | } -------------------------------------------------------------------------------- /sources/recipes/furniture_recipe/furniture_recipe_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "recipes/furniture_recipe.h" 11 | #include "recipes/recipe.h" 12 | #include "recipes_id.h" 13 | 14 | recipe_t *furniture_recipe_create(entity_t *(*func)(void)) 15 | { 16 | recipe_t *new = malloc(sizeof(recipe_t)); 17 | entity_t *furniture = (*func)(); 18 | 19 | memset(new, 0, sizeof(recipe_t)); 20 | new->id = R_FURNITURE; 21 | new->fur.create_furniture = func; 22 | recipe_init(new, furniture_item_create(furniture)); 23 | recipe_funcs_combine(&new->funcs, &furniture_recipe_funcs); 24 | return (new); 25 | } -------------------------------------------------------------------------------- /sources/universe/universe_destroy.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "universe.h" 10 | #include "level_gen.h" 11 | #include 12 | #include "floor.h" 13 | 14 | void universe_destroy(universe_t *self) 15 | { 16 | if (!self) 17 | return; 18 | for (int i = 0; self->floors[i]; i++) { 19 | floor_destroy(self->floors[i]); 20 | } 21 | if (self->player) 22 | player_destroy(self->player); 23 | if (self->menu) 24 | (*self->menu->funcs.destroy)(self->menu); 25 | if (self->craft) 26 | craft_destroy(self->craft); 27 | if (self->name) 28 | free(self->name); 29 | free(self); 30 | } -------------------------------------------------------------------------------- /include/menus/crafting_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef CRAFTING_MENU_H_ 9 | #define CRAFTING_MENU_H_ 10 | 11 | #include "menu_funcs.h" 12 | #include "recipes/recipe.h" 13 | 14 | extern const menu_funcs_t crafting_menu_funcs; 15 | 16 | typedef struct entity_s entity_t; 17 | 18 | typedef struct crafting_menu_s 19 | { 20 | int selection; 21 | entity_t *player; 22 | recipe_t *recipes; 23 | } crafting_menu_t; 24 | 25 | menu_t *crafting_menu_create(recipe_t *recipes, entity_t *player, char *name); 26 | void crafting_menu_tick(menu_t *self); 27 | void crafting_menu_draw(menu_t *self, screen_t *screen); 28 | void crafting_menu_destroy(menu_t *self); 29 | 30 | #endif -------------------------------------------------------------------------------- /sources/entities/furniture/furniture_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "entities/slime.h" 10 | #include "screen.h" 11 | #include 12 | #include "entities_id.h" 13 | 14 | void furniture_draw(entity_t *self, screen_t *screen) 15 | { 16 | sfVector2i p = self->pos; 17 | int t = (self->fur.tex * 2 + 8 + (26 * 32)); 18 | 19 | screen_render_entity(screen, (sfVector2i){p.x - 8, p.y - 4}, t, 0); 20 | screen_render_entity(screen, (sfVector2i){p.x, p.y - 4}, t + 1, 0); 21 | screen_render_entity(screen, (sfVector2i){p.x - 8, p.y + 4}, t + 32, 0); 22 | screen_render_entity(screen, (sfVector2i){p.x, p.y + 4}, t + 33, 0); 23 | } -------------------------------------------------------------------------------- /sources/floor/floor_insert_entity.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "floor.h" 10 | #include "entities_id.h" 11 | #include "entities/entity.h" 12 | #include "consts.h" 13 | 14 | void floor_insert_entity(floor_t *self, sfVector2i pos, entity_t *entity) 15 | { 16 | if (pos.x < 0 || pos.y < 0) 17 | return; 18 | if (pos.x >= self->size.x || pos.y >= self->size.y) 19 | return; 20 | for (int i = 0; i < entities_per_tile; i++) { 21 | if (!self->entities_in_tiles[pos.y * self->size.x + pos.x][i]) { 22 | self->entities_in_tiles[pos.y * self->size.x + pos.x][i] = entity; 23 | return; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /sources/tiles/ore/ore_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "screen.h" 13 | 14 | void ore_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 15 | { 16 | int ul = 24 + self.variant; 17 | int ur = ul + 1; 18 | int dl = ul + 32; 19 | int dr = dl + 1; 20 | 21 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, ul, 0); 22 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, ur, 0); 23 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, dl, 0); 24 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, dr, 0); 25 | } -------------------------------------------------------------------------------- /include/recipes/furniture_recipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef FURNITURE_RECIPE_H_ 9 | #define FURNITURE_RECIPE_H_ 10 | 11 | #include "recipe_funcs.h" 12 | 13 | extern const recipe_funcs_t furniture_recipe_funcs; 14 | 15 | typedef struct recipe_s recipe_t; 16 | typedef struct entity_s entity_t; 17 | 18 | typedef struct furniture_recipe_s 19 | { 20 | entity_t *(*create_furniture)(void); 21 | } furniture_recipe_t; 22 | 23 | recipe_t *furniture_recipe_create(entity_t *(*func)()); 24 | void furniture_recipe_craft(recipe_t *self, entity_t *player); 25 | void furniture_recipe_destroy(recipe_t *self); 26 | void furniture_recipe_craft(recipe_t *self, entity_t *player); 27 | 28 | #endif -------------------------------------------------------------------------------- /sources/entities/entities_remove_all.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include 10 | #include "entities_id.h" 11 | 12 | static void remove_entity(entity_t **list, entity_t *entity) 13 | { 14 | for (int i = 0; list[i]; i++) { 15 | if (list[i] == entity) { 16 | list[i] = 0; 17 | for (int j = i + 1; list[j]; j++) { 18 | list[j - 1] = list[j]; 19 | } 20 | return; 21 | } 22 | } 23 | } 24 | 25 | void entities_remove_all(entity_t **self, entity_t **to_remove) 26 | { 27 | for (int i = 0; to_remove[i]; i++) { 28 | remove_entity(self, to_remove[i]); 29 | } 30 | } -------------------------------------------------------------------------------- /sources/gui/gui_num_draw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "screen.h" 11 | #include "hsy.h" 12 | #include "gui.h" 13 | #include 14 | 15 | char *mitoa(int num, char str[20]) 16 | { 17 | char *dest = str; 18 | 19 | if (num / 10 != 0) 20 | dest = mitoa(num / 10, str); 21 | else if (num < 0) 22 | *dest++ = '-'; 23 | *dest++ = num % 10 + '0'; 24 | *dest = '\0'; 25 | return (dest); 26 | } 27 | 28 | void gui_num_draw(int num, screen_t *screen, sfVector2i pos, sfColor color) 29 | { 30 | char str[20]; 31 | 32 | mitoa(num, str); 33 | gui_text_draw(str, screen, pos, color); 34 | } -------------------------------------------------------------------------------- /sources/menus/options_menu/options_menu_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "menus/menu.h" 11 | #include "menus/title_menu.h" 12 | #include "universe.h" 13 | #include "menus_id.h" 14 | #include "hsy.h" 15 | 16 | menu_t *options_menu_create(input_t *input, menu_t *parent) 17 | { 18 | menu_t *new = malloc(sizeof(menu_t)); 19 | 20 | memset(new, 0, sizeof(menu_t)); 21 | new->name = hsy_strdup(""); 22 | new->id = M_OPTIONS; 23 | new->opt.selection = 0; 24 | new->opt.parent = parent; 25 | new->opt.save_next = false; 26 | new->input = input; 27 | new->funcs = options_menu_funcs; 28 | return (new); 29 | } -------------------------------------------------------------------------------- /include/entities/slime.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef SLIME_H_ 9 | #define SLIME_H_ 10 | 11 | #include "entity_funcs.h" 12 | 13 | typedef struct mob_s mob_t; 14 | typedef struct entity_s entity_t; 15 | 16 | extern const entity_funcs_t slime_funcs; 17 | 18 | typedef struct slime_s 19 | { 20 | sfVector2i off; 21 | int jump_time; 22 | int level; 23 | mob_t *mob; 24 | } slime_t; 25 | 26 | entity_t *slime_create(int level); 27 | void slime_draw(entity_t *self, screen_t *screen); 28 | void slime_tick(entity_t *self); 29 | void slime_die(entity_t *self); 30 | void slime_touched_by(entity_t *self, entity_t *entity); 31 | void slime_save(entity_t *self, int fd); 32 | 33 | #endif -------------------------------------------------------------------------------- /include/recipes/tool_recipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TOOL_RECIPE_H_ 9 | #define TOOL_RECIPE_H_ 10 | 11 | #include "recipe_funcs.h" 12 | 13 | extern const recipe_funcs_t tool_recipe_funcs; 14 | 15 | typedef struct tool_type_s tool_type_t; 16 | typedef struct recipe_s recipe_t; 17 | typedef struct entity_s entity_t; 18 | 19 | typedef struct tool_recipe_s 20 | { 21 | tool_type_t *type; 22 | int level; 23 | } tool_recipe_t; 24 | 25 | recipe_t *tool_recipe_create(tool_type_t *type, int level); 26 | void tool_recipe_craft(recipe_t *self, entity_t *player); 27 | void tool_recipe_destroy(recipe_t *self); 28 | void tool_recipe_craft(recipe_t *self, entity_t *player); 29 | 30 | #endif -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_getnbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_getnbr 4 | ** File description: 5 | ** hello world? 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | int hsy_getnbr(char const *str) 11 | { 12 | int res = 0; 13 | int sign = 0; 14 | int i = 0; 15 | int old = 0; 16 | 17 | for (i = 0; str[i] == '-' || str[i] == '+'; i++) 18 | sign += (str[i] == '-') ? 1 : 0; 19 | for (i = i; '0' <= str[i] && str[i] <= '9'; i++) { 20 | if (res == 214748364 && str[i] == '8' && sign % 2 == 1) 21 | return (-2147483648); 22 | old = res; 23 | res = (res * 10) + (str[i] - '0'); 24 | if (!((res >= 0) ^ (old < 0))) 25 | return (0); 26 | } 27 | res *= (sign % 2 == 0) ? 1 : -1; 28 | return (res); 29 | } 30 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strstr 4 | ** File description: 5 | ** vim > emacs 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | static char *check_str(char *str, char const *to_find) 11 | { 12 | if (hsy_strlen(str) < hsy_strlen(to_find)) 13 | return (0); 14 | for (int i = 0; to_find[i]; i++) 15 | if (str[i] != to_find[i]) 16 | return (0); 17 | return (str); 18 | } 19 | 20 | char *hsy_strstr(char *str, char const *to_find) 21 | { 22 | char *ret = 0; 23 | 24 | for (int i = 0; str[i]; i++) { 25 | if (str[i] == to_find[0]) { 26 | ret = check_str(str + i, to_find); 27 | } 28 | if (ret) { 29 | return (ret); 30 | } 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /lib/hsy/sources/hsy_strtoul.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2020 3 | ** hsy_strtoul 4 | ** File description: 5 | ** epitech > 42 6 | */ 7 | 8 | #include "hsy.h" 9 | 10 | unsigned int hsy_strtoul(char const *str, char **endptr) 11 | { 12 | char *keep = (char *)str; 13 | int mul = 1; 14 | int numbers = 0; 15 | unsigned int res = 0; 16 | 17 | while (hsy_isspace(str[0])) 18 | str += 1; 19 | if (str[0] == '-' || str[0] == '+') { 20 | mul = ((str[0] == '-') ? -1 : 1); 21 | str += 1; 22 | } 23 | while (str[0] >= '0' && str[0] <= '9') { 24 | res *= 10; 25 | res += str[0] - '0'; 26 | str += 1; 27 | numbers += 1; 28 | } 29 | *endptr = (numbers) ? (char *)str : keep; 30 | return (mul * res); 31 | } 32 | -------------------------------------------------------------------------------- /sources/entities/mob/mob_do_hurt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "entities/entity.h" 9 | #include "tiles_id.h" 10 | #include "entities/mob.h" 11 | 12 | void mob_do_hurt(entity_t *self, int damage, int dir) 13 | { 14 | if (self->mob.hurt_time) 15 | return; 16 | floor_add(self->floor, text_particle_create(damage, self->pos, sfRed)); 17 | self->mob.health -= damage; 18 | if (dir == D_DOWN) 19 | self->mob.knockback.y = +6; 20 | if (dir == D_UP) 21 | self->mob.knockback.y = -6; 22 | if (dir == D_LEFT) 23 | self->mob.knockback.x = -6; 24 | if (dir == D_RIGHT) 25 | self->mob.knockback.x = +6; 26 | self->mob.hurt_time = 10; 27 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_start_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "entities/entity.h" 11 | #include "entities/player.h" 12 | #include "floor.h" 13 | #include "random.h" 14 | #include "tiles_id.h" 15 | 16 | bool player_start_pos(entity_t *self, floor_t *floor) 17 | { 18 | sfVector2i pos = {0}; 19 | 20 | while (true) { 21 | pos.x = random_int(floor->size.x); 22 | pos.y = random_int(floor->size.y); 23 | if (floor_get_tile(floor, pos).id == T_GRASS) { 24 | self->pos.x = pos.x * 16 + 8; 25 | self->pos.y = pos.y * 16 + 8; 26 | return (true); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /sources/view/view_ratio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "rpg.h" 9 | 10 | sfView *view_ratio(sfView *view, int width, int height) 11 | { 12 | sfVector2f v_size = sfView_getSize(view); 13 | float w_ratio = width / (float)height; 14 | float v_ratio = v_size.x / v_size.y; 15 | sfVector2f size = {1.0, 1.0}; 16 | sfVector2f pos = {0.0, 0.0}; 17 | 18 | if (w_ratio > v_ratio) { 19 | size.x = v_ratio / w_ratio; 20 | pos.x = (1 - size.x) / 2.0; 21 | } else { 22 | size.y = w_ratio / v_ratio; 23 | pos.y = (1 - size.y) / 2.0; 24 | } 25 | sfView_setViewport(view, (sfFloatRect){pos.x, pos.y, size.x, size.y}); 26 | return (view); 27 | } -------------------------------------------------------------------------------- /include/resources/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef RESOURCE_H_ 9 | #define RESOURCE_H_ 10 | 11 | #include 12 | #include "resources/food_resource.h" 13 | #include "resources/plant_resource.h" 14 | 15 | typedef struct entity_s entity_t; 16 | 17 | typedef struct resource_s resource_t; 18 | typedef struct resource_s 19 | { 20 | int id; 21 | char *name; 22 | int tex; 23 | union { 24 | food_resource_t food; 25 | plant_resource_t plant; 26 | }; 27 | bool (*interact)(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla); 28 | } resource_t; 29 | 30 | bool resource_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla); 31 | 32 | #endif -------------------------------------------------------------------------------- /sources/inventory/inventory_count.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "inventory.h" 9 | #include "items_id.h" 10 | #include "resources/resource.h" 11 | 12 | int inventory_count(inventory_t *self, item_t *item) 13 | { 14 | item_t *tmp; 15 | int count = 0; 16 | 17 | if (item->id == I_RESOURCE) { 18 | tmp = inventory_find_resource(self, item->res.resource); 19 | if (tmp) 20 | return (tmp->res.count); 21 | } else { 22 | for (item_t *cur = self->items; cur; cur = cur->next) { 23 | if ((item->funcs.matches)(item, cur)) { 24 | count++; 25 | } 26 | } 27 | return (count); 28 | } 29 | return (0); 30 | } -------------------------------------------------------------------------------- /sources/entities/mob/player/player_use_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "entities_id.h" 11 | #include 12 | 13 | bool player_use_pos(entity_t *self, sfVector2i pos1, sfVector2i pos2) 14 | { 15 | entity_t **es = floor_get_entities(self->floor, pos1, pos2); 16 | int dir = self->mob.dir; 17 | bool is_player; 18 | 19 | for (int i = 0; es[i]; i++) { 20 | is_player = es[i]->id == E_MOB && es[i]->mob.id == MB_PLAYER; 21 | if (!is_player && (*es[i]->funcs.use)(es[i], self, dir)) { 22 | free(es); 23 | return (true); 24 | } 25 | } 26 | free(es); 27 | return (false); 28 | } -------------------------------------------------------------------------------- /sources/entities/mob/slime/slime_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void slime_save(entity_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, ","); 18 | hsy_fd_putnbr(fd, self->floor->depth); 19 | hsy_fd_putstr(fd, ","); 20 | hsy_fd_putnbr(fd, self->pos.x); 21 | hsy_fd_putstr(fd, ","); 22 | hsy_fd_putnbr(fd, self->pos.y); 23 | hsy_fd_putstr(fd, ","); 24 | hsy_fd_putnbr(fd, self->mob.id); 25 | hsy_fd_putstr(fd, ","); 26 | hsy_fd_putnbr(fd, self->mob.sli.level); 27 | hsy_fd_putstr(fd, "\n"); 28 | } -------------------------------------------------------------------------------- /sources/entities/mob/zombie/zombie_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void zombie_save(entity_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, ","); 18 | hsy_fd_putnbr(fd, self->floor->depth); 19 | hsy_fd_putstr(fd, ","); 20 | hsy_fd_putnbr(fd, self->pos.x); 21 | hsy_fd_putstr(fd, ","); 22 | hsy_fd_putnbr(fd, self->pos.y); 23 | hsy_fd_putstr(fd, ","); 24 | hsy_fd_putnbr(fd, self->mob.id); 25 | hsy_fd_putstr(fd, ","); 26 | hsy_fd_putnbr(fd, self->mob.zom.level); 27 | hsy_fd_putstr(fd, "\n"); 28 | } -------------------------------------------------------------------------------- /include/entities/text_particle.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef TEXT_PARTICLE_H_ 9 | #define TEXT_PARTICLE_H_ 10 | 11 | #include "entity_funcs.h" 12 | 13 | typedef struct mob_s mob_t; 14 | typedef struct entity_s entity_t; 15 | 16 | extern const entity_funcs_t text_particle_funcs; 17 | 18 | typedef struct text_particle_s 19 | { 20 | sfVector3f a; 21 | sfVector3f b; 22 | int time; 23 | int msg; 24 | sfColor color; 25 | } text_particle_t; 26 | 27 | entity_t *text_particle_create(int msg, sfVector2i pos, sfColor color); 28 | void text_particle_draw(entity_t *self, screen_t *screen); 29 | void text_particle_tick(entity_t *self); 30 | void text_particle_destroy(entity_t *self); 31 | 32 | #endif -------------------------------------------------------------------------------- /sources/entities/item_entity/item_entity_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "tiles_id.h" 11 | #include "entities/mob.h" 12 | #include "hsy.h" 13 | 14 | void item_entity_save(entity_t *self, int fd) 15 | { 16 | hsy_fd_putnbr(fd, self->id); 17 | hsy_fd_putstr(fd, ","); 18 | hsy_fd_putnbr(fd, self->floor->depth); 19 | hsy_fd_putstr(fd, ","); 20 | hsy_fd_putnbr(fd, self->pos.x); 21 | hsy_fd_putstr(fd, ","); 22 | hsy_fd_putnbr(fd, self->pos.y); 23 | hsy_fd_putstr(fd, ","); 24 | hsy_fd_putnbr(fd, self->itm.id); 25 | hsy_fd_putstr(fd, ","); 26 | item_save(self->itm.item, fd); 27 | hsy_fd_putstr(fd, "\n"); 28 | } -------------------------------------------------------------------------------- /sources/items/plant_interact.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "resources/resource.h" 9 | #include "entities/entity.h" 10 | 11 | static bool is_in_sources(resource_t *self, tile_t *tile) 12 | { 13 | for (int i = 0; self->plant.sources[i] && i < 5; i++) { 14 | if (self->plant.sources[i]->id == tile->id) { 15 | return (true); 16 | } 17 | } 18 | return (false); 19 | } 20 | 21 | bool plant_interact(resource_t *s, tile_t tile, sfVector2i p, entity_t *pla) 22 | { 23 | bool in_sources = is_in_sources(s, &tile); 24 | 25 | if (in_sources) { 26 | floor_set_tile(pla->floor, p, *s->plant.target, 0); 27 | return (true); 28 | } 29 | return (false); 30 | } -------------------------------------------------------------------------------- /sources/inventory/inventory_add_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "inventory.h" 10 | #include "items_id.h" 11 | 12 | void inventory_add_pos(inventory_t *self, item_t *item, int pos) 13 | { 14 | item_t *has = 0; 15 | 16 | if (item->id == I_RESOURCE) { 17 | has = inventory_find_resource(self, item->res.resource); 18 | if (!has) { 19 | item_list_add(&self->items, item, pos); 20 | self->item_count++; 21 | } else { 22 | has->res.count += item->res.count; 23 | (item->funcs.destroy)(item); 24 | } 25 | } else { 26 | item_list_add(&self->items, item, pos); 27 | self->item_count++; 28 | } 29 | } -------------------------------------------------------------------------------- /include/scenes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef SCENES_H_ 9 | #define SCENES_H_ 10 | 11 | #include "rpg.h" 12 | #include "game.h" 13 | 14 | /* S_COUNT absolutely needs to be the last !*/ 15 | enum scene_id_e 16 | { 17 | S_MENU, 18 | S_GAME, 19 | S_COUNT 20 | }; 21 | 22 | static const scene_t scenes[] = { 23 | { 24 | .init = main_menu_init, 25 | .update = main_menu_update, 26 | .event = main_menu_event, 27 | .draw = main_menu_draw, 28 | .destroy = main_menu_destroy 29 | }, 30 | { 31 | .init = game_init, 32 | .update = game_update, 33 | .draw = game_draw, 34 | .destroy = game_destroy 35 | } 36 | }; 37 | 38 | #endif /* SCENES_H_ */ -------------------------------------------------------------------------------- /sources/entities/mob/player/player_interact_pos.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "entities/entity.h" 10 | #include "entities_id.h" 11 | 12 | bool player_interact_pos(entity_t *self, sfVector2i pos1, sfVector2i pos2) 13 | { 14 | entity_t **es = floor_get_entities(self->floor, pos1, pos2); 15 | int dir = self->mob.dir; 16 | item_t *item = self->mob.pla.active_item; 17 | 18 | for (int i = 0; es[i]; i++) { 19 | if (es[i]->id == E_MOB && es[i]->mob.id == E_MOB) 20 | continue; 21 | if ((*es[i]->funcs.interact)(es[i], self, item, dir)) { 22 | free(es); 23 | return (true); 24 | } 25 | } 26 | free(es); 27 | return (false); 28 | } -------------------------------------------------------------------------------- /sources/tiles/wheat/wheat_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "screen.h" 13 | #include "tiles/farmland.h" 14 | 15 | void wheat_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 16 | { 17 | int data = floor_get_data(floor, p); 18 | int tex = data / 10 + 13; 19 | 20 | farmland_render(self, scr, floor, p); 21 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, tex, 0); 22 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, tex, 0); 23 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, tex, 0); 24 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, tex, 0); 25 | } -------------------------------------------------------------------------------- /include/resources/item.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #ifndef ITEM_H_ 9 | #define ITEM_H_ 10 | 11 | #include "resources/tool_item.h" 12 | #include "resources/resource_item.h" 13 | #include "resources/furniture_item.h" 14 | #include "item_funcs.h" 15 | 16 | typedef struct item_s item_t; 17 | typedef struct item_s 18 | { 19 | int id; 20 | union { 21 | tool_item_t tool; 22 | resource_item_t res; 23 | furniture_item_t fur; 24 | }; 25 | item_funcs_t funcs; 26 | item_t *next; 27 | } item_t; 28 | 29 | void item_list_add(item_t **list, item_t *new, int pos); 30 | int item_list_size(item_t *list); 31 | void item_list_remove(item_t **list, item_t *item); 32 | void item_save(item_t *self, int fd); 33 | 34 | #endif -------------------------------------------------------------------------------- /sources/entities/furniture/furnitures_types.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "entities_id.h" 11 | #include "random.h" 12 | #include "entities/furniture.h" 13 | #include "entities/workbench.h" 14 | #include "entities/entity.h" 15 | 16 | const furniture_type_t workbench_type = { 17 | .id = F_WORKBENCH, 18 | .name = "Workbench", 19 | .tex = 4, 20 | .funcs = (entity_funcs_t *)&workbench_funcs 21 | }; 22 | 23 | const furniture_type_t oven_type = { 24 | .id = F_OVEN, 25 | .name = "Oven", 26 | .tex = 4, 27 | .funcs = (entity_funcs_t *)&workbench_funcs 28 | }; 29 | 30 | const furniture_type_t *furnitures_types[] = { 31 | &workbench_type, 32 | &oven_type 33 | }; -------------------------------------------------------------------------------- /sources/items/tool_item/tool_item_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include 10 | #include "resources/item.h" 11 | #include "resources/tool_item.h" 12 | #include "items_id.h" 13 | #include "hsy.h" 14 | 15 | item_t *tool_item_create(tool_type_t *type, int level) 16 | { 17 | item_t *new = malloc(sizeof(item_t)); 18 | 19 | memset(new, 0, sizeof(item_t)); 20 | new->id = I_TOOL; 21 | new->tool.type = type; 22 | new->tool.level = level; 23 | new->tool.max_level = 4; 24 | hsy_strcat(new->tool.name, level_names[level]); 25 | hsy_strcat(new->tool.name, " "); 26 | hsy_strcat(new->tool.name, type->name); 27 | item_funcs_combine(&new->funcs, &tool_item_funcs); 28 | return (new); 29 | } -------------------------------------------------------------------------------- /sources/main_menu/main_menu_update.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** main 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include 9 | #include "rpg.h" 10 | #include "scenes.h" 11 | #include "menus/menu.h" 12 | 13 | void main_menu_update(engine_t *engine) 14 | { 15 | menu_data_t *data = &engine->menu_data; 16 | game_data_t *game = &engine->game_data; 17 | 18 | input_tick(data->input); 19 | (data->menu->funcs.tick)(data->menu); 20 | if (data->stop == true) 21 | engine->state = EN_STOP; 22 | if (!data->stop && data->universe) { 23 | //(engine->menu_data.menu->funcs.destroy)(engine->menu_data.menu); 24 | //engine->menu_data.menu = 0; 25 | engine->active_scene = S_GAME; 26 | (*scenes[engine->active_scene].init)(engine); 27 | } 28 | } -------------------------------------------------------------------------------- /sources/tiles/carrot/carrot_render.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** EPITECH PROJECT, 2021 3 | ** rpg.h 4 | ** File description: 5 | ** hey. real programmers use vim 6 | */ 7 | 8 | #include "tiles/tile.h" 9 | #include "tiles_id.h" 10 | 11 | #include "floor.h" 12 | #include "screen.h" 13 | #include "tiles/farmland.h" 14 | 15 | void carrot_render(tile_t self, screen_t *scr, floor_t *floor, sfVector2i p) 16 | { 17 | int data = floor_get_data(floor, p); 18 | int tex = data / 10 + 13 + 32; 19 | 20 | farmland_render(self, scr, floor, p); 21 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16}, tex, 0); 22 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16}, tex, 0); 23 | screen_render_tile(scr, (sfVector2i){p.x * 16, p.y * 16 + 8}, tex, 0); 24 | screen_render_tile(scr, (sfVector2i){p.x * 16 + 8, p.y * 16 + 8}, tex, 0); 25 | } --------------------------------------------------------------------------------