Im working on a cmd game for fun and I've run into a problem. I've coded in the movement and gravity, but in my last if statement where I attempt to make the character seize his downward movement if above a '219' char or in other wards a block, it doesnt work. I end up still going right through the block and deleting it if I attempt to fall on it. Heres the full source code so you may run it and see what I mean.
using namespace std;
char Map[10][81] =
{
" ",
" ",
" ",
" ",
" ### ",
" ",
" ",
" ",
" ",
"################################################################################",
};
int main()
{
bool start = true;
char dood('0');
bool print(false);
int x = 1;
int y = 8;
Map [y][x] = dood;
int cnt = 0;
int Height = 0;
int space_below = Map [y + 1][x];
while(start = true)
{
Sleep(20);
system("cls");
for(auto &c: Map)
{
for(auto &d: c)
{
if(d == '#')
{
d = 219;
}
cout << d;
}
cout << endl;
}
cout << "Height: " << Height <<" units";
if(GetAsyncKeyState(VK_RIGHT) != 0)
{
if(x != 79)
{
Map [y][x] = ' ';
x++;
Map [y][x] = dood;
}
}
if(GetAsyncKeyState(VK_LEFT) != 0)
{
if(x != 0)
{
Map [y][x] = ' ';
x--;
Map [y][x] = dood;
}
}
if (GetAsyncKeyState(VK_UP) != 0)
{
if(y < 9 && y > 0)
{
Map[y][x] = ' ';
y--;
Height++;
Map[y][x] = dood;
}
}
if(y < 8 && !GetAsyncKeyState(VK_UP))
{
if(space_below != '219')
{
Map[y][x] = ' ';
y++;
Height--;
Map[y][x] = dood;
}
}
}
return 0;
}
*Note: Inlude statements would work when pasting them in here, but I included iostream, windows.h, and time.h.
The last if statement is my gravity which procs if the player is not holding up, and when space_below, or the block below him is not a '219' ascii character, but but for some reason when I try to jump on that platform I made this doesn't work and that character just falls through and turns the block into a space(deletes it)!
I'm kinda new to c++, so I understand my mistake could be stupidly simple, but I haven't been able to find a fix on the internet. Any help is much appreciated :)