Umorna -- Tiny game written to test 'chads' library, it uses assets from itch.io...
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.

548 lines
24KB

  1. #define CHAD_TRAIT_LIMIT ( 3)
  2. #define CHAD_SKILL_LIMIT (24)
  3. #define CHAD_VALUE_LIMIT (10)
  4. #define CHAD_EFFECT_LIMIT ( 3)
  5. #define CHAD_MIGHT_LIMIT ( 1)
  6. #define CHAD_MAGIC_LIMIT ( 1)
  7. #define CHAD_RACE_LIMIT ( 3)
  8. #define CHAD_ITEM_LIMIT ( 3)
  9. #define CHAD_UNIT_LIMIT (54)
  10. #define CHAD_HERO_LIMIT ( 1)
  11. #define CHAD_BLOCK_LIMIT (28)
  12. #define CHAD_WORLD_LIMIT ( 1)
  13. #define CHAD_WORLD_WIDTH (90)
  14. #define CHAD_WORLD_HEIGHT (90)
  15. #include <xolatile/chads.h>
  16. #include <xolatile/chads.c>
  17. static int strength, dexterity, wisdom;
  18. static void define_traits (void) {
  19. strength = chad_define_trait ("Strength", 1, 1, 10);
  20. dexterity = chad_define_trait ("Dexterity", 1, 1, 10);
  21. wisdom = chad_define_trait ("Wisdom", 1, 1, 10);
  22. }
  23. static int swords, axes, maces, staves, bows, crossbows, slings, shields, armour, alchemy, medicine, mercantile, farmer, miner, lumber, traps, water_magic, earth_magic,
  24. wind_magic, black_magic, rune_magic, summon_magic, ritual_magic, charm_magic;
  25. static void define_skills (void) {
  26. swords = chad_define_skill ("Swords", 1, 1, 100);
  27. axes = chad_define_skill ("Axes", 1, 1, 100);
  28. maces = chad_define_skill ("Maces", 1, 1, 100);
  29. staves = chad_define_skill ("Staves", 1, 1, 100);
  30. bows = chad_define_skill ("Bows", 1, 1, 100);
  31. crossbows = chad_define_skill ("Crossbows", 1, 1, 100);
  32. slings = chad_define_skill ("Slings", 1, 1, 100);
  33. shields = chad_define_skill ("Shields", 1, 1, 100);
  34. armour = chad_define_skill ("Armour", 1, 1, 100);
  35. alchemy = chad_define_skill ("Alchemy", 1, 1, 100);
  36. medicine = chad_define_skill ("Medicine", 1, 1, 100);
  37. mercantile = chad_define_skill ("Mercantile", 1, 1, 100);
  38. farmer = chad_define_skill ("Farmer", 1, 1, 100);
  39. miner = chad_define_skill ("Miner", 1, 1, 100);
  40. lumber = chad_define_skill ("Lumber", 1, 1, 100);
  41. traps = chad_define_skill ("Traps", 1, 1, 100);
  42. water_magic = chad_define_skill ("Water Magic", 1, 1, 100);
  43. earth_magic = chad_define_skill ("Earth Magic", 1, 1, 100);
  44. wind_magic = chad_define_skill ("Wind Magic", 1, 1, 100);
  45. black_magic = chad_define_skill ("Black Magic", 1, 1, 100);
  46. rune_magic = chad_define_skill ("Rune Magic", 1, 1, 100);
  47. summon_magic = chad_define_skill ("Summon Magic", 1, 1, 100);
  48. ritual_magic = chad_define_skill ("Ritual Magic", 1, 1, 100);
  49. charm_magic = chad_define_skill ("Charm Magic", 1, 1, 100);
  50. }
  51. static int coin, food, wood, stone, iron, gold, silver, coal, gems, mana;
  52. static void define_values (void) {
  53. coin = chad_define_value ("Coin", 1);
  54. food = chad_define_value ("Food", 2);
  55. wood = chad_define_value ("Wood", 5);
  56. stone = chad_define_value ("Stone", 7);
  57. iron = chad_define_value ("Iron", 19);
  58. gold = chad_define_value ("Silver", 23);
  59. silver = chad_define_value ("Gold", 29);
  60. coal = chad_define_value ("Coal", 13);
  61. gems = chad_define_value ("Gems", 31);
  62. mana = chad_define_value ("Mana", 37);
  63. }
  64. static int gain_minor_strength, gain_major_strength, gain_great_strength;
  65. static void define_effects (void) {
  66. gain_minor_strength = chad_define_effect (CHAD_ENTITY_TRAIT, CHAD_TARGET_SELF | CHAD_TARGET_INCREASE, strength, 1);
  67. gain_major_strength = chad_define_effect (CHAD_ENTITY_TRAIT, CHAD_TARGET_SELF | CHAD_TARGET_INCREASE, strength, 3);
  68. gain_great_strength = chad_define_effect (CHAD_ENTITY_TRAIT, CHAD_TARGET_SELF | CHAD_TARGET_INCREASE, strength, 7);
  69. }
  70. static int might;
  71. static void define_mights (void) {
  72. might = chad_define_might ("Might", gain_minor_strength);
  73. }
  74. static int magic;
  75. static void define_magics (void) {
  76. magic = chad_define_magic ("Magic", 3, gain_major_strength);
  77. }
  78. static int orc, human, elf;
  79. static void define_races (void) {
  80. orc = chad_define_race ("Orc", strength, axes, wood);
  81. human = chad_define_race ("Human", dexterity, medicine, iron);
  82. elf = chad_define_race ("Elf", wisdom, rune_magic, gems);
  83. }
  84. static int iron_mace, iron_sword, iron_axe;
  85. static void define_items (void) {
  86. iron_mace = chad_define_item ("Iron Mace", 2, CHAD_ITEM_WEAPON, gain_minor_strength);
  87. iron_sword = chad_define_item ("Iron Sword", 3, CHAD_ITEM_WEAPON, gain_minor_strength);
  88. iron_axe = chad_define_item ("Iron Axe", 2, CHAD_ITEM_WEAPON, gain_minor_strength);
  89. }
  90. static int gnoll, gnoll_shaman, goblin, hob_goblin, thief, looter, warrior, shaman, chief, wolf_rider, boar_rider, overlord, ogre, ogre_mage, troll, war_troll, basilisk, wyvern,
  91. peasant, scout, hunter, swordman, axeman, crossbowman, horseman, guard, elite_guard, lancer, knight, kingsman, mage, arch_mage, giant, war_giant, griffin, roc, sprite,
  92. nature_spirit, half_elf, ranger, archer, elite_archer, blademaster, water_mage, earth_mage, wind_mage, rune_mage, runemaster, sacrificer, elk_rider, warmaster,
  93. coal_golem, iron_golem, sage;
  94. static void define_units (void) {
  95. gnoll = chad_define_unit ("Gnoll", "Dirt-Hut", orc, CHAD_UNIT_RANGE, 1, 2, 7, -1);
  96. gnoll_shaman = chad_define_unit ("Gnoll Shaman", "Treehouse", orc, CHAD_UNIT_MAGIC, 1, 3, 7, -1);
  97. goblin = chad_define_unit ("Goblin", "Dirty Shed", orc, CHAD_UNIT_MELEE, 2, 3, 7, -1);
  98. hob_goblin = chad_define_unit ("Hob-Goblin", "Old Barracks", orc, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 3, 5, 7, -1);
  99. thief = chad_define_unit ("Thief", "Thief Storehouse", orc, CHAD_UNIT_MELEE, 3, 7, 7, -1);
  100. looter = chad_define_unit ("Looter", "Abandoned Manor", orc, CHAD_UNIT_RANGE, 5, 7, 7, -1);
  101. warrior = chad_define_unit ("Warrior", "Longhouse", orc, CHAD_UNIT_MELEE, 7, 11, 7, -1);
  102. shaman = chad_define_unit ("Shaman", "Cottage", orc, CHAD_UNIT_MAGIC, 7, 11, 7, -1);
  103. chief = chad_define_unit ("Chief", "Campgrounds", orc, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 11, 13, 7, -1);
  104. wolf_rider = chad_define_unit ("Wolf-Rider", "Wold Den", orc, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 17, 17, 7, -1);
  105. boar_rider = chad_define_unit ("Boar-Rider", "Boar Ranch", orc, CHAD_UNIT_RANGE, 19, 23, 7, -1);
  106. overlord = chad_define_unit ("Overlord", "Orcish Temple", orc, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 23, 13, 7, -1);
  107. ogre = chad_define_unit ("Ogre", "Highlands", orc, CHAD_UNIT_MELEE, 29, 23, 7, -1);
  108. ogre_mage = chad_define_unit ("Ogre Mage", "Highland Tower", orc, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 31, 29, 7, -1);
  109. troll = chad_define_unit ("Troll", "Troll Den", orc, CHAD_UNIT_MELEE, 37, 31, 7, -1);
  110. war_troll = chad_define_unit ("War Troll", "Cavern-Fort", orc, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 41, 37, 7, -1);
  111. basilisk = chad_define_unit ("Basilisk", "Dungeon", orc, CHAD_UNIT_MELEE | CHAD_UNIT_EXTRA, 53, 59, 7, -1);
  112. wyvern = chad_define_unit ("Wyvern", "Swamp Pit", orc, CHAD_UNIT_MELEE | CHAD_UNIT_EXTRA, 59, 53, 7, -1);
  113. peasant = chad_define_unit ("Peasant", "Farm", human, CHAD_UNIT_MELEE, 1, 1, 7, -1);
  114. scout = chad_define_unit ("Scout", "Scout Shack", human, CHAD_UNIT_RANGE, 2, 3, 7, -1);
  115. hunter = chad_define_unit ("Hunter", "Archery", human, CHAD_UNIT_RANGE, 2, 3, 7, -1);
  116. swordman = chad_define_unit ("Swordman", "House of Slashing", human, CHAD_UNIT_MELEE, 3, 5, 7, -1);
  117. axeman = chad_define_unit ("Axeman", "House of Cutting", human, CHAD_UNIT_MELEE, 5, 5, 7, -1);
  118. crossbowman = chad_define_unit ("Crossbowman", "House of Shooting", human, CHAD_UNIT_RANGE, 5, 5, 7, -1);
  119. horseman = chad_define_unit ("Horseman", "Horse Ranch", human, CHAD_UNIT_MELEE, 7, 11, 7, -1);
  120. guard = chad_define_unit ("Guard", "Guard Barracks", human, CHAD_UNIT_MELEE, 7, 7, 7, -1);
  121. elite_guard = chad_define_unit ("Elite Guard", "Guard Home", human, CHAD_UNIT_MELEE, 13, 11, 7, -1);
  122. lancer = chad_define_unit ("Lancer", "Riding Meadow", human, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 17, 17, 7, -1);
  123. knight = chad_define_unit ("Knight", "Mansion of Honour", human, CHAD_UNIT_MELEE, 19, 23, 7, -1);
  124. kingsman = chad_define_unit ("Kingsman", "King's Academy", human, CHAD_UNIT_MELEE, 19, 17, 7, -1);
  125. mage = chad_define_unit ("Mage", "School of Mana", human, CHAD_UNIT_MAGIC, 23, 7, 7, -1);
  126. arch_mage = chad_define_unit ("Arch-Mage", "Temple of Mana", human, CHAD_UNIT_MAGIC, 29, 11, 7, -1);
  127. giant = chad_define_unit ("Giant", "Mound", human, CHAD_UNIT_MELEE, 41, 59, 7, -1);
  128. war_giant = chad_define_unit ("War Giant", "Mound-Fort", human, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 43, 67, 7, -1);
  129. griffin = chad_define_unit ("Griffin", "Griffin Nest", human, CHAD_UNIT_MELEE, 47, 53, 7, -1);
  130. roc = chad_define_unit ("Roc", "Heavenly Temple", human, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 53, 61, 7, -1);
  131. sprite = chad_define_unit ("Sprite", "Little Lamp", elf, CHAD_UNIT_MELEE, 1, 1, 7, -1);
  132. nature_spirit = chad_define_unit ("Nature Spirit", "Flower Palace", elf, CHAD_UNIT_MELEE, 1, 1, 7, -1);
  133. half_elf = chad_define_unit ("Half-Elf", "Slums", elf, CHAD_UNIT_MELEE, 1, 3, 7, -1);
  134. ranger = chad_define_unit ("Ranger", "Ranger Guild", elf, CHAD_UNIT_MELEE, 3, 5, 7, -1);
  135. archer = chad_define_unit ("Archer", "Arrow House", elf, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 3, 7, 7, -1);
  136. elite_archer = chad_define_unit ("Elite Archer", "Arrow Fortress", elf, CHAD_UNIT_MELEE | CHAD_UNIT_RANGE, 5, 7, 7, -1);
  137. blademaster = chad_define_unit ("Blademaster", "School of Blades", elf, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 7, 11, 7, -1);
  138. water_mage = chad_define_unit ("Water Mage", "Water Temple", elf, CHAD_UNIT_MAGIC, 11, 11, 7, -1);
  139. earth_mage = chad_define_unit ("Earth Mage", "Earth Temple", elf, CHAD_UNIT_MAGIC, 13, 13, 7, -1);
  140. wind_mage = chad_define_unit ("Wind Mage", "Wind Temple", elf, CHAD_UNIT_MAGIC, 13, 17, 7, -1);
  141. rune_mage = chad_define_unit ("Rune Mage", "Rune Monastery", elf, CHAD_UNIT_MAGIC, 17, 19, 7, -1);
  142. runemaster = chad_define_unit ("Runemaster", "Ancient Ruins", elf, CHAD_UNIT_MAGIC, 19, 23, 7, -1);
  143. sacrificer = chad_define_unit ("Sacrificer", "Altair", elf, CHAD_UNIT_MAGIC, 23, 19, 7, -1);
  144. elk_rider = chad_define_unit ("Elk Rider", "Elk Ranch-House", elf, CHAD_UNIT_MELEE, 29, 23, 7, -1);
  145. warmaster = chad_define_unit ("Warmaster", "Elven Fort", elf, CHAD_UNIT_MELEE | CHAD_UNIT_MAGIC, 41, 59, 7, -1);
  146. coal_golem = chad_define_unit ("Coal Golem", "Old Coal Mine", elf, CHAD_UNIT_MELEE, 43, 53, 7, -1);
  147. iron_golem = chad_define_unit ("Iron Golem", "Old Iron Mine", elf, CHAD_UNIT_MELEE, 47, 67, 7, -1);
  148. sage = chad_define_unit ("Sage", "Cabin in the Woods", elf, CHAD_UNIT_RANGE | CHAD_UNIT_MAGIC, 67, 47, 7, -1);
  149. }
  150. static void define_blocks (void) {
  151. (void) chad_define_block ("Ashland", 0, 12, -1, -1, -1);
  152. (void) chad_define_block ("Ashdirt", 0, 6, -1, -1, -1);
  153. (void) chad_define_block ("Ashdust", 0, 6, -1, -1, -1);
  154. (void) chad_define_block ("Garbage", CHAD_BLOCK_RANDOM, 12, -1, -1, -1);
  155. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_UP, 1, 0, 1, -1);
  156. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_DOWN, 1, 0, 1, -1);
  157. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_LEFT, 1, 0, 1, -1);
  158. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_RIGHT, 1, 0, 1, -1);
  159. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_UP | CHAD_BLOCK_LEFT, 1, 0, 1, -1);
  160. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_UP | CHAD_BLOCK_RIGHT, 1, 0, 1, -1);
  161. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_DOWN | CHAD_BLOCK_LEFT, 1, 0, 1, -1);
  162. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_DOWN | CHAD_BLOCK_RIGHT, 1, 0, 1, -1);
  163. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_UP | CHAD_BLOCK_LEFT, 1, 1, 0, -1);
  164. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_UP | CHAD_BLOCK_RIGHT, 1, 1, 0, -1);
  165. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_DOWN | CHAD_BLOCK_LEFT, 1, 1, 0, -1);
  166. (void) chad_define_block ("Ashdirt", CHAD_BLOCK_DOWN | CHAD_BLOCK_RIGHT, 1, 1, 0, -1);
  167. (void) chad_define_block ("Ashdust", CHAD_BLOCK_UP, 1, 0, 2, -1);
  168. (void) chad_define_block ("Ashdust", CHAD_BLOCK_DOWN, 1, 0, 2, -1);
  169. (void) chad_define_block ("Ashdust", CHAD_BLOCK_LEFT, 1, 0, 2, -1);
  170. (void) chad_define_block ("Ashdust", CHAD_BLOCK_RIGHT, 1, 0, 2, -1);
  171. (void) chad_define_block ("Ashdust", CHAD_BLOCK_UP | CHAD_BLOCK_LEFT, 1, 0, 2, -1);
  172. (void) chad_define_block ("Ashdust", CHAD_BLOCK_UP | CHAD_BLOCK_RIGHT, 1, 0, 2, -1);
  173. (void) chad_define_block ("Ashdust", CHAD_BLOCK_DOWN | CHAD_BLOCK_LEFT, 1, 0, 2, -1);
  174. (void) chad_define_block ("Ashdust", CHAD_BLOCK_DOWN | CHAD_BLOCK_RIGHT, 1, 0, 2, -1);
  175. (void) chad_define_block ("Ashdust", CHAD_BLOCK_UP | CHAD_BLOCK_LEFT, 1, 2, 0, -1);
  176. (void) chad_define_block ("Ashdust", CHAD_BLOCK_UP | CHAD_BLOCK_RIGHT, 1, 2, 0, -1);
  177. (void) chad_define_block ("Ashdust", CHAD_BLOCK_DOWN | CHAD_BLOCK_LEFT, 1, 2, 0, -1);
  178. (void) chad_define_block ("Ashdust", CHAD_BLOCK_DOWN | CHAD_BLOCK_RIGHT, 1, 2, 0, -1);
  179. }
  180. #include <stdlib.h>
  181. #include <raylib.h>
  182. #define BASE_SIZE (16)
  183. #define ICON_SIZE (32)
  184. #define FONT_SIZE (20)
  185. static float zoom = 2.0F;
  186. static Texture2D unit_data [CHAD_UNIT_LIMIT];
  187. //~static Texture2D base_data [CHAD_UNIT_LIMIT];
  188. static void render_unit (int race,
  189. int unit,
  190. int x,
  191. int y) {
  192. Rectangle source = { 0, (unit - race * 18) * BASE_SIZE, BASE_SIZE, BASE_SIZE };
  193. Rectangle destination = { x, y, BASE_SIZE * zoom, BASE_SIZE * zoom };
  194. Vector2 origin = { 0, 0 };
  195. DrawTexturePro (unit_data [race], source, destination, origin, 0.0F, WHITE);
  196. }
  197. static Texture2D icon_data [CHAD_ENTITY_COUNT];
  198. static void render_icon (int entity,
  199. int index,
  200. int x,
  201. int y) {
  202. char * * name;
  203. switch (entity) {
  204. case CHAD_ENTITY_TRAIT: name = chad_trait_name; break;
  205. case CHAD_ENTITY_SKILL: name = chad_skill_name; break;
  206. case CHAD_ENTITY_VALUE: name = chad_value_name; break;
  207. default: return;
  208. }
  209. DrawTextureRec (icon_data [entity], (Rectangle) { 0, 0 + index * ICON_SIZE, ICON_SIZE, ICON_SIZE }, (Vector2) { x, y }, WHITE);
  210. DrawText (name [index], x + ICON_SIZE + 6, y + 6, FONT_SIZE, WHITE);
  211. }
  212. static Texture2D ashlands_data;
  213. static void render_map (void) {
  214. int x, y;
  215. for (x = 0; x < CHAD_WORLD_WIDTH; ++x) {
  216. for (y = 0; y < CHAD_WORLD_HEIGHT; ++y) {
  217. int index = chad_world [0] [x] [y];
  218. int catch = (y * y + x + x / (y + 1) + y / (x + 1)) % chad_block_change [index];
  219. Rectangle source = { catch * BASE_SIZE, index * BASE_SIZE, BASE_SIZE, BASE_SIZE };
  220. Rectangle destination = { x * BASE_SIZE * zoom, y * BASE_SIZE * zoom, BASE_SIZE * zoom, BASE_SIZE * zoom };
  221. DrawTexturePro (ashlands_data, source, destination, (Vector2) { 0, 0 }, 0.0F, WHITE);
  222. }
  223. }
  224. }
  225. #include <fcntl.h>
  226. #include <unistd.h>
  227. #include <string.h>
  228. #define SYNTAX_LIMIT (64)
  229. static int syntax_count = 0;
  230. static int syntax_enrange [SYNTAX_LIMIT];
  231. static int syntax_derange [SYNTAX_LIMIT];
  232. static char syntax_begin [SYNTAX_LIMIT] [96];
  233. static char syntax_end [SYNTAX_LIMIT] [96];
  234. static char syntax_escape [SYNTAX_LIMIT];
  235. static int syntax_colour [SYNTAX_LIMIT];
  236. static int character_compare_array (char character, char * character_array) {
  237. int i = 0;
  238. do {
  239. if (character == character_array [i]) {
  240. return (1);
  241. }
  242. } while (++i != (int) strlen (character_array));
  243. return (0);
  244. }
  245. static void syntax_rule (int enrange,
  246. int derange,
  247. char * begin,
  248. char * end,
  249. char escape,
  250. int colour) {
  251. if (syntax_count >= SYNTAX_LIMIT) {
  252. return;
  253. }
  254. strncpy (syntax_begin [syntax_count], begin, 96);
  255. strncpy (syntax_end [syntax_count], end, 96);
  256. syntax_enrange [syntax_count] = enrange;
  257. syntax_derange [syntax_count] = derange;
  258. syntax_escape [syntax_count] = escape;
  259. syntax_colour [syntax_count] = colour;
  260. ++syntax_count;
  261. }
  262. static int syntax_loop (char * string,
  263. int * length) {
  264. int offset, subset, select;
  265. for (select = offset = 0; select != syntax_count; ++select) {
  266. if (syntax_enrange [select] == 0) {
  267. if (syntax_derange [select] == 0) {
  268. if (strncmp (string, syntax_begin [select], strlen (syntax_begin [select])) == 0) {
  269. break;
  270. }
  271. } else {
  272. if ((strncmp (string, syntax_begin [select], strlen (syntax_begin [select])) == 0)
  273. && (character_compare_array (string [offset + (int) strlen (syntax_begin [select])], syntax_end [select]) == 1)) {
  274. break;
  275. }
  276. }
  277. } else {
  278. for (subset = 0; subset != (int) strlen (syntax_begin [select]); ++subset) {
  279. if (string [offset] == syntax_begin [select] [subset]) {
  280. goto selected;
  281. }
  282. }
  283. }
  284. }
  285. selected:
  286. if (select >= syntax_count) {
  287. * length = 1;
  288. return (select);
  289. }
  290. for (offset = 1; string [offset - 1] != '\0'; ++offset) {
  291. if (string [offset] == syntax_escape [select]) {
  292. ++offset;
  293. continue;
  294. }
  295. if (syntax_derange [select] == 0) {
  296. if (strncmp (& string [offset], syntax_end [select], strlen (syntax_end [select])) == 0) {
  297. * length = offset + (int) strlen (syntax_end [select]);
  298. goto finished;
  299. }
  300. } else {
  301. subset = 0;
  302. if (strcmp (syntax_end [select], "") == 0) {
  303. break;
  304. } do {
  305. if (string [offset] == syntax_end [select] [subset]) {
  306. * length = offset;
  307. goto finished;
  308. }
  309. } while (++subset != (int) strlen (syntax_end [select]));
  310. }
  311. }
  312. finished:
  313. return (select);
  314. }
  315. #define COLOUR_GREY (0)
  316. #define COLOUR_WHITE (1)
  317. #define COLOUR_BLUE (2)
  318. #define COLOUR_YELLOW (3)
  319. #define COLOUR_CYAN (4)
  320. #define COLOUR_PINK (5)
  321. #define COLOUR_LMAO (7)
  322. static void syntax_c (void) {
  323. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
  324. char * keywords [] = {
  325. "register", "volatile", "auto", "const", "static", "extern", "if", "else",
  326. "do", "while", "for", "continue", "switch", "case", "default", "break",
  327. "enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
  328. "char", "short", "int", "long", "signed", "unsigned", "float", "double"
  329. };
  330. int word;
  331. syntax_rule (0, 0, "/*", "*/", '\0', COLOUR_GREY);
  332. syntax_rule (0, 0, "//", "\n", '\0', COLOUR_GREY);
  333. syntax_rule (0, 0, "#", "\n", '\\', COLOUR_LMAO);
  334. syntax_rule (0, 0, "'", "'", '\\', COLOUR_PINK);
  335. syntax_rule (0, 0, "\"", "\"", '\\', COLOUR_PINK);
  336. for (word = 0; word != sizeof (keywords) / sizeof (keywords [0]); ++word) {
  337. syntax_rule (0, 1, keywords [word], separators, '\0', COLOUR_YELLOW);
  338. }
  339. syntax_rule (1, 0, "()[]{}", "", '\0', COLOUR_BLUE);
  340. syntax_rule (1, 0, ".,:;<=>+*-/%!&~^?|", "", '\0', COLOUR_CYAN);
  341. syntax_rule (1, 1, "0123456789", separators, '\0', COLOUR_PINK);
  342. syntax_rule (1, 1, "abcdefghijklmnopqrstuvwxyz", separators, '\0', COLOUR_WHITE);
  343. syntax_rule (1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', COLOUR_WHITE);
  344. syntax_rule (1, 1, "_", separators, '\0', COLOUR_WHITE);
  345. }
  346. static void render_c_code (char * string,
  347. int x,
  348. int y) {
  349. int select, length = 0, offset, reset_x;
  350. reset_x = x;
  351. for (offset = 0; offset < (int) strlen (string); offset += length) {
  352. char substring [1024] = "";
  353. int i = 0, square = 16;
  354. Color colour = RED;
  355. select = syntax_loop (& string [offset], & length);
  356. strncpy (substring, & string [offset], (unsigned long int) length);
  357. switch (syntax_colour [select]) {
  358. case COLOUR_GREY: colour = GRAY; break;
  359. case COLOUR_WHITE: colour = WHITE; break;
  360. case COLOUR_BLUE: colour = BLUE; break;
  361. case COLOUR_YELLOW: colour = YELLOW; break;
  362. case COLOUR_CYAN: colour = PURPLE; break;
  363. case COLOUR_PINK: colour = RED; break;
  364. case COLOUR_LMAO: colour = GREEN; break;
  365. default: colour = GREEN; break;
  366. }
  367. for (i = 0; i < (int) strlen (substring); ++i) {
  368. if (substring [i] == '\n') {
  369. y += square;
  370. x = reset_x;
  371. } else if (substring [i] == '\t') {
  372. x += square * 4;
  373. } else {
  374. DrawTextCodepoint (GetFontDefault (), substring [i], (Vector2) { x, y }, square, colour);
  375. x += square;
  376. }
  377. }
  378. if (y > 900) {
  379. return;
  380. }
  381. }
  382. }
  383. int main (void) {
  384. define_traits ();
  385. define_skills ();
  386. define_values ();
  387. define_effects ();
  388. define_mights ();
  389. define_magics ();
  390. define_races ();
  391. define_items ();
  392. define_units ();
  393. define_blocks ();
  394. (void) chad_define_world ("Ashlands", 0XBEEF, 0, chad_block_count);
  395. chad_configure ();
  396. InitWindow (1800, 900, "EAX");
  397. SetExitKey (KEY_ESCAPE);
  398. SetTargetFPS (60);
  399. ashlands_data = LoadTexture ("sprite/world/ashlands.png");
  400. SetTextureFilter (ashlands_data, TEXTURE_FILTER_POINT);
  401. Texture2D vvv = LoadTexture ("sprite/orc/manor.png");
  402. icon_data [CHAD_ENTITY_TRAIT] = LoadTexture ("sprite/menu/traits.png");
  403. icon_data [CHAD_ENTITY_SKILL] = LoadTexture ("sprite/menu/skills.png");
  404. icon_data [CHAD_ENTITY_VALUE] = LoadTexture ("sprite/menu/values.png");
  405. unit_data [orc] = LoadTexture ("sprite/orc/units.png");
  406. unit_data [human] = LoadTexture ("sprite/human/units.png");
  407. unit_data [elf] = LoadTexture ("sprite/elf/units.png");
  408. syntax_c ();
  409. char * code = NULL;
  410. int file = open ("source/main.c", O_RDONLY);
  411. int size = (int) lseek (file, 0, SEEK_END);
  412. code = calloc ((unsigned long int) size + 1UL, 1UL);
  413. code [size] = '\0';
  414. lseek (file, 0, SEEK_SET);
  415. read (file, code, (unsigned long int) size);
  416. close (file);
  417. while (! WindowShouldClose ()) {
  418. BeginDrawing ();
  419. ClearBackground (BLACK);
  420. render_map ();
  421. Rectangle source = { 0, 0, BASE_SIZE * 15, BASE_SIZE * 10 };
  422. Rectangle destination = { 128, 128, BASE_SIZE * 15 * zoom, BASE_SIZE * 10 * zoom };
  423. DrawTexturePro (vvv, source, destination, (Vector2) { 0, 0 }, 0.0F, WHITE);
  424. render_c_code (code, 0, 0);
  425. for (int i = 0; i < 18; ++i) {
  426. render_unit (orc, i, 900 + 32 * i, 32);
  427. render_unit (human, i, 900 + 32 * i, 64);
  428. render_unit (elf, i, 900 + 32 * i, 96);
  429. }
  430. for (int i = 0; i < chad_trait_count; ++i) {
  431. render_icon (CHAD_ENTITY_TRAIT, i, 0, i * 32);
  432. }
  433. for (int i = 0; i < chad_skill_count; ++i) {
  434. render_icon (CHAD_ENTITY_SKILL, i, 300, i * 32);
  435. }
  436. for (int i = 0; i < chad_value_count; ++i) {
  437. render_icon (CHAD_ENTITY_VALUE, i, 600, i * 32);
  438. }
  439. EndDrawing ();
  440. }
  441. free (code);
  442. CloseWindow ();
  443. return (0);
  444. }