Need help with game

the @ symbol shouldn't leave a trail but it does

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  #include <iostream>
#include <windows.h>

using namespace std;

char map[23][23];

class Player
{
public:
	int x = 10;
	int y = 10;
	int px = 10;
	int py = 10;
	int hp = 100;
};

void SetMap()
{
	int countx = 23;
	int county = 23;

	while (county > 0)
	{
		while (countx > 0)
		{
			map[countx][county] = 219;
			countx--;
		}
		county--;
		countx = 23;
	}
}

void DrawScreen()
{
	int countx = 23;
	int county = 23;

	system("CLS");

	while (county > 0)
	{
		while (countx > 0)
		{
			cout << map[countx][county];
			countx--;
		}
		county--;
		countx = 23;
		cout << endl;
	}
}

int main()
{
	
	Player player;

	SetConsoleTitle("ASCII Quest");

	SetMap();
	
	while (true)
	{
		cout << "ASCII Quest" << endl << endl;
		cout << "1.Play" << endl << "2.Quit" << endl;
		
		system("pause > NULL");
		system("CLS");

		if (GetAsyncKeyState('1'))
		{
			while (TRUE)
			{
				map[player.px][player.py] = 219;
				map[player.x][player.y] = '@';

				DrawScreen();

				system("Pause > NULL");

				if (GetAsyncKeyState('W')) player.y++;

				if (GetAsyncKeyState('A')) player.x++;

				if (GetAsyncKeyState('D')) player.x--;

				if (GetAsyncKeyState('S')) player.y--;

				if (GetAsyncKeyState(VK_ESCAPE))
				{
					system("CLS");
					cout << "Paused" << endl << endl << "Press any key to resume.";
					system("Pause > NULL");
				}
				player.px = player.x;
				player.py = player.y;
			}
		}
		if (GetAsyncKeyState('2')) return(0);
	}	
}
Try moving line 77 to follow line 96( just before the line player.px = player.x; ).
Last edited on
Thanks!!!
You're welcome. I hope you'll see why that worked. At its old location line 77 was overwriting what line 96 does, because player.x equals player.px there (and for y). You want to assign the '@' symbol after player.x is changed, which isn't until after line 89 (for y).
Topic archived. No new replies allowed.