Skip to content

Instantly share code, notes, and snippets.

@dd86k
Last active October 11, 2016 22:14
Show Gist options
  • Save dd86k/816ec0fa3b52bbd5c2c6 to your computer and use it in GitHub Desktop.
Save dd86k/816ec0fa3b52bbd5c2c6 to your computer and use it in GitHub Desktop.
Make a character move! (Linux, C/C++, ncurses)

You will need the libcurses-dev packet which can be installed with:

APT: (Debian, Ubuntu)

sudo apt-get install libncurses-dev -y

YUM/DNF: (Fedora)

sudo yum intall libncurses-dev -y

I used Geany to compile the project. Don't forget the -lncurses commutator when constructing the object.

#include <ncurses.h>
int X = 40;
int Y = 12;
bool g = true;
int main()
{
initscr();
clear();
noecho();
printw("Movement test");
mvprintw(Y, X, "@");
while (g)
{
refresh();
switch (getch())
{
case 'D': //Left
mvprintw(Y, X, " ");
X--;
break;
case 'C': //Right
mvprintw(Y, X, " ");
X++;
break;
case 'A': //Up
mvprintw(Y, X, " ");
Y--;
break;
case 'B': //Down
mvprintw(Y, X, " ");
Y++;
break;
}
mvprintw(Y, X, "@");
// OR
//move(Y, X);
//printw("@");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment