12 #include <SFML/Graphics.h>
13 #include <SFML/System.h>
14 #include <SFML/Audio.h>
30 #define V2F (sfVector2f)
31 #define TIME(x) sfClock_getElapsedTime(x).microseconds / 1000000.0
32 #define CLOCKMICRO(clock) sfTime_asMilliseconds(sfClock_restart(clock))
34 #define BAR_SIZEW PLAYER_DIMO.x
39 #define MAX(a, b) ((a > b) ? a : b)
40 #define MIN(a, b) ((a < b) ? a : b)
41 #define TEXTURE "assets/map.png"
47 #define FONT "assets/mc.otf"
49 #define GREEN sfColor_fromRGB(15, 169, 88)
50 #define RED sfColor_fromRGB(139, 0, 0)
51 #define BLUE sfColor_fromRGB(30, 144, 255)
53 #define LEFTM (get_keys()->keys[0])
54 #define LEFTK (get_keys()->keys[get_bind()->left])
55 #define RIGHTK (get_keys()->keys[get_bind()->right])
56 #define UPK (get_keys()->keys[get_bind()->up])
57 #define DOWNK (get_keys()->keys[get_bind()->down])
58 #define ATTACKK (get_keys()->keys[get_bind()->attack])
59 #define SLOT1K (get_keys()->keys[get_bind()->inv1])
60 #define SLOT2K (get_keys()->keys[get_bind()->inv2])
61 #define SLOT3K (get_keys()->keys[get_bind()->inv3])
62 #define HITBOXK (get_keys()->keys[get_bind()->hitbox])
63 #define XPK (get_keys()->keys[get_bind()->xp])
64 #define ESCAPEK (get_keys()->keys[37])
65 #define PAUSEK (get_keys()->keys[get_bind()->pause])
66 #define HITK (get_keys()->keys[get_bind()->hit])
67 #define HEALK (get_keys()->keys[get_bind()->heal])
68 #define PASSKEYK (get_keys()->keys[get_bind()->pass])
69 #define INTERACTK (get_keys()->keys[get_bind()->interact])
70 #define INVENTORYK (get_keys()->keys[get_bind()->inv])
72 #define RANDINT(min, max) (rand() % (max - min + 1) + min)
73 #define MIN_INT -2147483648
74 #define MAX_INT 2147483647
75 #define CASE_SIZE (32 * MAP_SCALE)
78 #define MUSIC_INTRO "assets/intro.ogg"
79 #define MUSIC_MENU "assets/menu.ogg"
80 #define MUSIC_GAME "assets/game.ogg"
82 #define SOUND_DAMAGE "assets/hurt.ogg"
83 #define SOUND_HEAL "assets/heal.ogg"
84 #define SOUND_LEVELUP "assets/levelup.ogg"
85 #define SOUND_LOOT "assets/loot.ogg"
87 #define SOUND_DEAD_GLADIATOR "assets/dead_gladiator.ogg"
88 #define SOUND_DEAD_MIMIC "assets/dead_mimic.ogg"
89 #define SOUND_DEAD_MONSTER "assets/dead_monster.ogg"
90 #define SOUND_HIT_GLADIATOR "assets/hit_gladiator.ogg"
91 #define SOUND_HIT_MIMIC "assets/hit_mimic.ogg"
92 #define SOUND_HIT_MONSTER "assets/hit_monster.ogg"
93 #define SOUND_IDLE_MONSTER "assets/idle_monster.ogg"
139} player_orientation_e_t;
168 unsigned char *binding;
173 unsigned char attack;
175 unsigned char interact;
180 unsigned char hitbox;
188 unsigned char keys[102];
213 orientation_e_t orientation;
214 sfClock *animation_clock;
246 sfIntRect initial_rect;
252 entity_type_e_t type;
309 int xp_to_next_level;
315 int (*action)(action_player_e_t action);
316 player_orientation_e_t orientation;
327 sfColor *outline_color;
328 float outline_thickness;
334 sfVideoMode video_mode;
335 sfRenderWindow *window;
339 sfVector2i mouse_pos;
340 sfVector2i old_mouse_pos;
367 void (*function)(void);
378 sfTexture *main_texture;
386 sfText *text_chatbox;
398sfIntRect get_stat_rect(
char *stat);
401sfFont *get_font(
void);
403button_t **get_buttons_settings(
void);
406entity_t *get_new_item(sfVector2f pos,
int id);
409 #define RANDOM_ITEM(pos) get_new_item(pos, rand() % 12)
411int normalize_vector(sfVector2f *vector);
415void text_center(sfText **text, sfVector2f pos, sfIntRect rect);
417 int *offX_maX_miX_offY_maX_miY, ...);
418void letter_by_letter(
float *clock,
char **str,
int *j);
437int display_chatnpc(
char **dialog, sfVector2f pos,
int reset);
442void splash_function(
void (*func)(
void));
443void loading_function(
void (*func)(
void));
447void display_menu(
void);
448void display_main(
void);
449void display_pause(
void);
450void display_settings(
void);
451void display_bind(
void);
452void display_exit(
void);
454void display_equipments(
void);
455void display_globalstat(
void);
458void create_new_map(
void);
459char **generate_whole_map(
int width,
int height);
461void display_entity(
entity_t *entity);
463void display_hud(
void);
467void update_menu(
void);
468void update_main(
void);
469void update_pause(
void);
470void update_settings(
void);
471void update_bind(
void);
472void update_hud(
void);
473void update_player2(
void);
477int *get_offset_rect(
char *
id);
478void display_intro(
void);
479void update_intro(
void);
482int display_talk(
char reset);
483void display_bonus(
void);
487sfVector2f player_pos(
void);
488sfVector2f player_dim(
void);
489sfVector2f player_dimo(
void);
490 #define PLAYER_POS player_pos()
491 #define PLAYER_DIM player_dim()
492 #define PLAYER_DIMO player_dimo()
494void choose_offset(
char *action,
int *offset_rect, sfIntRect rect);
495void display_player(
void);
496void display_levelbar(
player_t *player);
497void display_level_up(
char *
id, action_player_e_t action,
498 float value,
int other);
499void display_hit_on_mob(
void);
500void display_player_stat(
entity_t *player_e);
501void update_player(
void);
502void stat_up(
char *
id, action_player_e_t stat,
int other);
503entity_t *init_player(sfSprite **sprite);
506int action_player(action_player_e_t action);
507void atk_up(sfText *text,
float value);
508void def_up(sfText *text,
float value);
509void hp_up(sfText *text,
float value);
510void attack_mob(
void);
513void update_item(
void);
515void events_item(sfEvent event);
519entity_t *random_npc(sfVector2f pos);
525void event_button(
button_t **buttons);
526void display_button(
button_t **buttons);
529void menu_resume(
void);
530void menu_settings(
void);
533void settings_quit(
void);
535void pause_resume(
void);
536void pause_bind(
void);
537void pause_settings(
void);
538void pause_menu(
void);
542void bind_right(
void);
545void bind_attack(
void);
546void bind_pause(
void);
547void bind_interact(
void);
548void bind_slot1(
void);
549void bind_slot2(
void);
550void bind_slot3(
void);
555void analyse_events(
void);
557void events_intro(sfEvent event);
558void events_main(sfEvent event);
559void events_player(sfEvent event);
560void events_menu(sfEvent event);
561void events_pause(sfEvent event);
562void events_settings(sfEvent event);
563void events_bind(sfEvent event);
564void events_exit(sfEvent event);
568void init_gladiator(sfVector2f pos);
569void init_chest_mimic(sfVector2f pos);
570void init_jar_mimic(sfVector2f pos);
571void init_barrel_mimic(sfVector2f pos);
572void init_demon(sfVector2f pos);
573void init_ghoul(sfVector2f pos);
576void init_game_help(
void);
580void update_entity(
entity_t *entity);
581void update_mob_animation(
entity_t *entity);
582int is_hitbox_intersecting(sfRectangleShape *hitbox1,
583 sfRectangleShape *hitbox2);
584void check_mob_action(
void);
585float calculate_damage(
float attack,
float defense);
586void check_mob_alive(
void);
589int is_invalid_case(sfVector2f map_case);
593float distance_heuristic(sfVector2f a, sfVector2f b);
594int vector_cmp(sfVector2f a, sfVector2f b);
595sfVector2f vector_add(sfVector2f a, sfVector2f b);
596path_t *get_best_path(sfVector2f start, sfVector2f end);
597void display_path(
path_t *path);
599sfVector2f pos_to_case(sfVector2f vector);
600sfVector2f move_to_next_point(sfVector2f start, sfVector2f end,
603int a_ov(
int side,
float speed,
entity_t *player);
604sfVector2f get_valid_random_pos(
void);
608void play_music(
char *path);
609void play_sound(
entity_t *entity,
char *path);
610void update_volume(
void);
614char *get_file(
char *file);
615void save_entities(
void);
617void save_player(
void);
619void load_entities(
void);
621void load_player(
void);
631button_t *create_button(
char *text, sfFloatRect rect,
void (*function)(
void));
646sfText *create_text(
int nb, ...);
660sfSprite *create_sprite(
int nb, ...);
677sfRectangleShape *create_rectangle(
int nb, ...);
692entity_t *create_entity(
int nb, ...);
693void update_entity(
entity_t *entity);
698char **generate_whole_map(
int width,
int height);
699void place_mobs_map(
void);
700void remove_mobs_fl(
void);
701void restart_game(
void);
702void move_end_ladder(
void);
703void place_npc_map(
void);
706void analyse_events(
void);