Bug with printing game

Can i speed up console cursor in any way? I have such Print and Deprint functions. the problem is on the screenshot.

The way ship looks like: http://imgur.com/ksXDDeI
The way it must look like: http://vignette2.wikia.nocookie.net/spaceinvaders/images/c/cb/Space-invaders.jpg/revision/latest?cb=20130701092122
if I don't move, everything is okay. But if this 'army' moves and i move at the same time, it gets broken.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 void virtual Deprint()
	{
		SetCursorPosition(position.X - col / 2 - 2, position.Y);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j <= col; j++)
			{
				SetCursorPosition(position.X + j, position.Y + i + 1);
				cout << ' ';
				Sleep(0.01);
			}
			SetCursorPosition(position.X - col / 2 - 2, position.Y + i + 1);
		}
	}

	void virtual Print()
	{
		SetCursorPosition(position.X - col / 2 - 1, position.Y);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col; j++)
			{
				SetCursorPosition(position.X + j, position.Y + i + 1);
				if (ship[i][j] == 1)
					cout << char(219);
				Sleep(0.01);
			}
			SetCursorPosition(position.X - col / 2 - 1, position.Y + i + 1);
		}
	}
Hi,
In Deprint() :
1
2
3
for (int i = 0; i < row; i++)
		{
			for (int j = 0; j <= col; j++)


The second for-loop is what that causes the buffer overflow here. Here's the fix :
1
2
3
for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col; j++)
Does that help you? :)
Nope, that's not the problem
Why do you use Sleep(0.01);? Sleep() doesn't accept double value from the start.
I can't see the screenshot. One link you provided is not accessible. The website says :
"That file type is not supported!

Supported formats: JPEG, GIF, PNG, APNG, TIFF, BMP, PDF, XCF"

Edit : What took you so long to respond?
Last edited on
Topic archived. No new replies allowed.