More to come...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.8KB

  1. #ifndef CHAPTER_X_HEADER
  2. #define CHAPTER_X_HEADER
  3. #include "chapter_0.h"
  4. #include "chapter_1.h"
  5. #include "chapter_2.h"
  6. #include "chapter_3.h"
  7. /*
  8. Okay, we're finally on chapter five, and now we'll write something fun, not serious and boring. Before the Great Flood, when our ancestors were riding dinosaurs, building
  9. pyramids, killing African men and mating with Asian women, people didn't have dedicated nor integrated graphical processing units, called GPUs. They only had their terminals,
  10. built inside some of their spaceships. And what did they do with them? They played terminal rogue-like games, similar to those that archeologists discovered in ancient Egypt,
  11. Syria, Sumeria, Greece and Atlantis. They were reconstructed around 50 years ago by some guy that made the game Rogue. So, all those myths, sagas and legends about Anubis,
  12. Gilgamesh, Achilles, Inana, Gaea, they were just playable characters or main characters in those games, with different statistics, skills, attributes and back-story. Now, lets
  13. make a simple terminal rogue-like game using what we wrote in previous chapters.
  14. First of all, lets talk briefly about keyword 'typedef' and why I hate to use it.
  15. */
  16. typedef int number_t;
  17. typedef void procedure_t;
  18. typedef char * string_t;
  19. typedef void * memory_t;
  20. typedef enum action_t {
  21. GAME_ACTION_NONE,
  22. GAME_ACTION_WAIT, GAME_ACTION_WALK, GAME_ACTION_REST, GAME_ACTION_CAMP,
  23. GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR,
  24. GAME_ACTION_SUMMON_PUPPET, GAME_ACTION_CALL_NATURE, GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM,
  25. GAME_ACTION_COUNT
  26. } action_t;
  27. typedef struct bundle_t {
  28. number_t minimum;
  29. number_t maximum;
  30. number_t current;
  31. } bundle_t;
  32. typedef struct symbol_t {
  33. number_t character;
  34. number_t colour;
  35. number_t effect;
  36. } symbol_t;
  37. typedef struct sprite_t {
  38. number_t width;
  39. number_t height;
  40. memory_t data;
  41. } sprite_t;
  42. typedef struct attribute_t {
  43. string_t name;
  44. number_t positive_count;
  45. number_t negative_count;
  46. bundle_t * points;
  47. action_t * positive;
  48. action_t * negative;
  49. } attribute_t;
  50. typedef struct skill_t {
  51. string_t name;
  52. number_t positive_count;
  53. number_t learning_rate;
  54. bundle_t * points;
  55. action_t * positive;
  56. } skill_t;
  57. typedef struct bot_t {
  58. string_t name;
  59. number_t x;
  60. number_t y;
  61. symbol_t * symbol;
  62. sprite_t * sprite;
  63. bundle_t * health;
  64. bundle_t * mana;
  65. bundle_t * stamina;
  66. } bot_t;
  67. typedef struct player_t {
  68. string_t name;
  69. number_t x;
  70. number_t y;
  71. symbol_t * symbol;
  72. sprite_t * sprite;
  73. bundle_t * health;
  74. bundle_t * mana;
  75. bundle_t * stamina;
  76. number_t attribute_count;
  77. number_t skill_count;
  78. attribute_t * * attributes;
  79. skill_t * * skills;
  80. } player_t;
  81. typedef struct block_t {
  82. string_t name;
  83. number_t collision;
  84. number_t override;
  85. symbol_t * symbol;
  86. sprite_t * sprite;
  87. } block_t;
  88. typedef struct world_t {
  89. number_t width;
  90. number_t height;
  91. number_t item_count;
  92. number_t bot_count;
  93. block_t * * block;
  94. bot_t * bots;
  95. player_t * player;
  96. } world_t;
  97. typedef procedure_t (* generate_t) (world_t *, memory_t, number_t, number_t, number_t, number_t);
  98. typedef struct generator_t {
  99. generate_t generate;
  100. } generator_t;
  101. extern procedure_t game_clean_up (procedure_t);
  102. extern bundle_t * game_bundle (number_t minimum, number_t maximum, number_t current);
  103. extern symbol_t * game_symbol (number_t character, number_t colour, number_t effect);
  104. extern sprite_t * game_sprite (number_t width, number_t height, memory_t data);
  105. extern generator_t * game_generator (generate_t generator);
  106. extern attribute_t * game_attribute (string_t name, bundle_t * points, ...);
  107. extern skill_t * game_skill (string_t name, bundle_t * points, ...);
  108. extern bot_t * game_bot (string_t name, symbol_t * symbol, sprite_t * sprite, bundle_t * health, bundle_t * mana, bundle_t * stamina);
  109. extern player_t * game_player (string_t name, symbol_t * symbol, sprite_t * sprite, bundle_t * health, bundle_t * mana, bundle_t * stamina, ...);
  110. extern block_t * game_block (string_t name, symbol_t * symbol, sprite_t * sprite, number_t collision, number_t override);
  111. extern world_t * game_world (number_t width, number_t height, ...);
  112. extern procedure_t game_render_attribute (attribute_t * attribute, number_t x, number_t y);
  113. extern procedure_t game_render_skill (skill_t * skill, number_t x, number_t y);
  114. extern procedure_t game_render_bot (bot_t * bot);
  115. extern procedure_t game_render_player (player_t * player);
  116. extern procedure_t game_render_block (block_t * block, number_t x, number_t y);
  117. extern procedure_t game_render_world (world_t * world, number_t x, number_t y, number_t width, number_t height);
  118. #endif