update js

master
sundowndev 2017-12-09 04:30:04 +01:00
commit 46ef071b34
2 changed files with 36 additions and 42 deletions

View File

@ -66,6 +66,8 @@ body{
padding-top: 150px;
background: rgba(155, 0, 0, 0.85);
box-shadow: inset 0px 0px 60px 0px rgba(0,0,0,0.75);
display: none;
z-index: 4;
}

View File

@ -31,25 +31,25 @@ var bulletDir = direction;
function setPosition (posX, posY, dir) {
gridX = x;
gridY = y;
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
if(grid.classList.contains('cible')){
return;
}
var grids = document.querySelectorAll('.col');
grids.forEach(function(e){
e.style.background = '';
e.style.backgroundPosition = '';
});
direction = dir;
grid.style.background = 'url(./assets/img/tank_bg.png) no-repeat';
grid.style.backgroundPosition = direction;
x = posX;
y = posY;
}
@ -61,39 +61,39 @@ function getPosition () {
function tirer () {
var posX = x;
var posY = y;
switch(direction){
case rotation.up:
posY--;
break
case rotation.down:
case rotation.down:
posY++;
break
case rotation.left:
case rotation.left:
posX--;
break
case rotation.right:
case rotation.right:
posX++;
break
}
if(posX < 1 || posX > maxX || posY < 1 || posY > maxY){
return;
}
bulletX = posX;
bulletY = posY;
bulletDir = direction;
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
grid.style.backgroundPosition = bulletDir;
}
function move(event) {
var k = event.key;
if(k == controls.up && y > 1){
var newY = y-1;
setPosition(x, newY, rotation.up);
@ -112,18 +112,17 @@ function move(event) {
}
}
<<<<<<< Updated upstream
setInterval(function(){
console.log('test');
if(bulletX == 0 || bulletY == 0){
return;
}
var newY = bulletY;
var newX = bulletX;
var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX);
if(bulletDestination.classList.contains('cible')){
bulletDestination.classList.remove('cible');
cibleValue = cibleValue - 1;
@ -139,7 +138,7 @@ setInterval(function(){
}, 1000);
return;
}
switch(bulletDir){
case rotation.up:
newY--;
@ -154,23 +153,23 @@ setInterval(function(){
newX++;
break;
}
if(newY < 1 || newY > maxY || newX < 1 || newX > maxX){
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
grid.style.background = '';
grid.style.backgroundPosition = '';
return;
}
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
grid.style.background = '';
grid.style.backgroundPosition = '';
var bulletDestination = document.querySelector('.line-'+newY+' .col-'+newX);
if(bulletDestination.classList.contains('cible')){
bulletDestination.classList.remove('cible');
cibleValue = cibleValue - 1;
@ -184,18 +183,15 @@ setInterval(function(){
}, 1000);
return;
}
bulletX = newX;
bulletY = newY;
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
grid.style.backgroundPosition = bulletDir;
}, 32.12);
=======
document.addEventListener('keydown', move, false);
>>>>>>> Stashed changes
var ntm = setInterval(function(){
x2 = Math.floor(Math.random() * 11);
@ -206,18 +202,19 @@ var ntm = setInterval(function(){
if (y2 == y){
y2 = y+1;
}
if(ciblex < maxX && cibley < maxY){
console.log(ciblex+' pour '+maxX);
emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley);
emplacement.classList.add('cible');
}
var ciblex = x2,
cibley = y2,
emplacement = document.querySelector(".line-"+ciblex+" .col-"+cibley);
emplacement.classList.add('cible');
cibleValue = cibleValue + 1;
<<<<<<< HEAD
if (cibleValue>=4){
// game over
console.log("TAS PERDU");
@ -226,9 +223,4 @@ var ntm = setInterval(function(){
}, 1000);
document.addEventListener('keydown', move, false);
setPosition(x, y, direction);
=======
}, 3000);
>>>>>>> Stashed changes
setPosition(x, y, direction);