Help in Doing Certain Tasks

How can I make this so that the enemies disappear when we attack? In addition, the main character seems to be insta-dying :\
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <string>
#include <vector>

using namespace std;

void Clear()
{
	int n;
	for (n = 0; n < 10; n++)
		printf("\n\n\n\n\n\n\n");
}

char tmp_map[18][44];

char map[18][44] = {
	"+_________________________________________+",
	"|                                         |",
	"|                                         |",
	"|## #####     ###### ##   #########       |",
	"|   |                                     |",
	"| | |### |  |           |                 |",
	"| |      |  | |###  |   |  |              |",
	"| | #####|  | |      ## |                 |",
	"| |           |###  |      |              |",
	"| |##### ###         ##                   |",
	"|         ######  ###     #### ###        |",
	"|                                         |",
	"|# ### ####      ###   #####   ##         |",
	"|                                         |",
	"|                        ##               |",
	"|                                         |",
	"|    #####                                |",
	"+_________________________________________+"
};
void ShowMap()
{
	for (int i = 0; i < 18; i++) {
		printf("%s\n", map[i]);
	}
}

void gotoxy(short x, short y)
{
	HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD position = { x, y };

	SetConsoleCursorPosition(hStdout, position);
}

class entity {
public:
	entity(int x, int y) {
		this->x = x;
		this->y = y;
	}

	void move_x(int p) {
		if (map[y][x + p] == ' ') x += p;
	}

	void move_y(int p) {
		if (map[y + p][x] == ' ') y += p;
	}

	void move(int p, int q) {
		x += p;
		y += q;
	}

	int get_x() { return x; }
	int get_y() { return y; }

	void draw(char p) {
		map[x][y] = p;
		gotoxy(x, y); printf("%c", p);
	}

private:
	int x;
	int y;
};

struct walk {
	short walk_count;
	short x;
	short y;
	short back;
};

struct target {
	short x;
	short y;
};

vector<target> walk_queue;

vector<walk> BFSArray;

void AddArray(int x, int y, int wc, int back) {
	if (tmp_map[y][x] == ' ' || tmp_map[y][x] == '.') {
		tmp_map[y][x] = '#';
		walk tmp;
		tmp.x = x;
		tmp.y = y;
		tmp.walk_count = wc;
		tmp.back = back;
		BFSArray.push_back(tmp);
	}
}

void FindPath(int sx, int sy, int x, int y) {
	memcpy(tmp_map, map, sizeof(map));
	BFSArray.clear();
	walk tmp;
	tmp.x = sx;
	tmp.y = sy;
	tmp.walk_count = 0;
	tmp.back = -1;
	BFSArray.push_back(tmp);

	int i = 0;
	while (i < BFSArray.size()) {
		if (BFSArray[i].x == x && BFSArray[i].y == y) {
			walk_queue.clear();
			target tmp2;
			while (BFSArray[i].walk_count != 0) {
				tmp2.x = BFSArray[i].x;
				tmp2.y = BFSArray[i].y;
				walk_queue.push_back(tmp2);

				i = BFSArray[i].back;
			}

			break;
		}

		AddArray(BFSArray[i].x + 1, BFSArray[i].y, BFSArray[i].walk_count + 1, i);
		AddArray(BFSArray[i].x - 1, BFSArray[i].y, BFSArray[i].walk_count + 1, i);
		AddArray(BFSArray[i].x, BFSArray[i].y + 1, BFSArray[i].walk_count + 1, i);
		AddArray(BFSArray[i].x, BFSArray[i].y - 1, BFSArray[i].walk_count + 1, i);

		/*
		AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i );

		AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i );
		*/
		i++;
	}

	BFSArray.clear();
}

int main() {
	//this string is to retrieve the user's input name
	string name;
	
	
	cout << "			             Please Press 'ENTER' to Begin " << endl;



	std::cin.get();
	Clear();
	cout << "Far into the future, in a world ravaged by evil droids, there was a single bot, seeking to avenge his kind." << endl;
	Sleep(3000);
	cout << "The droids had long since tried to consume him, and make him one of their kind." << endl;
	Sleep(3000);
	cout << "But, little did they know, he had the power of" << endl;
	Sleep(3000);
	cout << "CRYPTOMANCY!!!" << endl;
	Sleep(3000);
	cout << "Press 'ENTER'";
	cin.get();
	cin.get();
	Clear();

	
	std::cin.get();
	Clear();
	cout << "Press 'ENTER'";
	std::cin.get();

	bool running = true;
	int x = 15; // hero x
	int y = 16; // hero y
	int old_x;
	int old_y;

	int ex = 1;
	int ey = 1;


	int pts = 0;

	printf("Instruction:\n1. Arrow Keys to move your hero\n2. Eat the dots produced by the Eater to gain points\n3. Don't get caught by the Eater\n\n");
	printf("H -> Hard\nN -> Normal\nE -> Easy\n\nInput : ");

	char diffi;
	int speedmod = 3;

	cin >> diffi;

	if (diffi == 'N' || diffi == 'n') {
		speedmod = 2;
	}
	else if (diffi == 'H' || diffi == 'h') {
		speedmod = 1;
	}

	system("cls");
	ShowMap();

	gotoxy(x, y); cout << "H";

	int frame = 0;

	FindPath(ex, ey, x, y);

	while (running) {
		gotoxy(x, y); cout << " ";

		old_x = x;
		old_y = y;

		if (GetAsyncKeyState(0x53)) {
			if (map[y + 1][x] == '.') { y++; pts++; }
			else
				if (map[y + 1][x] == ' ') y++;
		}
		if (GetAsyncKeyState(0x57)) {
			if (map[y - 1][x] == '.') { y--; pts++; }
			else
				if (map[y - 1][x] == ' ') y--;
		}
		if (GetAsyncKeyState(0x44)) {
			if (map[y][x + 1] == '.') { x++; pts++; }
			else
				if (map[y][x + 1] == ' ') x++;
		}
		if (GetAsyncKeyState(0x41)) {
			if (map[y][x - 1] == '.') { x--; pts++; }
			else
				if (map[y][x - 1] == ' ') x--;
		}

		if (GetAsyncKeyState(VK_SPACE)) {
			if (map[y][x + 2] == 'E') { x++; pts++; }
			else if (map[y][x - 2] == 'E') { x--; pts++; }
			else if (map[y - 2][x] == 'E') { y--; pts++; }
			else if (map[y + 2][x] == 'E') { y++; pts++; }
			else if (map[y][x - 1] == 'E') { x--; pts++; }
			else if (map[y - 1][x] == 'E') { y--; pts++; }
			else if (map[y + 1][x] == 'E') { y++; pts++; }
			else if (map[y][x + 1] == 'E') { x++; pts++; }
			else if (map[y][x - 2] == 'E') { x--; pts++; }

			else if (map[y - 2][x - 2] == 'E') { y--; pts++; }
			else if (map[y + 2][x - 2] == 'E') { y++; pts++; }
			else if (map[y - 1][x - 1] == 'E') { x--; pts++; }
			else if (map[y - 2][x + 2] == 'E') { x--; pts++; }
			else if (map[y - 1][x + 1] == 'E') { y--; pts++; }
			else if (map[y + 1][x - 1] == 'E') { y++; pts++; }
			else if (map[y + 1][x + 1] == 'E') { x++; pts++; }
			else if (map[y + 2][x + 2] == 'E') { x++; pts++; }

			if (old_x != x || old_y != y) {
				FindPath(ex, ey, x, y);
			}

			gotoxy(x, y); cout << "H";

			map[ey][ex] = '.';
			gotoxy(ex, ey); cout << ".";

			if (frame%speedmod == 0 && walk_queue.size() != 0) {
				ex = walk_queue.back().x;
				ey = walk_queue.back().y;
				walk_queue.pop_back();
			}

			gotoxy(ex, ey); cout << "E";

			if (ex == x && ey == y) {
				break;
			}


			gotoxy(32, 18);
			gotoxy(46, 1); cout << pts;
			Sleep(100);
			frame++;
		}

		system("cls");
		cout << "GAMEOVER! You scored: %i , pts" << endl;
		cout << "" << endl;
	
		cin.get();
		cin.get();

		return 0;
	}
}
Last edited on
Topic archived. No new replies allowed.