Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <3ds.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctime>
- #include <iostream>
- using namespace std;
- struct Map_Tile
- {
- char tileCharacter;
- bool walkable;
- };
- struct Point
- {
- int x, y;
- } playerPos;
- int const MapWidth = 10;
- int const MapHeight = 10;
- Map_Tile map[MapWidth][MapHeight];
- void GenMap() {
- srand(time(NULL));
- for (int y = 0; y < MapHeight; y++)
- {
- for(int x = 0; x < MapWidth; x++)
- {
- int t = rand() % 2;
- if(t == 0)
- {
- map[x][y].tileCharacter = '#';
- map[x][y].walkable = false;
- }
- else
- {
- map[x][y].tileCharacter = '.';
- map[x][y].walkable = true;
- }
- }
- }
- map[0][0].tileCharacter = '.';
- map[0][0].walkable = true;
- }
- void PrintMap()
- {
- for (int y = 0; y < MapHeight; y++)
- {
- for(int x = 0; x < MapWidth; x++)
- {
- if(x == playerPos.x && y == playerPos.y)
- cout << "@";
- else
- cout << map[x][y].tileCharacter;
- }
- cout << endl;
- }
- }
- int main()
- {
- gfxInitDefault();
- //gfxSet3D(true); // uncomment if using stereoscopic 3D
- // Let us set up the top and bottom screen
- PrintConsole topConsole;
- PrintConsole bottomConsole;
- consoleInit(GFX_TOP, &topConsole);
- consoleInit(GFX_BOTTOM, &bottomConsole);
- bool update = true;
- playerPos.x = 0;
- playerPos.y = 0;
- // Main loop
- while (aptMainLoop())
- {
- gspWaitForVBlank();
- hidScanInput();
- // Your code goes here
- u32 kDown = hidKeysDown();
- if (kDown & KEY_START)
- break; // break in order to return to hbmenu
- // Start game statements here
- // Where you start to print stuff to the screen *__* Important!
- if(update) {
- consoleSelect(&topConsole);
- consoleClear();
- GenMap();
- PrintMap();
- //player move up
- if (kDown & KEY_UP)
- {
- if(playerPos.y > 0 && map[playerPos.x][playerPos.y-1].walkable)
- {
- playerPos.y--;
- }
- }
- //player move udown
- if (kDown & KEY_DOWN)
- {
- if (playerPos.y < MapHeight -1 && map[playerPos.x][playerPos.y+1].walkable)
- {
- playerPos.y++;
- }
- }
- //player move right
- if (kDown & KEY_RIGHT)
- {
- if(playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x+1].walkable)
- {
- playerPos.x++;
- }
- }
- //player move left
- if (kDown & KEY_LEFT)
- {
- if(kDown & KEY_LEFT && playerPos.x < MapWidth -1 && map[playerPos.x][playerPos.x-1].walkable)
- {
- playerPos.x--;
- }
- }
- consoleSelect(&bottomConsole);
- consoleClear();
- printf("Press Y for new map");
- if (kDown & KEY_Y)
- {
- GenMap();
- PrintMap();
- }
- update = false;
- }
- // Flush and swap framebuffers
- gfxFlushBuffers();
- gfxSwapBuffers();
- }
- gfxExit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement