I want to write a program that let's you move a character on the screen, basically, I will improve on this to hopefully make a sort of game. One problem I'm having trouble deleting the previously printed character, it just leaves a trail behind otherwise.
I've tried making a variable (actually 2) to keep track of the printed character and delete it (put space instead) when a new one is printed, which I couldn't get to work.
#include <ncurses.h>
using namespace std;
int x=10,y=10;
void pro(char dr)
{
switch (dr)
{
case 'u':
move(--y, x);
break;
case 'd':
move(++y, x);
break;
case 'r':
move(y, ++x);
break;
case 'l':
move(y, --x);
break;
}
addch('#');
}
int main()
{
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
int in;
border(0, 0, 0, 0, 0, 0, 0, 0);
while (true)
{
in = getch();
switch (in)
{
case KEY_UP:
pro('u');
break;
case KEY_DOWN:
pro('d');
break;
case KEY_RIGHT:
pro('r');
break;
case KEY_LEFT:
pro('l');
break;
}
}
endwin();
}
This code currently leaves a trail behind, and I want it to delete the previous one.