So I want to display an object with certain coordinates on the screen and make it able to move. If for example "u" is pressed it goes up and etc. So I tried using variables X and Y (initialized to 0) and after a "clear screen" deploying the object with a for loop. So check this out:
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
char input;
char player = 1;
char keyup = 0x48, keydown = 0x50, keyright = 0x4d, keyleft = 0x4b;
int x = 0, y = 0;
void position()
{
for (int start = 0; start <= y; start++)
{
cout << "\n";
}
for (int start = 0; start <= x; start++)
{
cout << " ";
}
cout << player;
}
void moveup()
{
x - 1;
system("cls");
position();
}
void movedown()
{
y + 1;
system("cls");
position();
}
void moveright()
{
x + 1;
system("cls");
position();
}
void moveleft()
{
y - 1;
system("cls");
position();
}
int main()
{
while (1)
{
position();
cin >> input;
if (input == keyup) moveup();
if (input == keydown) movedown();
if (input == keyright) moveright();
if (input == keyleft) moveleft();
system("cls");
}
}
So when I run it it just shows me the cube for ASCII key = 1; And no matter what I press it just blinks showing me the 'player' on the same position. Can you guys tell me what is the PROBLEM?