Tank 1990
Описание
Игра конца 20 века Battle City, известная как Tank 1990, созданная на языке JavaScript. В программе предусмотрено управление танком при нажатии на клавиши клавиатуры "WASD" и "Пробел", противники и усложнение игры с каждым уровнем.
Автор: Галеев Рауль Рустемович, группа №3630103/90003
Игра
Код программы
HTML
<!DOCTYPE html> <html> <head> <title>ALPHA</title> <script src='alpha1.js'></script> </head> <body>
<canvas id="canvas_example" width=500 height=500 style='border: 1px solid #000000;'></canvas> | </br>Добро пожаловать. Кнопки управления: WASD. Нажмите "Пробел" чтобы выстрелить.
</br> Не дайте врагу убить Вас и Вашу зелёную базу! </br></br>Очки: </br>Уровень: |
</body> </html>
JavaScript
window.addEventListener('load', main, false); function main() { function fps() { for (var i = 0; i < bullets.length; i++) { map[bullets[i].x][bullets[i].y] = 0; if (bullets[i].dir == UP) { bullets[i].y = bullets[i].y; if (map[bullets[i].x][bullets[i].y-1] == 0) { bullets[i].y -= 1; } else if (map[bullets[i].x][bullets[i].y-1] == 2) { map[bullets[i].x][bullets[i].y-1] = 0; bullets.splice(i, 1); // continue; } else if ((map[bullets[i].x][bullets[i].y-1] == 7)&&(bullets[i].tag == me)) { map[bullets[i].x][bullets[i].y-1] = 0; for (var j = 0; j < enemies.length; j++) { 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])) { console.log(11111); bullets.splice(i, 1);
map[enemies[j].xbot][enemies[j].ybot] = 0; map[enemies[j].xbot+1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot-1] = 0; map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
enemies.splice(j, 1);
killsCount(); draw(); } } } else 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)) { map[bullets[i].x][bullets[i].y-1] = 0; map[x][y] = 0; map[x+1][y] = 0; map[x][y+1] = 0; map[x-1][y] = 0; map[x][y-1] = 0; map[x+1][y+1] = 0; map[x-1][y-1] = 0; map[x+1][y-1] = 0; map[x-1][y+1] = 0; draw();
gameOver(); break;
} else { bullets.splice(i, 1); continue; } } else
if (bullets[i].dir == DOWN) { bullets[i].y = bullets[i].y; if (map[bullets[i].x][bullets[i].y+1] == 0) { bullets[i].y += 1; } else if (map[bullets[i].x][bullets[i].y+1] == 2) { map[bullets[i].x][bullets[i].y+1] = 0; bullets.splice(i, 1); // continue; } else if ((map[bullets[i].x][bullets[i].y+1] == 7)&&(bullets[i].tag == me)) { map[bullets[i].x][bullets[i].y+1] = 0; for (var j = 0; j < enemies.length; j++) { 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])) { console.log(11111); bullets.splice(i, 1);
map[enemies[j].xbot][enemies[j].ybot] = 0; map[enemies[j].xbot+1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot-1] = 0; map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
enemies.splice(j, 1);
killsCount(); draw(); } } } else 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)) { map[bullets[i].x][bullets[i].y-1] = 0; map[x][y] = 0; map[x+1][y] = 0; map[x][y+1] = 0; map[x-1][y] = 0; map[x][y-1] = 0; map[x+1][y+1] = 0; map[x-1][y-1] = 0; map[x+1][y-1] = 0; map[x-1][y+1] = 0; draw();
gameOver(); break; }
else { bullets.splice(i, 1); continue; } } else
if (bullets[i].dir == RIGHT) { bullets[i].x = bullets[i].x; if (map[bullets[i].x+1][bullets[i].y] == 0) { bullets[i].x += 1; } else if (map[bullets[i].x+1][bullets[i].y] == 2) { map[bullets[i].x+1][bullets[i].y] = 0; bullets.splice(i, 1); // continue; } else if ((map[bullets[i].x+1][bullets[i].y] == 7)&&(bullets[i].tag == me)) { map[bullets[i].x+1][bullets[i].y] = 0; for (var j = 0; j < enemies.length; j++) { 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])) { console.log(11111); bullets.splice(i, 1);
map[enemies[j].xbot][enemies[j].ybot] = 0; map[enemies[j].xbot+1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot-1] = 0; map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
enemies.splice(j, 1);
killsCount(); draw(); } } } else 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)) { map[bullets[i].x][bullets[i].y-1] = 0; map[x][y] = 0; map[x+1][y] = 0; map[x][y+1] = 0; map[x-1][y] = 0; map[x][y-1] = 0; map[x+1][y+1] = 0; map[x-1][y-1] = 0; map[x+1][y-1] = 0; map[x-1][y+1] = 0; draw();
gameOver(); break;
} else { bullets.splice(i, 1); continue; } } else if (bullets[i].dir == LEFT) { bullets[i].x = bullets[i].x; if (map[bullets[i].x-1][bullets[i].y] == 0) { bullets[i].x -= 1; } else if (map[bullets[i].x-1][bullets[i].y] == 2) { map[bullets[i].x-1][bullets[i].y] = 0; bullets.splice(i, 1); // continue; } else if ((map[bullets[i].x-1][bullets[i].y] == 7)&&(bullets[i].tag == me)) { map[bullets[i].x-1][bullets[i].y] = 0; for (var j = 0; j < enemies.length; j++) { 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])) { console.log(11111); bullets.splice(i, 1);
map[enemies[j].xbot][enemies[j].ybot] = 0; map[enemies[j].xbot+1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot] = 0; map[enemies[j].xbot][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot+1] = 0; map[enemies[j].xbot-1][enemies[j].ybot-1] = 0; map[enemies[j].xbot+1][enemies[j].ybot-1] = 0; map[enemies[j].xbot-1][enemies[j].ybot+1] = 0;
enemies.splice(j, 1);
killsCount(); draw(); } } } else 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)) { map[bullets[i].x][bullets[i].y-1] = 0; map[x][y] = 0; map[x+1][y] = 0; map[x][y+1] = 0; map[x-1][y] = 0; map[x][y-1] = 0; map[x+1][y+1] = 0; map[x-1][y-1] = 0; map[x+1][y-1] = 0; map[x-1][y+1] = 0;
gameOver(); break;
} else { bullets.splice(i, 1); continue; } } map[bullets[i].x][bullets[i].y] = 4; } draw();
} var ctx = canvas_example.getContext('2d'); var w = canvas_example.width; var h = canvas_example.height;
var N = 50;
/* function pause(ms) { return new Promise(resolve => setTimeout(resolve, ms)); // для паузы в последствии писать await pause(1000); } */ var map = []; for (var i=0; i<N; i++) { var a = []; for (var j=0; j<N; j++) { a.push(0); } map.push(a); }
var kills = 0; var x = 18; var y = 45;
var me = 0; var enemy = 1;
var UP = 0; var RIGHT = 1; var DOWN = 3; var LEFT = 2;
var pause = false;
var koef = 5;
var a = 0; var b = 1; var c = 0;
var bullets = [];
let timer;
map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x-1][y] = 1; map[x][y-1] = 6; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1;
// СТЕНЫ // СТЕНА БАЗЫ for (var i=20; i<23; i++) { for (var j=41; j<47; j++) { map[i][j] = 2; } } for (var i=26; i<29; i++) { for (var j=41; j<47; j++) { map[i][j] = 2; } } for (var i=20; i<29; i++) { for (var j=41; j<44; j++) { map[i][j] = 2; } } // База for (var i=23; i<26; i++) { for (var j=44; j<47; j++) { map[i][j] = 5; } } // ГРАНИЦЫ-СТЕНЫ function reWall() { for (var i=0; i<50; i++) { for (var j=0; j<3; j++) { map[i][j] = 3; } } for (var i=0; i<3; i++) { for (var j=0; j<50; j++) { map[i][j] = 3; } } for (var i=47; i<50; i++) { for (var j=0; j<50; j++) { map[i][j] = 3; } } for (var i=0; i<50; i++) { for (var j=47; j<50; j++) { map[i][j] = 3; } } // Жёсткие стены for (var i=23; i<26; i++) { for (var j=3; j<6; j++) { map[i][j] = 3; } }
for (var i=44; i<47; i++) { for (var j=23; j<26; j++) { map[i][j] = 3; } }
for (var i=3; i<6; i++) { for (var j=23; j<26; j++) { map[i][j] = 3; } } draw(); } // innocent стены // Разрушающиеся стены for (var i=12; i<20; i++) { for (var j=6; j<9; j++) { map[i][j] = 2; } }
for (var i=15; i<18; i++) { for (var j=12; j<15; j++) { map[i][j] = 3; } }
for (var i=31; i<34; i++) { for (var j=12; j<15; j++) { map[i][j] = 3; } }
for (var i=12; i<20; i++) { for (var j=15; j<18; j++) { map[i][j] = 2; } }
for (var i=20; i<29; i++) { for (var j=24; j<27; j++) { map[i][j] = 2; } }
for (var i=29; i<38; i++) { for (var j=6; j<9; j++) { map[i][j] = 2; } }
for (var i=29; i<38; i++) { for (var j=15; j<18; j++) { map[i][j] = 2; } }
for (var i=6; i<9; i++) { for (var j=6; j<18; j++) { map[i][j] = 2; } }
for (var i=6; i<20; i++) { for (var j=30; j<33; j++) { map[i][j] = 2; } }
for (var i=29; i<44; i++) { for (var j=30; j<33; j++) { map[i][j] = 2; } }
for (var i=41; i<44; i++) { for (var j=30; j<39; j++) { map[i][j] = 2; } }
for (var i=6; i<9; i++) { for (var j=30; j<39; j++) { map[i][j] = 2; } }
for (var i=41; i<44; i++) { for (var j=6; j<18; j++) { map[i][j] = 2; } }
for (var i=23; i<26; i++) { for (var j=6; j<26; j++) { map[i][j] = 2; } }
draw();
function draw() { for (var i=0; i<N; i++) { for (var j=0; j<N; j++) { if (map[i][j]==0) { ctx.fillStyle='white'; } else
if (map[i][j]==1) { ctx.fillStyle='red'; } else
if (map[i][j]==2) { ctx.fillStyle='brown'; } else if (map[i][j]==3) { ctx.fillStyle='grey'; } else if (map[i][j]==4) { ctx.fillStyle='black'; } else if (map[i][j]==5) { ctx.fillStyle='green'; } else if (map[i][j]==7) { ctx.fillStyle='blue'; } else if (map[i][j]==8) { ctx.fillStyle='purple'; } else if (map[i][j]==6) { ctx.fillStyle='orange'; } /* else { ctx.fillStyle='red'; } */
ctx.fillRect(i*w/N, j*h/N, N, N); } } }
function shootUp(x,y,dir,tag) {
if (dir == UP) { bullets.push({ x: x, y: y-2, dir: dir, tag: tag}); } else if (dir == DOWN) { bullets.push({ x: x, y: y+2, dir: dir, tag: tag}); } else if (dir == RIGHT) { bullets.push({ x: x+2, y: y, dir: dir, tag: tag}); } else if (dir == LEFT) { bullets.push({ x: x-2, y: y, dir: dir, tag: tag}); } else { bullets.splice(i, 1); } } // Управление function player() { document.onkeypress = function (event) { if (pause) return; let key = event.keyCode || event.charCodel; if ((event.key == 'd')||(event.key == 'в')||(event.key == 'D')||(event.key == 'В')){ map[x-1][y] = 1; map[x+1][y] = 6; map[x][y+1] = 1; map[x][y-1] = 1; draw(); if ((map[x+2][y]==0)&&(map[x+2][y+1]==0)&&(map[x+2][y-1]==0)) { map[x-1][y-1] = 0; map[x-1][y] = 0; map[x-1][y+1] = 0; x++; map[x][y] = 1; map[x+1][y] = 6; map[x][y+1] = 1; map[x-1][y] = 1; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } b = 1; } else if ((event.key == 'a')||(event.key == 'ф')||(event.key == 'A')||(event.key == 'Ф')){ map[x-1][y] = 6; map[x+1][y] = 1; map[x][y+1] = 1; map[x][y-1] = 1; draw(); if ((map[x-2][y]==0)&&(map[x-2][y+1]==0)&&(map[x-2][y-1]==0)) { map[x+1][y-1] = 0; map[x+1][y] = 0; map[x+1][y+1] = 0; x--; map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x-1][y] = 6; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } b = 2; } else if ((event.key == 's')||(event.key == 'ы')||(event.key == 'S')||(event.key == 'Ы')){ map[x-1][y] = 1; map[x+1][y] = 1; map[x][y+1] = 6; map[x][y-1] = 1; draw(); if ((map[x][y+2]==0)&&(map[x+1][y+2]==0)&&(map[x-1][y+2]==0)) { map[x+1][y-1] = 0; map[x][y-1] = 0; map[x-1][y-1] = 0; y++; map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 6; map[x-1][y] = 1; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1;
draw(); } b = 3; } else if ((event.key == 'w')||(event.key == 'ц')||(event.key == 'W')||(event.key == 'Ц')){ map[x-1][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x][y-1] = 6; draw(); if ((map[x][y-2]==0)&&(map[x+1][y-2]==0)&&(map[x-1][y-2]==0)) { map[x+1][y+1] = 0; map[x][y+1] = 0; map[x-1][y+1] = 0; y--; map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x-1][y] = 1; map[x][y-1] = 6; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } b = 4; } else if (!timer && event.key == ' ') { if ((map[x][y-1] == 6)&&(map[x][y-2] != 3)) { // map[x][y-2] = 4; //a = 1; shootUp(x,y,UP,me);
} if ((map[x][y+1] == 6)&&(map[x][y+2] != 3)) { //a = 2; shootUp(x,y,DOWN, me); } if ((map[x+1][y] == 6)&&(map[x+2][y] != 3)) { //a = 3; shootUp(x,y,RIGHT,me); } if ((map[x-1][y] == 6)&&(map[x-2][y] != 3)) { //a = 4; shootUp(x,y,LEFT,me); } timer = setTimeout(() => timer = clearTimeout(timer), 150); } } }
function renderPlayer() { if (b == 1) { map[x][y] = 1; map[x+1][y] = 6; map[x][y+1] = 1; map[x-1][y] = 1; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } else if (b == 2) { map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x-1][y] = 6; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } else if (b == 3) { map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 6; map[x-1][y] = 1; map[x][y-1] = 1; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } else if (b == 4) { map[x][y] = 1; map[x+1][y] = 1; map[x][y+1] = 1; map[x-1][y] = 1; map[x][y-1] = 6; map[x+1][y+1] = 1; map[x-1][y-1] = 1; map[x+1][y-1] = 1; map[x-1][y+1] = 1; draw(); } }
// БОТЯРА
var enemies = []; var xbot; var ybot; var j = 1; var gen = 0; var lvl = 0;
function botSpawn() { if (enemies == 0) { lvl = lvl + 1; enemies.push({ xbot: 21, ybot: 10 }); enemies.push({ xbot: 27, ybot: 10 }); if (lvl == 2) { enemies.push({ xbot: 44, ybot: 4 }); enemies.push({ xbot: 4, ybot: 4 }); } if (lvl == 3) { enemies.push({ xbot: 44, ybot: 4 }); enemies.push({ xbot: 4, ybot: 4 }); enemies.push({ xbot: 7, ybot: 24 }); } if (lvl == 4) { enemies.push({ xbot: 44, ybot: 4 }); enemies.push({ xbot: 4, ybot: 4 }); enemies.push({ xbot: 7, ybot: 24 }); enemies.push({ xbot: 42, ybot: 24 }); } koef = koef + 5; }
for (var i = 0; i < enemies.length; i++) { map[enemies[i].xbot][enemies[i].ybot] = 7; map[enemies[i].xbot+1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot-1] = 7; map[enemies[i].xbot-1][enemies[i].ybot+1] = 7; } levelCount(); }
function botMove() { for (var i = 0; i < enemies.length; i++) { gen = Math.floor(Math.random()*4); // вправо 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)) { map[enemies[i].xbot-1][enemies[i].ybot-1] = 0; map[enemies[i].xbot-1][enemies[i].ybot] = 0; map[enemies[i].xbot-1][enemies[i].ybot+1] = 0; enemies[i].xbot++; map[enemies[i].xbot][enemies[i].ybot] = 7; map[enemies[i].xbot+1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot-1] = 7; map[enemies[i].xbot-1][enemies[i].ybot+1] = 7; draw(); } else // влево 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)) { map[enemies[i].xbot+1][enemies[i].ybot-1] = 0; map[enemies[i].xbot+1][enemies[i].ybot] = 0; map[enemies[i].xbot+1][enemies[i].ybot+1] = 0; enemies[i].xbot--; map[enemies[i].xbot][enemies[i].ybot] = 7; map[enemies[i].xbot+1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot-1] = 7; map[enemies[i].xbot-1][enemies[i].ybot+1] = 7; draw(); } else // вниз 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)) { map[enemies[i].xbot+1][enemies[i].ybot-1] = 0; map[enemies[i].xbot][enemies[i].ybot-1] = 0; map[enemies[i].xbot-1][enemies[i].ybot-1] = 0; enemies[i].ybot++; map[enemies[i].xbot][enemies[i].ybot] = 7; map[enemies[i].xbot+1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot-1] = 7; map[enemies[i].xbot-1][enemies[i].ybot+1] = 7; draw(); } // вверх /* 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)) { map[enemies[i].xbot+1][enemies[i].ybot+1] = 0; map[enemies[i].xbot][enemies[i].ybot+1] = 0; map[enemies[i].xbot-1][enemies[i].ybot+1] = 0; enemies[i].ybot--; map[enemies[i].xbot][enemies[i].ybot] = 7; map[enemies[i].xbot+1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot] = 7; map[enemies[i].xbot][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot+1] = 7; map[enemies[i].xbot-1][enemies[i].ybot-1] = 7; map[enemies[i].xbot+1][enemies[i].ybot-1] = 7; map[enemies[i].xbot-1][enemies[i].ybot+1] = 7; draw(); } */ var genS = Math.floor(Math.random()*4); console.log(genS); if ((genS > 2)&&(gen == 0)) { // &&(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)) { shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy); } else if ((genS > 2)&&(gen == 1)) { shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy); } else if ((genS > 2)&&(gen == 2)) { shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy); } else if ((genS > 2)&&(gen == 3)) { shootUp(enemies[i].xbot,enemies[i].ybot,gen,enemy); } } } function killsCount() { Kills.innerHTML =++ kills; } function levelCount() { Level.innerHTML = lvl; }
function gameOver() {
setTimeout(() => { ctx.fillStyle = 'white'; ctx.fillRect(w/4,h/4,w/2,w/2); ctx.strokeRect(w/4,h/4,w/2,w/2); ctx.fillStyle = 'black'; ctx.font = "30px Arial"; ctx.textAlign = "center"; ctx.fillText('Вы проиграли!',w/2,h/2); ctx.font = "20px Arial"; ctx.textAlign = "center"; ctx.fillText('Сыграть снова! ',w/2,h/2+60); console.log('LOSE'); }, 500); pause = true; clearInterval(Interval1); clearInterval(Interval2); clearInterval(Interval3); clearInterval(Interval4); clearInterval(Interval5);
}
canvas_example.onclick = function () { if (pause) { document.location.reload(); } }
var Interval1 = setInterval(botSpawn, 1000); var Interval2 = setInterval(renderPlayer, 1); var Interval3 = setInterval(fps, 1000/60); var Interval4 = setInterval(botMove, 1000/koef); var Interval5 = setInterval(reWall, 1); setInterval(kills, 1); player();
}