#172018 - zelbo - Sat Jan 09, 2010 12:52 am
I'm somewhat new to c. Trying to wrap my head around pointers currently.
I'm trying to make a roguelike without using curses. So i plan to use an array to hold all the display information, then update as needed. i'm having trouble with scope and pointers, however.
running into trouble at line 41 (void drawMap(void))
any help is greatly appreciated.
do i just need to give up and use curses? even doing that, i feel like i should get a handle on how to make this work.
edit: cut out some irrelevant parts, made small changes to how i'm trying to do it.
Last edited by zelbo on Sun Jan 10, 2010 11:36 pm; edited 1 time in total
I'm trying to make a roguelike without using curses. So i plan to use an array to hold all the display information, then update as needed. i'm having trouble with scope and pointers, however.
running into trouble at line 41 (void drawMap(void))
any help is greatly appreciated.
do i just need to give up and use curses? even doing that, i feel like i should get a handle on how to make this work.
Code: |
/* Yet Another Roguelike for the DS - By Zelbo */ #include <nds.h> #include <stdio.h> #include <time.h> #include <string.h> // Month information const char* month[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; // Arrays for displays - map, items, creatures, fog of war int dispMap[32][20], dispItems[32][20], dispCreatures[32][20], dispFog[32][20]; // monster class class monster { private: public: char name[15]; int avatar; // ascii code of display char int cRace, cClass; int x, y, z; int maxHealth, maxMana, curHealth, curMana; int attack, armor, experience, level; bool alive; int state; void move(int direction) { }; }; /* Scope and pointers ... how do i make this work? do i need to pass pointers for console and array to the function? */ void drawMap(void) { // maybe do this part outside of the function? // consoleSelect(&winGame0); for(i=0;i<32;i++) { for(i2=0;i2<20;i2++) { iprintf("%c", dispMap(i,i2)); } } } //--------------------------------------------------------------------------------- int main(void) { // initialize variables monster Player; Player.avatar=64; Player.x=10; Player.y=10; int keys; int i, i2; int hours, seconds, minutes; unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4; init_by_array(init, length); touchPosition touch; // initialize the consoles PrintConsole winGame0; PrintConsole winGame1; PrintConsole winGame2; PrintConsole winGame3; PrintConsole winMessage; PrintConsole winStats; PrintConsole winDebug; // set screen modes videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); // assign memory banks vramSetBankA(VRAM_A_MAIN_BG); vramSetBankC(VRAM_C_SUB_BG); // define the consoles /* consoleInit (PrintConsole *console, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics) */ consoleInit(&winGame0, 0, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winGame1, 1, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winGame2, 2, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winGame3, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winMessage, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winStats, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true); consoleInit(&winDebug, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true); // customize consoles /* void consoleSetWindow ( PrintConsole * console, int x, int y, int width, int height ) */ consoleSetWindow(&winGame0, 0, 0, 32, 20); consoleSetWindow(&winGame1, 0, 0, 32, 20); consoleSetWindow(&winGame2, 0, 0, 32, 20); consoleSetWindow(&winGame3, 0, 0, 32, 20); consoleSetWindow(&winMessage, 0, 20, 32, 3); consoleSetWindow(&winStats, 0, 23, 32, 1); consoleSetWindow(&winDebug, 0, 0, 32, 24); // test all consoles consoleSelect(&winGame0); iprintf("Game Window\n"); consoleSelect(&winMessage); iprintf("Message Window\n"); consoleSelect(&winStats); iprintf("Quick Stats"); consoleSelect(&winDebug); iprintf("Debug Window\n"); for(i2=32;i2<127;i2++) { iprintf("%c",i2); } consoleSelect(&winGame2); iprintf("\x1b[10;20H\x1b[35m%c", Player.avatar); consoleSelect(&winGame0); drawMap(); // select bottom console consoleSelect(&bottomScreen); while(1) { // get the time inform time_t unixTime = time(NULL); struct tm* timeStruct = gmtime((const time_t *)&unixTime); hours = timeStruct->tm_hour; minutes = timeStruct->tm_min; seconds = timeStruct->tm_sec; //get input touchRead(&touch); scanKeys(); keys = keysHeld(); // display date and time iprintf("\x1b[2J%s %i %i %02i:%02i:%02i", month[timeStruct->tm_mon], timeStruct->tm_mday, timeStruct->tm_year +1900, hours, minutes, seconds); // display the current time // display pen coordinates iprintf("\x1b[1;0HTouch x, y = %02i, %02i\n", (touch.px/8), (touch.py/8)); swiWaitForVBlank(); } return 0; } |
edit: cut out some irrelevant parts, made small changes to how i'm trying to do it.
Last edited by zelbo on Sun Jan 10, 2010 11:36 pm; edited 1 time in total