Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.66 KB | None | 0 0
  1. #include <string.h>
  2. #include <3ds.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctime>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. struct Map_Tile
  12.        {
  13.          char tileCharacter;
  14.          bool walkable;
  15.        };
  16.  
  17.  struct Point
  18.  {
  19.     int x, y;
  20.  
  21.  } playerPos;
  22.  
  23.   int const MapWidth  =  10;
  24.   int const MapHeight =  10;
  25.   Map_Tile map[MapWidth][MapHeight];
  26.  
  27. void GenMap() {
  28.  
  29. srand(time(NULL));
  30. for (int y = 0; y < MapHeight; y++)
  31.   {
  32.    for(int x = 0; x < MapWidth; x++)
  33.    {
  34.     int t = rand() % 2;
  35.     if(t == 0)
  36.     {
  37.         map[x][y].tileCharacter = '#';
  38.         map[x][y].walkable = false;
  39.     }
  40.     else
  41.     {
  42.         map[x][y].tileCharacter = '.';
  43.         map[x][y].walkable = true;
  44.     }
  45.   }
  46. }
  47. map[0][0].tileCharacter = '.';
  48. map[0][0].walkable = true;
  49. }
  50.  
  51. void PrintMap()
  52. {
  53. for (int y = 0; y < MapHeight; y++)
  54.    {
  55.    for(int x = 0; x < MapWidth; x++)
  56.         {
  57.         if(x == playerPos.x && y == playerPos.y)
  58.             cout << "@";
  59.         else
  60.             cout << map[x][y].tileCharacter;
  61.          }
  62.         cout << endl;
  63.  
  64.   }
  65.  
  66. }
  67. int main()
  68. {
  69.     gfxInitDefault();
  70.     //gfxSet3D(true); // uncomment if using stereoscopic 3D
  71.  
  72.         // Let us set up the top and bottom screen
  73.         PrintConsole topConsole;
  74.         PrintConsole bottomConsole;
  75.         consoleInit(GFX_TOP, &topConsole);
  76.         consoleInit(GFX_BOTTOM, &bottomConsole);
  77.  
  78.         bool update = true;
  79.        
  80.         playerPos.x = 0;
  81.         playerPos.y = 0;
  82.  
  83.     // Main loop
  84.     while (aptMainLoop())
  85.     {
  86.         gspWaitForVBlank();
  87.         hidScanInput();
  88.  
  89.         // Your code goes here
  90.  
  91.         u32 kDown = hidKeysDown();
  92.         if (kDown & KEY_START)
  93.         break; // break in order to return to hbmenu
  94.  
  95.      // Start game statements here
  96.  
  97.  
  98.              
  99.              // Where you start to print stuff to the screen *__* Important!
  100.                 if(update) {
  101.                     consoleSelect(&topConsole);
  102.                     consoleClear();
  103.                    
  104.                     GenMap();
  105.                   PrintMap();
  106.          
  107.                     //player move up
  108.                    if (kDown & KEY_UP)
  109.                    {
  110.                     if(playerPos.y > 0 && map[playerPos.x][playerPos.y-1].walkable)
  111.                     {
  112.                       playerPos.y--;
  113.                     }
  114.                 }
  115.                    
  116.                        //player move udown
  117.                      if (kDown & KEY_DOWN)
  118.                      {
  119.                     if (playerPos.y < MapHeight -1 && map[playerPos.x][playerPos.y+1].walkable)
  120.                     {
  121.                       playerPos.y++;
  122.                     }
  123.                 }
  124.                        //player move right
  125.                    if (kDown & KEY_RIGHT)
  126.                 {
  127.                     if(playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x+1].walkable)
  128.                     {
  129.                       playerPos.x++;
  130.                     }
  131.                 }
  132.  
  133.                            //player move left
  134.                 if (kDown & KEY_LEFT)
  135.                 {
  136.                     if(kDown & KEY_LEFT && playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x-1].walkable)
  137.                     {
  138.                       playerPos.x--;
  139.                     }
  140.                }
  141.                
  142.  
  143.                     consoleSelect(&bottomConsole);
  144.                     consoleClear();
  145.                     printf("Press Y for new map");
  146.  
  147.                     if (kDown & KEY_Y)
  148.                     {
  149.                       GenMap();
  150.                       PrintMap();
  151.                     }
  152.                     update = false;
  153.                }
  154.  
  155.         // Flush and swap framebuffers
  156.         gfxFlushBuffers();
  157.         gfxSwapBuffers();
  158.     }
  159.  
  160.     gfxExit();
  161.     return 0;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement