update js

master
sundowndev 2017-12-09 04:03:42 +01:00
parent d519778c7a
commit 3d1f5facc6
1 changed files with 25 additions and 6 deletions

View File

@ -27,10 +27,19 @@ var bulletX = 0;
var bulletY = 0; var bulletY = 0;
var bulletDir = direction; var bulletDir = direction;
var cibleValue = 0;
function setPosition (posX, posY, dir) { function setPosition (posX, posY, dir) {
gridX = x; gridX = x;
gridY = y; gridY = y;
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
if(grid.classList.contains('cible')){
return;
}
var grids = document.querySelectorAll('.col'); var grids = document.querySelectorAll('.col');
grids.forEach(function(e){ grids.forEach(function(e){
@ -38,8 +47,6 @@ function setPosition (posX, posY, dir) {
e.style.backgroundPosition = ''; e.style.backgroundPosition = '';
}); });
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
direction = dir; direction = dir;
grid.style.background = 'url(./assets/img/tank_bg.png) no-repeat'; grid.style.background = 'url(./assets/img/tank_bg.png) no-repeat';
@ -148,6 +155,7 @@ setInterval(function(){
var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX); var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX);
if(bulletDestination.classList.contains('cible')){ if(bulletDestination.classList.contains('cible')){
cibleValue -= 1;
bulletDestination.classList.remove('cible'); bulletDestination.classList.remove('cible');
bulletDestination.classList.add('cible-touchee'); bulletDestination.classList.add('cible-touchee');
bulletX = 0; bulletX = 0;
@ -168,18 +176,29 @@ setInterval(function(){
}, 32.12); }, 32.12);
setInterval(function(){ setInterval(function(){
x2 = Math.floor(Math.random() * 11); x2 = Math.floor(Math.random() * 10) + 1;
if (x2 == x){ if (x2 == x){
x2 = x+1; x2 = x+1;
} }
y2 = Math.floor(Math.random() * 21); y2 = Math.floor(Math.random() * 20) + 1;
if (y2 == y){ if (y2 == y){
y2 = y+1; y2 = y+1;
} }
var ciblex = x2, var ciblex = x2,
cibley = y2, cibley = y2
if(ciblex < maxX && cibley < maxY){
console.log(ciblex+' pour '+maxX);
emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley); emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley);
emplacement.classList.add('cible'); emplacement.classList.add('cible');
}
cibleValue = cibleValue + 1;
if (cibleValue>=3){
console.log("TAS PERDU");
// TODO
}
}, 3000); }, 3000);
document.addEventListener('keydown', move, false); document.addEventListener('keydown', move, false);