Original Post
Hello, I recently started making a rogue-like and was to the point where i had a map and character moving around obstacles, with doors and blockable terrian. All was good, but I was using a custom header for console commands, and it down right sucked when it came to text output (very cumbersome when printing strings). So I heard about the pdcurses library and built me a copy to win32 using gcc. I set it up and it works, but I can't get this code to work. I adapted the simplest part from my budding rogue-like to the pdcurses console lib and it won't draw my '@' character at all. This code should move the '@' around on the blank screen, but nope. It only prints the string and exits with ESC. (so i know the lib is working) What is wrong with my code for drawing the character and using the arrow keys for input? (the documentation said that is how the keys are defined, I was going straight to ascii codes which ran me into trouble latter). please can someone help me with this. I want to convert the rest of my startup game, but can't if I can't even draw a character to the screen or collect arrow key input.
#include <string>
#include <sstream>
#include <curses.h>
#define ESC 27
int main( void )
{
initscr(); //initialize curses
//initscr();
keypad(initscr(),1);
curs_set(0);
int nKey;
int nPlayerX=40, nPlayerY=12;
printw("Press ESC to exit");
refresh();
while((nKey = getch()) != ESC )
{
// Output phase
mvaddch( nPlayerX, nPlayerY, '@' );
// Processing phase
switch( nKey )
{
// Move down
case KEY_UP:
nPlayerY++;
break;
// Move left
case KEY_LEFT:
nPlayerX--;
break;
// Move right
case KEY_RIGHT:
nPlayerX++;
break;
// Move up
case KEY_DOWN:
nPlayerY--;
break;
case ESC:
endwin();
return 0;
break;
}
}
return 0;
}