Tank 1990 — различия между версиями

Материал из Department of Theoretical and Applied Mechanics
Перейти к: навигация, поиск
(Новая страница: «==Описание== Игра конца 20 века Battle City, известная как Tank 1990, созданная на языке JavaScript. В прог…»)
 
 
(не показаны 2 промежуточные версии этого же участника)
Строка 9: Строка 9:
  
 
==Код программы==
 
==Код программы==
<div class="mw-collapsible mw-collapsed" style="width:100%">
+
<div class="mw-collapsible mw-collapsed">
HTML
+
'''Код программы на языке JavaScript:''' <div class="mw-collapsible-content">
<div class="mw-collapsible-content">
+
<syntaxhighlight lang="javascript" line start="1" enclose="div">
<!DOCTYPE html>
 
<!--Комментарий -->
 
<html> <!--Открытие-->
 
<head>
 
<title>ALPHA</title>
 
<script src='alpha1.js'></script>
 
</head>
 
<body>
 
<table>
 
<tr>
 
<td><canvas id="canvas_example" width=500 height=500 style='border: 1px solid #000000;'></canvas></td>
 
<td></br>Добро пожаловать. Кнопки управления: WASD. Нажмите "Пробел" чтобы выстрелить.
 
</br> Не дайте врагу убить Вас и Вашу зелёную базу!
 
</br></br>Очки: <span id=Kills></span>
 
</br>Уровень: <span id=Level></span></td>
 
</tr>
 
</table>
 
</body>
 
</html>
 
</div></div>
 
  
<div class="mw-collapsible mw-collapsed" style="width:100%">
 
JavaScript
 
<div class="mw-collapsible-content">
 
 
window.addEventListener('load', main, false);
 
window.addEventListener('load', main, false);
 
function main()
 
function main()
Строка 914: Строка 891:
  
  
</div></div>
+
 
 +
</syntaxhighlight>
 +
</div>

Текущая версия на 16:52, 1 июня 2020

Описание[править]

Игра конца 20 века Battle City, известная как Tank 1990, созданная на языке JavaScript. В программе предусмотрено управление танком при нажатии на клавиши клавиатуры "WASD" и "Пробел", противники и усложнение игры с каждым уровнем.

Автор: Галеев Рауль Рустемович, группа №3630103/90003

Игра[править]

Код программы[править]

Код программы на языке JavaScript:
  1 window.addEventListener('load', main, false);
  2 function main()
  3 {
  4 	function fps() {
  5 		for (var i = 0; i < bullets.length; i++) {
  6 			map[bullets[i].x][bullets[i].y] = 0;
  7 			if (bullets[i].dir == UP) {
  8 				bullets[i].y = bullets[i].y;
  9 				if (map[bullets[i].x][bullets[i].y-1] == 0) {
 10 					bullets[i].y -= 1;
 11 				} 
 12 				else
 13 				if (map[bullets[i].x][bullets[i].y-1] == 2) {
 14 					map[bullets[i].x][bullets[i].y-1] = 0;
 15 					bullets.splice(i, 1);
 16 					// continue;
 17 				} 
 18 				else
 19 				if ((map[bullets[i].x][bullets[i].y-1] == 7)&&(bullets[i].tag == me)) {
 20 					map[bullets[i].x][bullets[i].y-1] = 0;
 21 					for (var j = 0; j < enemies.length; j++) {
 22 						if ((map[bullets[i].x][bullets[i].y-1] == map[enemies[j].xbot][enemies[j].ybot+1])||(map[bullets[i].x][bullets[i].y-1] == map[enemies[j].xbot+1][enemies[j].ybot+1])||(map[bullets[i].x][bullets[i].y-1] == map[enemies[j].xbot-1][enemies[j].ybot+1])) {
 23 							console.log(11111);
 24 							bullets.splice(i, 1);
 25 							
 26 							map[enemies[j].xbot][enemies[j].ybot] = 0;
 27 							map[enemies[j].xbot+1][enemies[j].ybot] = 0;
 28 							map[enemies[j].xbot][enemies[j].ybot+1] = 0;
 29 							map[enemies[j].xbot-1][enemies[j].ybot] = 0;
 30 							map[enemies[j].xbot][enemies[j].ybot-1] = 0;
 31 							map[enemies[j].xbot+1][enemies[j].ybot+1] = 0;
 32 							map[enemies[j].xbot-1][enemies[j].ybot-1] = 0;
 33 							map[enemies[j].xbot+1][enemies[j].ybot-1] = 0;
 34 							map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
 35 							
 36 							enemies.splice(j, 1);
 37 							
 38 							killsCount();
 39 							draw();
 40 						}
 41 					}
 42 				} else
 43 				if (((map[bullets[i].x][bullets[i].y-1] == 1)||(map[bullets[i].x][bullets[i].y-1] == 6)||(map[bullets[i].x][bullets[i].y-1] == 5))&&(bullets[i].tag == enemy)) {
 44 					map[bullets[i].x][bullets[i].y-1] = 0;
 45 					map[x][y] = 0;
 46 					map[x+1][y] = 0;
 47 					map[x][y+1] = 0;
 48 					map[x-1][y] = 0;
 49 					map[x][y-1] = 0;
 50 					map[x+1][y+1] = 0;
 51 					map[x-1][y-1] = 0;
 52 					map[x+1][y-1] = 0;
 53 					map[x-1][y+1] = 0;
 54 					draw();
 55 					
 56 					gameOver();
 57 					break;
 58 					
 59 				}
 60 				else {
 61 					bullets.splice(i, 1);
 62 					continue;
 63 				}
 64 			} else
 65 				
 66 			if (bullets[i].dir == DOWN) {
 67 				bullets[i].y = bullets[i].y;
 68 				if (map[bullets[i].x][bullets[i].y+1] == 0) {
 69 					bullets[i].y += 1;
 70 				} else 
 71 				if (map[bullets[i].x][bullets[i].y+1] == 2) {
 72 					map[bullets[i].x][bullets[i].y+1] = 0;
 73 					bullets.splice(i, 1);
 74 					// continue;
 75 				} else
 76 				if ((map[bullets[i].x][bullets[i].y+1] == 7)&&(bullets[i].tag == me)) {
 77 					map[bullets[i].x][bullets[i].y+1] = 0;
 78 					for (var j = 0; j < enemies.length; j++) {
 79 						if ((map[bullets[i].x][bullets[i].y+1] == map[enemies[j].xbot][enemies[j].ybot-1])||(map[bullets[i].x][bullets[i].y+1] == map[enemies[j].xbot+1][enemies[j].ybot-1])||(map[bullets[i].x][bullets[i].y+1] == map[enemies[j].xbot-1][enemies[j].ybot-1])) {
 80 							console.log(11111);
 81 							bullets.splice(i, 1);
 82 							
 83 							map[enemies[j].xbot][enemies[j].ybot] = 0;
 84 							map[enemies[j].xbot+1][enemies[j].ybot] = 0;
 85 							map[enemies[j].xbot][enemies[j].ybot+1] = 0;
 86 							map[enemies[j].xbot-1][enemies[j].ybot] = 0;
 87 							map[enemies[j].xbot][enemies[j].ybot-1] = 0;
 88 							map[enemies[j].xbot+1][enemies[j].ybot+1] = 0;
 89 							map[enemies[j].xbot-1][enemies[j].ybot-1] = 0;
 90 							map[enemies[j].xbot+1][enemies[j].ybot-1] = 0;
 91 							map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
 92 							
 93 							enemies.splice(j, 1);
 94 							
 95 							killsCount();
 96 							draw();
 97 						}
 98 					}
 99 				} else
100 				if (((map[bullets[i].x][bullets[i].y+1] == 1)||(map[bullets[i].x][bullets[i].y+1] == 6)||(map[bullets[i].x][bullets[i].y+1] == 5))&&(bullets[i].tag == enemy)) {
101 					map[bullets[i].x][bullets[i].y-1] = 0;
102 					map[x][y] = 0;
103 					map[x+1][y] = 0;
104 					map[x][y+1] = 0;
105 					map[x-1][y] = 0;
106 					map[x][y-1] = 0;
107 					map[x+1][y+1] = 0;
108 					map[x-1][y-1] = 0;
109 					map[x+1][y-1] = 0;
110 					map[x-1][y+1] = 0;
111 					draw();
112 					
113 					gameOver();
114 					break;
115 				}
116 				
117 				else
118 				{
119 					bullets.splice(i, 1);
120 					continue;
121 				}
122 			} else
123 				
124 			if (bullets[i].dir == RIGHT) {
125 				bullets[i].x = bullets[i].x;
126 				if (map[bullets[i].x+1][bullets[i].y] == 0) {
127 					bullets[i].x += 1;
128 				} else 
129 				if (map[bullets[i].x+1][bullets[i].y] == 2) {
130 					map[bullets[i].x+1][bullets[i].y] = 0;
131 					bullets.splice(i, 1);
132 					// continue;
133 				} else
134 				if ((map[bullets[i].x+1][bullets[i].y] == 7)&&(bullets[i].tag == me)) {
135 					map[bullets[i].x+1][bullets[i].y] = 0;
136 					for (var j = 0; j < enemies.length; j++) {
137 						if ((map[bullets[i].x+1][bullets[i].y] == map[enemies[j].xbot-1][enemies[j].ybot])||(map[bullets[i].x+1][bullets[i].y] == map[enemies[j].xbot-1][enemies[j].ybot+1])||(map[bullets[i].x+1][bullets[i].y] == map[enemies[j].xbot-1][enemies[j].ybot-1])) {
138 							console.log(11111);
139 							bullets.splice(i, 1);
140 							
141 							map[enemies[j].xbot][enemies[j].ybot] = 0;
142 							map[enemies[j].xbot+1][enemies[j].ybot] = 0;
143 							map[enemies[j].xbot][enemies[j].ybot+1] = 0;
144 							map[enemies[j].xbot-1][enemies[j].ybot] = 0;
145 							map[enemies[j].xbot][enemies[j].ybot-1] = 0;
146 							map[enemies[j].xbot+1][enemies[j].ybot+1] = 0;
147 							map[enemies[j].xbot-1][enemies[j].ybot-1] = 0;
148 							map[enemies[j].xbot+1][enemies[j].ybot-1] = 0;
149 							map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
150 							
151 							enemies.splice(j, 1);
152 							
153 							killsCount();
154 							draw();
155 						}
156 					}
157 				} else
158 					if (((map[bullets[i].x+1][bullets[i].y] == 1)||(map[bullets[i].x+1][bullets[i].y] == 6)||(map[bullets[i].x+1][bullets[i].y] == 5))&&(bullets[i].tag == enemy)) {
159 					map[bullets[i].x][bullets[i].y-1] = 0;
160 					map[x][y] = 0;
161 					map[x+1][y] = 0;
162 					map[x][y+1] = 0;
163 					map[x-1][y] = 0;
164 					map[x][y-1] = 0;
165 					map[x+1][y+1] = 0;
166 					map[x-1][y-1] = 0;
167 					map[x+1][y-1] = 0;
168 					map[x-1][y+1] = 0;
169 					draw();
170 					
171 					gameOver();
172 					break;
173 					
174 				} else
175 				{
176 					bullets.splice(i, 1);
177 					continue;
178 				}
179 			} else
180 			if (bullets[i].dir == LEFT) {
181 				bullets[i].x = bullets[i].x;
182 				if (map[bullets[i].x-1][bullets[i].y] == 0) {
183 					bullets[i].x -= 1;
184 				} else 
185 				if (map[bullets[i].x-1][bullets[i].y] == 2) {
186 					map[bullets[i].x-1][bullets[i].y] = 0;
187 					bullets.splice(i, 1);
188 					// continue;
189 				} 
190 				else
191 				if ((map[bullets[i].x-1][bullets[i].y] == 7)&&(bullets[i].tag == me)) {
192 					map[bullets[i].x-1][bullets[i].y] = 0;
193 					for (var j = 0; j < enemies.length; j++) {
194 						if ((map[bullets[i].x-1][bullets[i].y] == map[enemies[j].xbot+1][enemies[j].ybot])||(map[bullets[i].x-1][bullets[i].y] == map[enemies[j].xbot+1][enemies[j].ybot+1])||(map[bullets[i].x-1][bullets[i].y] == map[enemies[j].xbot+1][enemies[j].ybot-1])) {
195 							console.log(11111);
196 							bullets.splice(i, 1);
197 							
198 							map[enemies[j].xbot][enemies[j].ybot] = 0;
199 							map[enemies[j].xbot+1][enemies[j].ybot] = 0;
200 							map[enemies[j].xbot][enemies[j].ybot+1] = 0;
201 							map[enemies[j].xbot-1][enemies[j].ybot] = 0;
202 							map[enemies[j].xbot][enemies[j].ybot-1] = 0;
203 							map[enemies[j].xbot+1][enemies[j].ybot+1] = 0;
204 							map[enemies[j].xbot-1][enemies[j].ybot-1] = 0;
205 							map[enemies[j].xbot+1][enemies[j].ybot-1] = 0;
206 							map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
207 							
208 							enemies.splice(j, 1);
209 							
210 							killsCount();
211 							draw();
212 						}
213 					}
214 				} else
215 					if (((map[bullets[i].x-1][bullets[i].y] == 1)||(map[bullets[i].x-1][bullets[i].y] == 6)||(map[bullets[i].x-1][bullets[i].y] == 5))&&(bullets[i].tag == enemy)) {
216 					map[bullets[i].x][bullets[i].y-1] = 0;
217 					map[x][y] = 0;
218 					map[x+1][y] = 0;
219 					map[x][y+1] = 0;
220 					map[x-1][y] = 0;
221 					map[x][y-1] = 0;
222 					map[x+1][y+1] = 0;
223 					map[x-1][y-1] = 0;
224 					map[x+1][y-1] = 0;
225 					map[x-1][y+1] = 0;
226 					
227 					gameOver();
228 					break;
229 					
230 					} else
231 				{
232 					bullets.splice(i, 1);
233 					continue;
234 				}
235 			}
236 			map[bullets[i].x][bullets[i].y] = 4;
237 		}
238 		draw();
239 		
240 	}
241 	var ctx = canvas_example.getContext('2d');
242 	var w = canvas_example.width;
243 	var h = canvas_example.height;
244 	
245 	var N = 50;
246 	
247 	/*
248 	function pause(ms) {
249 		return new Promise(resolve => setTimeout(resolve, ms));
250 		// для паузы в последствии писать await pause(1000);
251 	}	
252 	*/
253 	var map = [];
254 	for (var i=0; i<N; i++) {
255 		var a = [];
256 		for (var j=0; j<N; j++) {
257 			a.push(0);
258 		}
259 		map.push(a);
260 	}
261 	
262 	var kills = 0;
263 	var x = 18;
264 	var y = 45;
265 	
266 	var me = 0;
267 	var enemy = 1;
268 	
269 	var UP = 0;
270 	var RIGHT = 1;
271 	var DOWN = 3;
272 	var LEFT = 2;
273 	
274 	var pause = false;
275 	
276 	var koef = 5;
277 	
278 	var a = 0;
279 	var b = 1;
280 	var c = 0;
281 	
282 	var bullets = [];
283 	
284 	let timer;
285 	
286 	map[x][y] = 1;
287 	map[x+1][y] = 1;
288 	map[x][y+1] = 1;
289 	map[x-1][y] = 1;
290 	map[x][y-1] = 6;
291 	map[x+1][y+1] = 1;
292 	map[x-1][y-1] = 1;
293 	map[x+1][y-1] = 1;
294 	map[x-1][y+1] = 1;
295 	
296 	// СТЕНЫ
297 		// СТЕНА БАЗЫ
298 	for (var i=20; i<23; i++) {
299 		for (var j=41; j<47; j++) {
300 		map[i][j] = 2;
301 		}
302 	}
303 	for (var i=26; i<29; i++) {
304 		for (var j=41; j<47; j++) {
305 		map[i][j] = 2;
306 		}
307 	}
308 	for (var i=20; i<29; i++) {
309 		for (var j=41; j<44; j++) {
310 		map[i][j] = 2;
311 		}
312 	}
313 	// База
314 	for (var i=23; i<26; i++) {
315 		for (var j=44; j<47; j++) {
316 		map[i][j] = 5;
317 		}
318 	}
319 	// ГРАНИЦЫ-СТЕНЫ
320 	function reWall() {
321 	for (var i=0; i<50; i++) {
322 		for (var j=0; j<3; j++) {
323 		map[i][j] = 3;
324 		}
325 	}
326 	for (var i=0; i<3; i++) {
327 		for (var j=0; j<50; j++) {
328 		map[i][j] = 3;
329 		}
330 	}
331 	for (var i=47; i<50; i++) {
332 		for (var j=0; j<50; j++) {
333 		map[i][j] = 3;
334 		}
335 	}
336 	for (var i=0; i<50; i++) {
337 		for (var j=47; j<50; j++) {
338 		map[i][j] = 3;
339 		}
340 	}
341 	// Жёсткие стены
342 	for (var i=23; i<26; i++) {
343 		for (var j=3; j<6; j++) {
344 		map[i][j] = 3;
345 		}
346 	}
347 	
348 	for (var i=44; i<47; i++) {
349 		for (var j=23; j<26; j++) {
350 		map[i][j] = 3;
351 		}
352 	}
353 	
354 	for (var i=3; i<6; i++) {
355 		for (var j=23; j<26; j++) {
356 		map[i][j] = 3;
357 		}
358 	}
359 	draw();
360 	}
361 	// innocent стены
362 		// Разрушающиеся стены
363 	for (var i=12; i<20; i++) {
364 		for (var j=6; j<9; j++) {
365 		map[i][j] = 2;
366 		}
367 	}
368 	
369 	for (var i=15; i<18; i++) {
370 		for (var j=12; j<15; j++) {
371 		map[i][j] = 3;
372 		}
373 	}
374 	
375 	for (var i=31; i<34; i++) {
376 		for (var j=12; j<15; j++) {
377 		map[i][j] = 3;
378 		}
379 	}
380 	
381 	for (var i=12; i<20; i++) {
382 		for (var j=15; j<18; j++) {
383 		map[i][j] = 2;
384 		}
385 	}
386 	
387 	for (var i=20; i<29; i++) {
388 		for (var j=24; j<27; j++) {
389 		map[i][j] = 2;
390 		}
391 	}
392 	
393 	for (var i=29; i<38; i++) {
394 		for (var j=6; j<9; j++) {
395 		map[i][j] = 2;
396 		}
397 	}
398 	
399 	for (var i=29; i<38; i++) {
400 		for (var j=15; j<18; j++) {
401 		map[i][j] = 2;
402 		}
403 	}
404 	
405 	for (var i=6; i<9; i++) {
406 		for (var j=6; j<18; j++) {
407 		map[i][j] = 2;
408 		}
409 	}
410 	
411 	for (var i=6; i<20; i++) {
412 		for (var j=30; j<33; j++) {
413 		map[i][j] = 2;
414 		}
415 	}
416 	
417 	for (var i=29; i<44; i++) {
418 		for (var j=30; j<33; j++) {
419 		map[i][j] = 2;
420 		}
421 	}
422 	
423 	for (var i=41; i<44; i++) {
424 		for (var j=30; j<39; j++) {
425 		map[i][j] = 2;
426 		}
427 	}
428 	
429 	for (var i=6; i<9; i++) {
430 		for (var j=30; j<39; j++) {
431 		map[i][j] = 2;
432 		}
433 	}
434 	
435 	for (var i=41; i<44; i++) {
436 		for (var j=6; j<18; j++) {
437 		map[i][j] = 2;
438 		}
439 	}
440 	
441 	for (var i=23; i<26; i++) {
442 		for (var j=6; j<26; j++) {
443 		map[i][j] = 2;
444 		}
445 	}
446 	
447 	
448 	draw();
449 	
450 	function draw() {
451 		for (var i=0; i<N; i++) {
452 			for (var j=0; j<N; j++) {
453 				if (map[i][j]==0) {
454 					ctx.fillStyle='white';
455 				} else
456 				
457 				if (map[i][j]==1) {
458 					ctx.fillStyle='red';
459 				} else
460 				
461 				if (map[i][j]==2) {
462 					ctx.fillStyle='brown';
463 				} else
464 				if (map[i][j]==3) {
465 					ctx.fillStyle='grey';
466 				} else
467 				if (map[i][j]==4) {
468 					ctx.fillStyle='black';
469 				} else
470 				if (map[i][j]==5) {
471 					ctx.fillStyle='green';
472 				} else
473 				if (map[i][j]==7) {
474 					ctx.fillStyle='blue';
475 				} else
476 				if (map[i][j]==8) {
477 					ctx.fillStyle='purple';
478 				} else
479 				if (map[i][j]==6) {
480 					ctx.fillStyle='orange';
481 				}
482 				/*
483 				else {
484 					ctx.fillStyle='red';
485 				}
486 				*/
487 				
488 				ctx.fillRect(i*w/N, j*h/N, N, N);
489 			}
490 		}
491 	}
492 	
493 
494 	function shootUp(x,y,dir,tag) {
495 
496 		if (dir == UP) {
497 			bullets.push({ x: x, y: y-2, dir: dir, tag: tag});
498 		} else
499 		if (dir == DOWN) {
500 			bullets.push({ x: x, y: y+2, dir: dir, tag: tag});
501 		} else
502 		if (dir == RIGHT) {
503 			bullets.push({ x: x+2, y: y, dir: dir, tag: tag});
504 		} else
505 		if (dir == LEFT) {
506 			bullets.push({ x: x-2, y: y, dir: dir, tag: tag});
507 		} else
508 				{
509 					bullets.splice(i, 1);
510 				}
511 	}
512 	// Управление
513 	function player() {
514 	document.onkeypress = function (event) {
515 		if (pause) return;
516 		let key = event.keyCode || event.charCodel;
517 		if ((event.key == 'd')||(event.key == 'в')||(event.key == 'D')||(event.key == 'В')){
518 			map[x-1][y] = 1;
519 			map[x+1][y] = 6;
520 			map[x][y+1] = 1;
521 			map[x][y-1] = 1;
522 			draw();
523 			if ((map[x+2][y]==0)&&(map[x+2][y+1]==0)&&(map[x+2][y-1]==0)) {
524 				map[x-1][y-1] = 0;
525 				map[x-1][y] = 0;
526 				map[x-1][y+1] = 0;
527 				x++;
528 				map[x][y] = 1;
529 				map[x+1][y] = 6;
530 				map[x][y+1] = 1;
531 				map[x-1][y] = 1;
532 				map[x][y-1] = 1;
533 				map[x+1][y+1] = 1;
534 				map[x-1][y-1] = 1;
535 				map[x+1][y-1] = 1;
536 				map[x-1][y+1] = 1;
537 				draw();
538 			}
539 			b = 1;
540 		} else 
541 		if ((event.key == 'a')||(event.key == 'ф')||(event.key == 'A')||(event.key == 'Ф')){
542 			map[x-1][y] = 6;
543 			map[x+1][y] = 1;
544 			map[x][y+1] = 1;
545 			map[x][y-1] = 1;
546 			draw();
547 			if ((map[x-2][y]==0)&&(map[x-2][y+1]==0)&&(map[x-2][y-1]==0)) { 
548 				map[x+1][y-1] = 0;
549 				map[x+1][y] = 0;
550 				map[x+1][y+1] = 0;
551 				x--;
552 				map[x][y] = 1;
553 				map[x+1][y] = 1;
554 				map[x][y+1] = 1;
555 				map[x-1][y] = 6;
556 				map[x][y-1] = 1;
557 				map[x+1][y+1] = 1;
558 				map[x-1][y-1] = 1;
559 				map[x+1][y-1] = 1;
560 				map[x-1][y+1] = 1;
561 				draw();
562 			}
563 			b = 2;
564 		}
565 		else 
566 		if ((event.key == 's')||(event.key == 'ы')||(event.key == 'S')||(event.key == 'Ы')){
567 			map[x-1][y] = 1;
568 			map[x+1][y] = 1;
569 			map[x][y+1] = 6;
570 			map[x][y-1] = 1;
571 			draw();
572 			if ((map[x][y+2]==0)&&(map[x+1][y+2]==0)&&(map[x-1][y+2]==0)) {
573 				map[x+1][y-1] = 0;
574 				map[x][y-1] = 0;
575 				map[x-1][y-1] = 0;
576 				y++;
577 				map[x][y] = 1;
578 				map[x+1][y] = 1;
579 				map[x][y+1] = 6;
580 				map[x-1][y] = 1;
581 				map[x][y-1] = 1;
582 				map[x+1][y+1] = 1;
583 				map[x-1][y-1] = 1;
584 				map[x+1][y-1] = 1;
585 				map[x-1][y+1] = 1;
586 				
587 				draw();
588 			}
589 			b = 3;
590 		}
591 		else
592 		if ((event.key == 'w')||(event.key == 'ц')||(event.key == 'W')||(event.key == 'Ц')){
593 			map[x-1][y] = 1;
594 			map[x+1][y] = 1;
595 			map[x][y+1] = 1;
596 			map[x][y-1] = 6;
597 			draw();
598 			if ((map[x][y-2]==0)&&(map[x+1][y-2]==0)&&(map[x-1][y-2]==0)) {
599 				map[x+1][y+1] = 0;
600 				map[x][y+1] = 0;
601 				map[x-1][y+1] = 0;
602 				y--;
603 				map[x][y] = 1;
604 				map[x+1][y] = 1;
605 				map[x][y+1] = 1;
606 				map[x-1][y] = 1;
607 				map[x][y-1] = 6;
608 				map[x+1][y+1] = 1;
609 				map[x-1][y-1] = 1;
610 				map[x+1][y-1] = 1;
611 				map[x-1][y+1] = 1;
612 				draw();
613 			}
614 			b = 4;
615 		}
616 	    else
617 		if (!timer && event.key == ' ') {
618 			if ((map[x][y-1] == 6)&&(map[x][y-2] != 3))  {
619 				// map[x][y-2] = 4;
620 				//a = 1;
621 				shootUp(x,y,UP,me);
622 				
623 			}
624 			if ((map[x][y+1] == 6)&&(map[x][y+2] != 3)) {
625 				//a = 2;
626 				shootUp(x,y,DOWN, me);
627 			}
628 			if ((map[x+1][y] == 6)&&(map[x+2][y] != 3)) {
629 				//a = 3;
630 				shootUp(x,y,RIGHT,me);
631 			}
632 			if ((map[x-1][y] == 6)&&(map[x-2][y] != 3)) {
633 				//a = 4;
634 				shootUp(x,y,LEFT,me);
635 			}
636 			timer = setTimeout(() => timer = clearTimeout(timer), 150);
637 		}
638 	}
639 	}
640 	
641 	function renderPlayer() {
642 		if (b == 1) {
643 				map[x][y] = 1;
644 				map[x+1][y] = 6;
645 				map[x][y+1] = 1;
646 				map[x-1][y] = 1;
647 				map[x][y-1] = 1;
648 				map[x+1][y+1] = 1;
649 				map[x-1][y-1] = 1;
650 				map[x+1][y-1] = 1;
651 				map[x-1][y+1] = 1;
652 				draw();
653 		} else
654 		if (b == 2) {
655 				map[x][y] = 1;
656 				map[x+1][y] = 1;
657 				map[x][y+1] = 1;
658 				map[x-1][y] = 6;
659 				map[x][y-1] = 1;
660 				map[x+1][y+1] = 1;
661 				map[x-1][y-1] = 1;
662 				map[x+1][y-1] = 1;
663 				map[x-1][y+1] = 1;
664 				draw();
665 		} else
666 		if (b == 3) {
667 				map[x][y] = 1;
668 				map[x+1][y] = 1;
669 				map[x][y+1] = 6;
670 				map[x-1][y] = 1;
671 				map[x][y-1] = 1;
672 				map[x+1][y+1] = 1;
673 				map[x-1][y-1] = 1;
674 				map[x+1][y-1] = 1;
675 				map[x-1][y+1] = 1;
676 				draw();
677 		} else
678 		if (b == 4) {
679 				map[x][y] = 1;
680 				map[x+1][y] = 1;
681 				map[x][y+1] = 1;
682 				map[x-1][y] = 1;
683 				map[x][y-1] = 6;
684 				map[x+1][y+1] = 1;
685 				map[x-1][y-1] = 1;
686 				map[x+1][y-1] = 1;
687 				map[x-1][y+1] = 1;
688 				draw();
689 		}
690 	}
691 	
692 	
693 	// БОТЯРА
694 	
695 	var enemies = [];
696 	var xbot;
697 	var ybot;
698 	var j = 1;
699 	var gen = 0;
700 	var lvl = 0;
701 	
702 	function botSpawn() {
703 	if (enemies == 0) {
704 	lvl = lvl + 1;
705 	enemies.push({ xbot: 21, ybot: 10 });
706 	enemies.push({ xbot: 27, ybot: 10 });
707 	if (lvl == 2) {
708 	enemies.push({ xbot: 44, ybot: 4 });
709 	enemies.push({ xbot: 4, ybot: 4 });
710 	}
711 	if (lvl == 3) {
712 		enemies.push({ xbot: 44, ybot: 4 });
713 		enemies.push({ xbot: 4, ybot: 4 });
714 		enemies.push({ xbot: 7, ybot: 24 });
715 	}
716 	if (lvl == 4) {
717 		enemies.push({ xbot: 44, ybot: 4 });
718 		enemies.push({ xbot: 4, ybot: 4 });
719 		enemies.push({ xbot: 7, ybot: 24 });
720 		enemies.push({ xbot: 42, ybot: 24 });
721 	}
722 	koef = koef + 5;
723 	}
724 
725 	for (var i = 0; i < enemies.length; i++) {
726 		map[enemies[i].xbot][enemies[i].ybot] = 7;
727 		map[enemies[i].xbot+1][enemies[i].ybot] = 7;
728 		map[enemies[i].xbot][enemies[i].ybot+1] = 7;
729 		map[enemies[i].xbot-1][enemies[i].ybot] = 7;
730 		map[enemies[i].xbot][enemies[i].ybot-1] = 7;
731 		map[enemies[i].xbot+1][enemies[i].ybot+1] = 7;
732 		map[enemies[i].xbot-1][enemies[i].ybot-1] = 7;
733 		map[enemies[i].xbot+1][enemies[i].ybot-1] = 7;
734 		map[enemies[i].xbot-1][enemies[i].ybot+1] = 7;
735 	}
736 	levelCount();
737 	}
738 
739 	function botMove() {
740 		for (var i = 0; i < enemies.length; i++) {
741 			gen = Math.floor(Math.random()*4);
742 			// вправо
743 		if ((gen == 0)&&(map[enemies[i].xbot+2][enemies[i].ybot]==0)&&(map[enemies[i].xbot+2][enemies[i].ybot+1]==0)&&(map[enemies[i].xbot+2][enemies[i].ybot-1]==0)) {
744 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 0;
745 					map[enemies[i].xbot-1][enemies[i].ybot] = 0;
746 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 0;
747 					enemies[i].xbot++;
748 					map[enemies[i].xbot][enemies[i].ybot] = 7;
749 					map[enemies[i].xbot+1][enemies[i].ybot] = 7;
750 					map[enemies[i].xbot][enemies[i].ybot+1] = 7;
751 					map[enemies[i].xbot-1][enemies[i].ybot] = 7;
752 					map[enemies[i].xbot][enemies[i].ybot-1] = 7;
753 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 7;
754 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 7;
755 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 7;
756 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 7;
757 					draw();
758 		} else 
759 			// влево
760 		if ((gen == 1)&&(map[enemies[i].xbot-2][enemies[i].ybot]==0)&&(map[enemies[i].xbot-2][enemies[i].ybot+1]==0)&&(map[enemies[i].xbot-2][enemies[i].ybot-1]==0)) { 
761 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 0;
762 					map[enemies[i].xbot+1][enemies[i].ybot] = 0;
763 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 0;
764 					enemies[i].xbot--;
765 					map[enemies[i].xbot][enemies[i].ybot] = 7;
766 					map[enemies[i].xbot+1][enemies[i].ybot] = 7;
767 					map[enemies[i].xbot][enemies[i].ybot+1] = 7;
768 					map[enemies[i].xbot-1][enemies[i].ybot] = 7;
769 					map[enemies[i].xbot][enemies[i].ybot-1] = 7;
770 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 7;
771 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 7;
772 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 7;
773 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 7;
774 					draw();
775 		} else
776 		    // вниз
777 		if ((gen == 2)&&(map[enemies[i].xbot][enemies[i].ybot+2]==0)&&(map[enemies[i].xbot+1][enemies[i].ybot+2]==0)&&(map[enemies[i].xbot-1][enemies[i].ybot+2]==0)) {
778 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 0;
779 					map[enemies[i].xbot][enemies[i].ybot-1] = 0;
780 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 0;
781 					enemies[i].ybot++;
782 					map[enemies[i].xbot][enemies[i].ybot] = 7;
783 					map[enemies[i].xbot+1][enemies[i].ybot] = 7;
784 					map[enemies[i].xbot][enemies[i].ybot+1] = 7;
785 					map[enemies[i].xbot-1][enemies[i].ybot] = 7;
786 					map[enemies[i].xbot][enemies[i].ybot-1] = 7;
787 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 7;
788 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 7;
789 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 7;
790 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 7;
791 					draw();
792 			}
793 			// вверх
794 			/*
795 		if ((gen == 3)&&(map[enemies[i].xbot][enemies[i].ybot-2]==0)&&(map[enemies[i].xbot+1][enemies[i].ybot-2]==0)&&(map[enemies[i].xbot-1][enemies[i].ybot-2]==0)) {
796 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 0;
797 					map[enemies[i].xbot][enemies[i].ybot+1] = 0;
798 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 0;
799 					enemies[i].ybot--;
800 					map[enemies[i].xbot][enemies[i].ybot] = 7;
801 					map[enemies[i].xbot+1][enemies[i].ybot] = 7;
802 					map[enemies[i].xbot][enemies[i].ybot+1] = 7;
803 					map[enemies[i].xbot-1][enemies[i].ybot] = 7;
804 					map[enemies[i].xbot][enemies[i].ybot-1] = 7;
805 					map[enemies[i].xbot+1][enemies[i].ybot+1] = 7;
806 					map[enemies[i].xbot-1][enemies[i].ybot-1] = 7;
807 					map[enemies[i].xbot+1][enemies[i].ybot-1] = 7;
808 					map[enemies[i].xbot-1][enemies[i].ybot+1] = 7;
809 					draw();
810 			}
811 		*/
812 		var genS = Math.floor(Math.random()*4);
813 		console.log(genS);
814 		if ((genS > 2)&&(gen == 0)) {
815 			// &&(map[enemies[i].xbot-2][enemies[i].ybot] != 3)&&(map[enemies[i].xbot][enemies[i].ybot+2] != 3)&&(map[enemies[i].xbot][enemies[i].ybot-2] != 3)) {
816 			shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy);
817 		} else
818 		if ((genS > 2)&&(gen == 1)) {
819 			shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy);
820 		} else
821 		if ((genS > 2)&&(gen == 2)) {
822 			shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy);
823 		} else
824 		if ((genS > 2)&&(gen == 3)) {
825 			shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy);
826 		}
827 	}
828 	}
829 	function killsCount() {
830 		Kills.innerHTML =++ kills;
831 	}
832 	function levelCount() {
833 		Level.innerHTML = lvl;
834 	}
835 	
836 	function gameOver() {
837 		
838 					setTimeout(() => {
839 						ctx.fillStyle = 'white';
840 						ctx.fillRect(w/4,h/4,w/2,w/2);
841 						ctx.strokeRect(w/4,h/4,w/2,w/2);
842 						ctx.fillStyle = 'black';
843 						ctx.font = "30px Arial";
844 						ctx.textAlign = "center";
845 						ctx.fillText('Вы проиграли!',w/2,h/2);
846 						ctx.font = "20px Arial";
847 						ctx.textAlign = "center";
848 						ctx.fillText('Сыграть снова! ',w/2,h/2+60);
849 						console.log('LOSE');
850 					}, 500);
851 					pause = true;
852 					clearInterval(Interval1);
853 					clearInterval(Interval2);
854 					clearInterval(Interval3);
855 					clearInterval(Interval4);
856 					clearInterval(Interval5);
857 					
858 					
859 	}
860 	
861 	canvas_example.onclick = function () {
862 		if (pause) {
863 			document.location.reload();
864 		}
865 	}
866 	
867 	var Interval1 = setInterval(botSpawn, 1000);
868 	var Interval2 = setInterval(renderPlayer, 1);
869 	var Interval3 = setInterval(fps, 1000/60);
870 	var Interval4 = setInterval(botMove, 1000/koef);
871 	var Interval5 = setInterval(reWall, 1);
872 	setInterval(kills, 1);
873 	player();
874 	
875 }