#include <iostream>
#include <stdio.h>
#include <curses.h>
using namespace std;
void drawPosition(int, int);
int getKeyPress();
void clearScreen();
void resetCursorPos();
int main(){
int exitLoop = 0;
initscr();
int xPos = 0;
int yPos = 0;
clearScreen();
while(exitLoop == 0){
resetCursorPos();
drawPosition(xPos,yPos);
refresh();
switch(getKeyPress()){ //Check for key presses, and execute actions for them
case 27: exitLoop = 1; // escape
case int('w'): yPos--; // w
case int('a'): xPos--; // a
case int('s'): yPos++; // s
case int('d'): xPos++; //d
}
}
endwin();
return 0;
}
void drawPosition(int xPos, int yPos){
//printf("\033[ %i; %if", xPos, yPos);
move(xPos,yPos);
printw("0");
}
int getKeyPress(){
int text;
text = getch();
return text;
}
void clearScreen(){
printf("\033[2J");
}
void resetCursorPos(){
move(0,0);
}
Using Eclipse to Compile/Build and running it from the command line. There are no compilation errors, and it seems like it should work... However, when I run it, the S key increases x and y by one, the D key increases y by one, A increases X by one, and W does nothing. This is nothing close to what the code tells it to do. The escape key code works fine.
The compiler being used by Eclipse is g++, if that info is needed.
I have had this problem with compiling using windows (the horror!), and somehow I fixed it, however that was a year ago or so. I have the source code for that program, however it is using a completely different method of drawing things. I have tried using direct ascii codes, and int('Letter'), and it makes no difference. I'll check the windows version of this code I have, however to my knowledge it was close to this, however not using escape codes to clear the screen, and printing spaces instead.
I would like to know if there are any problems that stand out to any of you on this forum, that might be causing this to not work.


Sign In
Create Account

Back to top









