Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #define MAP_WIDTH 22
- #define MAP_HEIGHT 21
- struct tile {
- uint16_t Population;
- char People[5]; // note this makes struct 8 bytes each...
- // char[3] is for the brackets to mark player selection, e.g. (.::)
- // to select a single tile player bracket actually.. is like, uhh..
- // char[3] of the slected tile = ')' and char[3] of the previous tile becomes '('
- };
- struct cursor {
- unsigned char X: 5;
- unsigned char Y: 5;
- } Cursor;
- void setup(struct tile *Map, size_t numTiles)
- {
- system("cls");
- srand(time(NULL));
- int X = 0; int Y = 0;
- int i = 0;
- while (i < numTiles) {
- int occupied = rand() % 10;
- int r;
- if (!occupied) {
- Map[i].Population = 0;
- r = 0;
- } else {
- Map[i].Population = r;
- r = rand() % 512;
- }
- Map[i].People[0] = ' ';
- Map[i].People[4] = '\0';
- if (!r) {
- Map[i].People[1] = ' ';
- Map[i].People[2] = ' ';
- Map[i].People[3] = ' ';
- }
- else if (r < 80) {
- Map[i].People[1] = '.';
- Map[i].People[2] = ' ';
- Map[i].People[3] = ' ';
- }
- else if (r < 160) {
- Map[i].People[1] = '.';
- Map[i].People[2] = '.';
- Map[i].People[3] = ' ';
- }
- else if (r < 240) {
- Map[i].People[1] = '.';
- Map[i].People[2] = '.';
- Map[i].People[3] = '.';
- }
- else if (r < 320) {
- Map[i].People[1] = '.';
- Map[i].People[2] = '.';
- Map[i].People[3] = ':';
- }
- else if (r < 400) {
- Map[i].People[1] = '.';
- Map[i].People[2] = ':';
- Map[i].People[3] = ':';
- }
- else if (r < 480) {
- Map[i].People[1] = ':';
- Map[i].People[2] = ':';
- Map[i].People[3] = ':';
- }
- else if (r < 500) {
- Map[i].People[1] = 'W';
- Map[i].People[2] = '=';
- Map[i].People[3] = 'W';
- } else {
- // mountains
- if (r < 510) {
- Map[i].People[1] = '/';
- Map[i].People[2] = '\\';
- Map[i].People[3] = '^';
- } else {
- Map[i].People[1] = '/';
- Map[i].People[2] = '$';
- Map[i].People[3] = '\\';
- }
- }
- ++i;
- }
- }
- // http://higherorderfun.com/blog/2010/08/17/understanding-the-game-main-loop/
- char isTimeToUpdate()
- {
- return 1;
- }
- int hasTimeToDraw()
- {
- return 1;
- }
- void processInput()
- {
- }
- void updateGameState()
- {
- }
- void waitUntilItsTime()
- {
- // ?
- }
- void drawScreen(const struct tile (&Map)[MAP_HEIGHT][MAP_WIDTH], int Gold)
- {
- system("cls");
- int x = 0; int y = 0;
- while (y < MAP_HEIGHT) {
- x = 0;
- if (y % 2){
- printf(" ");
- }
- while (x < MAP_WIDTH) {
- printf("%s", Map[y][x].People);
- ++x;
- }
- printf("\n\n");
- ++y;
- }
- printf("Gold: %d\n", Gold);
- printf("Prices: 150, 300, 600.");
- printf(" Population at the cursor:\n");
- printf("Speed: Normal");
- printf(" %d", Map[Cursor.Y][Cursor.X].Population);
- }
- int main()
- {
- struct tile Map[MAP_HEIGHT][MAP_WIDTH];
- // setup(Map, sizeof Map / sizeof *Map);
- setup(Map, MAP_HEIGHT * MAP_WIDTH);
- int GameIsRunning = 1;
- while (GameIsRunning) {
- if (isTimeToUpdate()) {
- processInput();
- updateGameState();
- if (hasTimeToDraw()) drawScreen();
- } else {
- waitUntilItsTime();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement