Advertisement
xth

HELP. ME.

xth
Jun 1st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #define     MAP_WIDTH   22
  5. #define     MAP_HEIGHT  21
  6.  
  7. struct tile {
  8.     uint16_t Population;
  9.     char People[5]; // note this makes struct 8 bytes each...
  10.     // char[3] is for the brackets to mark player selection, e.g. (.::)
  11.     // to select a single tile player bracket actually.. is like, uhh..
  12.     // char[3] of the slected tile = ')' and char[3] of the previous tile becomes '('
  13. };
  14.  
  15. struct cursor {
  16.     unsigned char X: 5;
  17.     unsigned char Y: 5;
  18. } Cursor;
  19.  
  20. void setup(struct tile *Map, size_t numTiles)
  21. {
  22.     system("cls");
  23.     srand(time(NULL));
  24.    
  25.     int X = 0; int Y = 0;
  26.     int i = 0;
  27.     while (i < numTiles) {
  28.         int occupied = rand() % 10;
  29.         int r;
  30.         if (!occupied) {
  31.             Map[i].Population = 0;
  32.             r = 0;
  33.         } else {
  34.             Map[i].Population = r;
  35.             r = rand() % 512;
  36.         }
  37.         Map[i].People[0] = ' ';
  38.         Map[i].People[4] = '\0';
  39.  
  40.         if (!r) {
  41.             Map[i].People[1] = ' ';
  42.             Map[i].People[2] = ' ';
  43.             Map[i].People[3] = ' ';
  44.         }
  45.         else if (r < 80) {
  46.             Map[i].People[1] = '.';
  47.             Map[i].People[2] = ' ';
  48.             Map[i].People[3] = ' ';
  49.         }
  50.         else if (r < 160) {
  51.             Map[i].People[1] = '.';
  52.             Map[i].People[2] = '.';
  53.             Map[i].People[3] = ' ';
  54.         }
  55.         else if (r < 240) {
  56.             Map[i].People[1] = '.';
  57.             Map[i].People[2] = '.';
  58.             Map[i].People[3] = '.';
  59.         }
  60.         else if (r < 320) {
  61.             Map[i].People[1] = '.';
  62.             Map[i].People[2] = '.';
  63.             Map[i].People[3] = ':';
  64.         }
  65.         else if (r < 400) {
  66.             Map[i].People[1] = '.';
  67.             Map[i].People[2] = ':';
  68.             Map[i].People[3] = ':';
  69.         }
  70.         else if (r < 480) {
  71.             Map[i].People[1] = ':';
  72.             Map[i].People[2] = ':';
  73.             Map[i].People[3] = ':';
  74.         }
  75.         else if (r < 500) {                
  76.             Map[i].People[1] = 'W';
  77.             Map[i].People[2] = '=';
  78.             Map[i].People[3] = 'W';
  79.         } else {
  80.             // mountains
  81.             if (r < 510) {
  82.                 Map[i].People[1] = '/';
  83.                 Map[i].People[2] = '\\';
  84.                 Map[i].People[3] = '^';
  85.             } else {
  86.                 Map[i].People[1] = '/';
  87.                 Map[i].People[2] = '$';
  88.                 Map[i].People[3] = '\\';
  89.             }
  90.         }
  91.         ++i;
  92.     }
  93. }
  94.  
  95.  
  96. // http://higherorderfun.com/blog/2010/08/17/understanding-the-game-main-loop/
  97. char isTimeToUpdate()
  98. {
  99.         return 1;
  100. }
  101. int hasTimeToDraw()
  102. {
  103.     return 1;
  104. }
  105. void processInput()
  106. {
  107.  
  108. }
  109. void updateGameState()
  110. {
  111.  
  112. }
  113. void waitUntilItsTime()
  114. {
  115.     // ?
  116. }
  117.  
  118. void drawScreen(const struct tile (&Map)[MAP_HEIGHT][MAP_WIDTH], int Gold)
  119. {
  120.     system("cls");
  121.     int x = 0; int y = 0;
  122.     while (y < MAP_HEIGHT) {
  123.         x = 0;
  124.         if (y % 2){
  125.             printf("  ");
  126.         }
  127.         while (x < MAP_WIDTH) {
  128.             printf("%s", Map[y][x].People);
  129.             ++x;
  130.         }
  131.         printf("\n\n");
  132.         ++y;
  133.     }
  134.     printf("Gold:  %d\n", Gold);
  135.     printf("Prices: 150, 300, 600.");
  136.     printf("        Population at the cursor:\n");
  137.     printf("Speed: Normal");
  138.     printf("                     %d", Map[Cursor.Y][Cursor.X].Population);
  139.  
  140. }
  141.  
  142. int main()
  143. {
  144.     struct tile Map[MAP_HEIGHT][MAP_WIDTH];
  145.     // setup(Map, sizeof Map / sizeof *Map);
  146.     setup(Map, MAP_HEIGHT * MAP_WIDTH);
  147.     int GameIsRunning = 1;
  148.     while (GameIsRunning) {
  149.         if (isTimeToUpdate()) {
  150.             processInput();
  151.             updateGameState();
  152.             if (hasTimeToDraw()) drawScreen();
  153.  
  154.  
  155.  
  156.         } else {
  157.             waitUntilItsTime();
  158.         }
  159.     }
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement