Text-Based-Graphics not updating correctly
so this is kinda hard to explain but I will do my best.
I am making a rpg(ish) game using the Cmd on windows for graphics. I am
basically just making walls and a player right now and updating him and
redrawing the screen.
my problem is that movement works perfect except when I attempt to hold
the "Down" key down. there is a short pause and then the player 'jumps' to
the bottom of the screen. I have no idea why this is happening and cannot
seem to single my problem down to a narrow part of my code so here is all
of it (still not a lot of code).
#include <iostream>
#include <cstring>
#include <cstdlib>
#include<conio.h>
#include<Dos.h>
#include <windows.h>
#define HEIGHT 25
#define WIDTH 80
using namespace std;
void boardLogic();
void renderBoard();
void render();
int seed = 0;
int GameSpeed = 150;
int MovementSpeed = 1500;
bool stopped = false;
bool doneRendering = false;
char board[83][83] =
{"###############################################################################",
"#1
#",
"#2 @
#",
"#3
#",
"#4
#",
"#5
#",
"#6
#",
"#7
#",
"#8
#",
"#9
#",
"#
#",
"#
#",
"#
#",
"#
#",
"#
#",
"#
#",
"###############################################################################",
"#
#",
"#1
#",
"#2
#",
"#3
#",
"#4
#",
"#5
#",
"###############################################################################",
};
int main()
{
system("Color 3");
while(stopped == false)
{
boardLogic();
system("cls");
render();
Sleep(GameSpeed);
}
}
void renderBoard()
{
srand(seed);
for(int x = 0; x < 24; x++)
{
cout << board[x];
for(int y = 0; y < 84; y++)
{
if(board[x][y] == '#') board[x][y] = 219;
}
cout << endl;
}
}
void boardLogic()
{
for(int x = 0; x < 24; x++)
{
for(int y = 0; y < 84; y++)
{
if(board[x][y] == '#') board[x][y] = 219;
if(board[x][y] == '@' && doneRendering == true)
{
if(GetAsyncKeyState(VK_UP) != 0)
{
if(board[x-1][y] == ' ')
{
board[x-1][y] = '@';
board[x][y] = ' ';
break;
}
Sleep(MovementSpeed);
break;
}
if(GetAsyncKeyState(VK_RIGHT) != 0)
{
if(board[x][y+1] == ' ')
{
board[x][y+1] = '@';
board[x][y] = ' ';
break;
}
Sleep(MovementSpeed);
break;
}
if(GetAsyncKeyState(VK_LEFT) != 0)
{
if(board[x][y-1] == ' ')
{
board[x][y-1] = '@';
board[x][y] = ' ';
break;
}
Sleep(MovementSpeed);
break;
}
if(GetAsyncKeyState(VK_DOWN) != 0)
{
if(board[x+1][y] == ' ')
{
board[x+1][y] = '@';
board[x][y] = ' ';
break;
}
Sleep(MovementSpeed);
break;
}
}
}
}
}
void render()
{
doneRendering = false;
renderBoard();
doneRendering = true;
}
No comments:
Post a Comment