More to come...
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

155 строки
8.2KB

  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. #ifndef CHAPTER_6_SOURCE
  8. #define CHAPTER_6_SOURCE
  9. #include "chapter_6.h"
  10. #define UNUSED(variable) (void) variable
  11. static procedure_t generate_full_fill_function (world_t * world, memory_t data, number_t width, number_t height, number_t x, number_t y) {
  12. UNUSED (width); UNUSED (height); UNUSED (x); UNUSED (y);
  13. for (number_t j = 0; j < world->height; ++j) {
  14. for (number_t i = 0; i < world->width; ++i) {
  15. world->block [j * world->width + i] = (block_t *) data;
  16. }
  17. }
  18. }
  19. static procedure_t generate_rectangle_fill_function (world_t * world, memory_t data, number_t width, number_t height, number_t x, number_t y) {
  20. for (number_t j = 0; j < height; ++j) {
  21. for (number_t i = 0; i < width; ++i) {
  22. world->block [(j + y) * world->width + (i + x)] = (block_t *) data;
  23. }
  24. }
  25. }
  26. static procedure_t generate_rectangle_line_function (world_t * world, memory_t data, number_t width, number_t height, number_t x, number_t y) {
  27. for (number_t offset = 0; offset < width; ++offset) {
  28. world->block [world->width * y + offset + x] = (block_t *) data;
  29. world->block [world->width * (height - 1 + y) + offset + x] = (block_t *) data;
  30. }
  31. for (number_t offset = 0; offset < height; ++offset) {
  32. world->block [world->width * (y + offset) + x] = (block_t *) data;
  33. world->block [world->width * (y + offset) + width - 1 + x] = (block_t *) data;
  34. }
  35. }
  36. static procedure_t generate_create_bots_function (world_t * world, memory_t data, number_t width, number_t height, number_t x, number_t y) {
  37. UNUSED (height); UNUSED (x); UNUSED (y);
  38. bot_t * bot = (bot_t *) data;
  39. number_t count = width;
  40. for (number_t index = 0; index < count; ++index) {
  41. world->bot_count += 1;
  42. world->bots = reallocate (world->bots, world->bot_count * (number_t) sizeof (* world->bots));
  43. memory_copy (& world->bots [world->bot_count - 1], game_bot (bot->name, bot->symbol, NULL, bot->health, bot->mana, bot->stamina), (number_t) sizeof (* world->bots));
  44. world->bots [world->bot_count - 1].x = randomize (1, 40);
  45. world->bots [world->bot_count - 1].y = randomize (1, 40);
  46. }
  47. }
  48. procedure_t play_game (procedure_t) {
  49. generator_t * full_fill = game_generator (generate_full_fill_function);
  50. generator_t * rectangle_fill = game_generator (generate_rectangle_fill_function);
  51. generator_t * rectangle_line = game_generator (generate_rectangle_line_function);
  52. generator_t * create_bots = game_generator (generate_create_bots_function);
  53. bot_t * goblin = game_bot ("Goblin", game_symbol ('g', COLOUR_RED, EFFECT_NORMAL), NULL, game_bundle (0, 11, 11), game_bundle (0, 3, 3), game_bundle (0, 23, 23));
  54. bot_t * hob_goblin = game_bot ("Hob Goblin", game_symbol ('g', COLOUR_RED, EFFECT_BOLD), NULL, game_bundle (0, 17, 17), game_bundle (0, 7, 7), game_bundle (0, 31, 31));
  55. bot_t * orc = game_bot ("Orc", game_symbol ('G', COLOUR_RED, EFFECT_NORMAL), NULL, game_bundle (0, 23, 23), game_bundle (0, 5, 5), game_bundle (0, 47, 47));
  56. bot_t * ogre = game_bot ("Ogre", game_symbol ('G', COLOUR_RED, EFFECT_BOLD), NULL, game_bundle (0, 37, 37), game_bundle (0, 2, 2), game_bundle (0, 83, 83));
  57. player_t * player = game_player ("Riri", game_symbol ('@', COLOUR_CYAN, EFFECT_BOLD), NULL, game_bundle (0, 29, 29), game_bundle (0, 3, 3), game_bundle (0, 37, 37),
  58. game_attribute ("Strength", game_bundle (1, 12, 0), GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, -GAME_ACTION_CAMP, 0),
  59. game_attribute ("Edurance", game_bundle (1, 12, 0), GAME_ACTION_WALK, GAME_ACTION_CAMP, -GAME_ACTION_REST, 0),
  60. game_attribute ("Wisdom", game_bundle (1, 12, 0), GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM, -GAME_ACTION_WALK, 0),
  61. game_attribute ("Agility", game_bundle (1, 12, 0), GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR, -GAME_ACTION_WAIT, 0),
  62. NULL,
  63. game_skill ("Blades", game_bundle (10, 120, 0), GAME_ACTION_SWING_BLADE, 0),
  64. game_skill ("Axes", game_bundle (10, 120, 0), GAME_ACTION_SWING_AXE, 0),
  65. game_skill ("Bows", game_bundle (10, 120, 0), GAME_ACTION_SHOOT_ARROW, 0),
  66. game_skill ("Spears", game_bundle (10, 120, 0), GAME_ACTION_THROW_SPEAR, 0),
  67. game_skill ("Puppet Magic", game_bundle (10, 120, 0), GAME_ACTION_SUMMON_PUPPET, 0),
  68. game_skill ("Nature Magic", game_bundle (10, 120, 0), GAME_ACTION_CALL_NATURE, 0),
  69. game_skill ("Rune Magic", game_bundle (10, 120, 0), GAME_ACTION_CITE_RUNE, 0),
  70. game_skill ("Charm Magic", game_bundle (10, 120, 0), GAME_ACTION_CAST_CHARM, 0),
  71. NULL);
  72. block_t * grass = game_block ("Grass", game_symbol (',', COLOUR_GREEN, EFFECT_BOLD), NULL, FALSE, FALSE);
  73. block_t * stone_floor = game_block ("Stone Floor", game_symbol ('.', COLOUR_GREY, EFFECT_BOLD), NULL, FALSE, FALSE);
  74. block_t * stone_wall = game_block ("Stone Wall", game_symbol ('#', COLOUR_GREY, EFFECT_BOLD), NULL, TRUE, FALSE);
  75. world_t * world = game_world (300, 100, full_fill, grass, 0, 0, 0, 0,
  76. rectangle_fill, stone_floor, 5, 9, 2, 4,
  77. rectangle_line, stone_wall, 5, 9, 2, 4,
  78. create_bots, goblin, 3, 0, 0, 0,
  79. NULL);
  80. player->attributes [0]->points->current = 7;
  81. player->attributes [1]->points->current = 3;
  82. player->attributes [2]->points->current = 5;
  83. player->attributes [3]->points->current = 3;
  84. player->skills [0]->points->current = randomize (1, 10);
  85. player->skills [1]->points->current = randomize (1, 10);
  86. player->skills [2]->points->current = randomize (1, 10);
  87. player->skills [3]->points->current = randomize (1, 10);
  88. player->skills [4]->points->current = randomize (1, 10);
  89. player->skills [5]->points->current = randomize (1, 10);
  90. player->skills [6]->points->current = randomize (1, 10);
  91. player->skills [7]->points->current = randomize (1, 10);
  92. curses_configure ();
  93. terminal_show_cursor (FALSE);
  94. while (curses_active) {
  95. number_t game_screen_offset = curses_screen_width - 40;
  96. curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
  97. game_render_world (world, 0, 0, game_screen_offset, curses_screen_height);
  98. game_render_bot (goblin);hob_goblin->x=1;hob_goblin->y=1;
  99. game_render_bot (hob_goblin);orc->x=2;orc->y=2;
  100. game_render_bot (orc);ogre->x=3;ogre->y=3;
  101. game_render_bot (ogre);
  102. game_render_player (player);
  103. for (number_t attribute = 0; attribute < player->attribute_count; ++attribute) {
  104. game_render_attribute (player->attributes [attribute], game_screen_offset, 1 + attribute);
  105. }
  106. for (number_t skill = 0; skill < player->skill_count; ++skill) {
  107. game_render_skill (player->skills [skill], game_screen_offset, 6 + skill);
  108. }
  109. switch (curses_character) {
  110. case SIGNAL_ARROW_UP: player->y -= 1; limit (& player->y, 0, world->height - 1); break;
  111. case SIGNAL_ARROW_DOWN: player->y += 1; limit (& player->y, 0, world->height - 1); break;
  112. case SIGNAL_ARROW_LEFT: player->x -= 1; limit (& player->x, 0, world->width - 1); break;
  113. case SIGNAL_ARROW_RIGHT: player->x += 1; limit (& player->x, 0, world->width - 1); break;
  114. default: break;
  115. }
  116. curses_synchronize ();
  117. }
  118. terminal_show_cursor (TRUE);
  119. game_clean_up ();
  120. }
  121. #endif