More to come...
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

146 satır
5.5KB

  1. /*
  2. Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
  3. Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
  4. And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
  5. It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
  6. */
  7. #include "../chapter/chapter_0.c"
  8. #include "../chapter/chapter_1.c"
  9. #include "../chapter/chapter_2.c"
  10. static int player_x = 0;
  11. static int player_y = 0;
  12. static int entity_define (char * name, int character, int colour, int effect, int value, int logic, int menu);
  13. static void entity_create (int entity, int amount);
  14. static void entity_render (int entity);
  15. static void entity_clean_up (void);
  16. static int entity_count = 0;
  17. static char * * entity_name = NULL;
  18. static char * entity_character = '\0';
  19. static int * entity_colour = 0;
  20. static int * entity_effect = 0;
  21. static int * entity_value = 0;
  22. static int * entity_logic = 0;
  23. static int * entity_menu = 0;
  24. static int entity_usage = 0;
  25. static int * entity_index = 0;
  26. static int * entity_x = 0;
  27. static int * entity_y = 0;
  28. static void player_move_up (void) { player_y -= 1; limit (& player_y, 0, curses_screen_height - 1); }
  29. static void player_move_down (void) { player_y += 1; limit (& player_y, 0, curses_screen_height - 1); }
  30. static void player_move_left (void) { player_x -= 1; limit (& player_x, 0, curses_screen_width - 1); }
  31. static void player_move_right (void) { player_x += 1; limit (& player_x, 0, curses_screen_width - 1); }
  32. int main (void) {
  33. terminal_show_cursor (FALSE);
  34. curses_configure ();
  35. curses_bind (SIGNAL_W, player_move_up);
  36. curses_bind (SIGNAL_S, player_move_down);
  37. curses_bind (SIGNAL_A, player_move_left);
  38. curses_bind (SIGNAL_D, player_move_right);
  39. int goblin = entity_define ("Goblin", 'G', COLOUR_RED, EFFECT_NORMAL, FALSE, FALSE, 0);
  40. int coin = entity_define ("Coin", '+', COLOUR_YELLOW, EFFECT_BOLD, FALSE, FALSE, 0);
  41. entity_create (goblin, 3);
  42. entity_create (coin, 3);
  43. while (curses_active) {
  44. curses_render_background ('.', COLOUR_GREY, EFFECT_BOLD);
  45. curses_render_rectangle_fill (',', COLOUR_GREEN, EFFECT_NORMAL, 10, 10, 80, 24);
  46. curses_render_rectangle_line ('#', COLOUR_WHITE, EFFECT_NORMAL, 10, 10, 80, 24);
  47. for (int entity = 0; entity < entity_usage; ++entity) {
  48. entity_render (entity);
  49. }
  50. curses_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player_x, player_y);
  51. curses_synchronize ();
  52. }
  53. entity_clean_up ();
  54. terminal_show_cursor (TRUE);
  55. return (EXIT_SUCCESS);
  56. }
  57. static int entity_define (char * name, int character, int colour, int effect, int value, int logic, int menu) {
  58. int entity_index = entity_count;
  59. ++entity_count;
  60. entity_name = reallocate (entity_name, entity_count * (int) sizeof (* entity_name));
  61. entity_character = reallocate (entity_character, entity_count * (int) sizeof (* entity_character));
  62. entity_colour = reallocate (entity_colour, entity_count * (int) sizeof (* entity_colour));
  63. entity_effect = reallocate (entity_effect, entity_count * (int) sizeof (* entity_effect));
  64. entity_value = reallocate (entity_value, entity_count * (int) sizeof (* entity_value));
  65. entity_logic = reallocate (entity_logic, entity_count * (int) sizeof (* entity_logic));
  66. entity_menu = reallocate (entity_menu, entity_count * (int) sizeof (* entity_menu));
  67. string_copy ((entity_name [entity_index] = allocate (string_length (name) + 1)), name);
  68. entity_character [entity_index] = character;
  69. entity_colour [entity_index] = colour;
  70. entity_effect [entity_index] = effect;
  71. entity_value [entity_index] = value;
  72. entity_logic [entity_index] = logic;
  73. entity_menu [entity_index] = menu;
  74. return (entity_index);
  75. }
  76. static void entity_create (int entity, int amount) {
  77. int index;
  78. for (index = 0; index < amount; ++index) {
  79. ++entity_usage;
  80. entity_index = reallocate (entity_index, entity_usage * (int) sizeof (* entity_index));
  81. entity_x = reallocate (entity_x, entity_usage * (int) sizeof (* entity_x));
  82. entity_y = reallocate (entity_y, entity_usage * (int) sizeof (* entity_y));
  83. entity_index [entity_usage - 1] = entity;
  84. entity_x [entity_usage - 1] = randomize (0, curses_screen_width - 1);
  85. entity_y [entity_usage - 1] = randomize (0, curses_screen_height - 1);
  86. }
  87. }
  88. static void entity_render (int entity) {
  89. curses_render_character (entity_character [entity_index [entity]],
  90. entity_colour [entity_index [entity]],
  91. entity_effect [entity_index [entity]],
  92. entity_x [entity],
  93. entity_y [entity]);
  94. }
  95. void entity_clean_up (void) {
  96. for (int entity = 0; entity < entity_count; ++entity) {
  97. entity_name [entity] = deallocate (entity_name [entity]);
  98. }
  99. entity_name = deallocate (entity_name);
  100. entity_character = deallocate (entity_character);
  101. entity_colour = deallocate (entity_colour);
  102. entity_effect = deallocate (entity_effect);
  103. entity_value = deallocate (entity_value);
  104. entity_logic = deallocate (entity_logic);
  105. entity_menu = deallocate (entity_menu);
  106. entity_index = deallocate (entity_index);
  107. entity_x = deallocate (entity_x);
  108. entity_y = deallocate (entity_y);
  109. entity_count = 0;
  110. entity_usage = 0;
  111. }