mirror of https://github.com/sundowndev/Detank.git
270 SEVRAN
parent
9eae7baf84
commit
06b61e58d2
|
@ -66,6 +66,8 @@ body{
|
||||||
padding-top: 150px;
|
padding-top: 150px;
|
||||||
background: rgba(155, 0, 0, 0.85);
|
background: rgba(155, 0, 0, 0.85);
|
||||||
box-shadow: inset 0px 0px 60px 0px rgba(0,0,0,0.75);
|
box-shadow: inset 0px 0px 60px 0px rgba(0,0,0,0.75);
|
||||||
|
display: none;
|
||||||
|
z-index: 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,25 +32,25 @@ var bulletDir = direction;
|
||||||
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);
|
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
|
||||||
|
|
||||||
if(grid.classList.contains('cible')){
|
if(grid.classList.contains('cible')){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var grids = document.querySelectorAll('.col');
|
var grids = document.querySelectorAll('.col');
|
||||||
|
|
||||||
grids.forEach(function(e){
|
grids.forEach(function(e){
|
||||||
e.style.background = '';
|
e.style.background = '';
|
||||||
e.style.backgroundPosition = '';
|
e.style.backgroundPosition = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
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';
|
||||||
grid.style.backgroundPosition = direction;
|
grid.style.backgroundPosition = direction;
|
||||||
|
|
||||||
x = posX;
|
x = posX;
|
||||||
y = posY;
|
y = posY;
|
||||||
}
|
}
|
||||||
|
@ -62,39 +62,39 @@ function getPosition () {
|
||||||
function tirer () {
|
function tirer () {
|
||||||
var posX = x;
|
var posX = x;
|
||||||
var posY = y;
|
var posY = y;
|
||||||
|
|
||||||
switch(direction){
|
switch(direction){
|
||||||
case rotation.up:
|
case rotation.up:
|
||||||
posY--;
|
posY--;
|
||||||
break
|
break
|
||||||
case rotation.down:
|
case rotation.down:
|
||||||
posY++;
|
posY++;
|
||||||
break
|
break
|
||||||
case rotation.left:
|
case rotation.left:
|
||||||
posX--;
|
posX--;
|
||||||
break
|
break
|
||||||
case rotation.right:
|
case rotation.right:
|
||||||
posX++;
|
posX++;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if(posX < 1 || posX > maxX || posY < 1 || posY > maxY){
|
if(posX < 1 || posX > maxX || posY < 1 || posY > maxY){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bulletX = posX;
|
bulletX = posX;
|
||||||
bulletY = posY;
|
bulletY = posY;
|
||||||
bulletDir = direction;
|
bulletDir = direction;
|
||||||
|
|
||||||
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
|
var grid = document.querySelector('.line-'+posY+' .col-'+posX);
|
||||||
|
|
||||||
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
|
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
|
||||||
grid.style.backgroundPosition = bulletDir;
|
grid.style.backgroundPosition = bulletDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function move(event) {
|
function move(event) {
|
||||||
var k = event.key;
|
var k = event.key;
|
||||||
|
|
||||||
if(k == controls.up && y > 1){
|
if(k == controls.up && y > 1){
|
||||||
var newY = y-1;
|
var newY = y-1;
|
||||||
setPosition(x, newY, rotation.up);
|
setPosition(x, newY, rotation.up);
|
||||||
|
@ -113,18 +113,17 @@ function move(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
console.log('test');
|
console.log('test');
|
||||||
if(bulletX == 0 || bulletY == 0){
|
if(bulletX == 0 || bulletY == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newY = bulletY;
|
var newY = bulletY;
|
||||||
var newX = bulletX;
|
var newX = bulletX;
|
||||||
|
|
||||||
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')){
|
||||||
bulletDestination.classList.remove('cible');
|
bulletDestination.classList.remove('cible');
|
||||||
cibleValue = cibleValue - 1;
|
cibleValue = cibleValue - 1;
|
||||||
|
@ -138,7 +137,7 @@ setInterval(function(){
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(bulletDir){
|
switch(bulletDir){
|
||||||
case rotation.up:
|
case rotation.up:
|
||||||
newY--;
|
newY--;
|
||||||
|
@ -153,23 +152,23 @@ setInterval(function(){
|
||||||
newX++;
|
newX++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(newY < 1 || newY > maxY || newX < 1 || newX > maxX){
|
if(newY < 1 || newY > maxY || newX < 1 || newX > maxX){
|
||||||
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
||||||
|
|
||||||
grid.style.background = '';
|
grid.style.background = '';
|
||||||
grid.style.backgroundPosition = '';
|
grid.style.backgroundPosition = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
||||||
|
|
||||||
grid.style.background = '';
|
grid.style.background = '';
|
||||||
grid.style.backgroundPosition = '';
|
grid.style.backgroundPosition = '';
|
||||||
|
|
||||||
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')){
|
||||||
bulletDestination.classList.remove('cible');
|
bulletDestination.classList.remove('cible');
|
||||||
cibleValue = cibleValue - 1;
|
cibleValue = cibleValue - 1;
|
||||||
|
@ -183,18 +182,15 @@ setInterval(function(){
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bulletX = newX;
|
bulletX = newX;
|
||||||
bulletY = newY;
|
bulletY = newY;
|
||||||
|
|
||||||
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
var grid = document.querySelector('.line-'+bulletY+' .col-'+bulletX);
|
||||||
|
|
||||||
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
|
grid.style.background = 'url(./assets/img/bg_bullet.png) no-repeat';
|
||||||
grid.style.backgroundPosition = bulletDir;
|
grid.style.backgroundPosition = bulletDir;
|
||||||
}, 32.12);
|
}, 32.12);
|
||||||
=======
|
|
||||||
document.addEventListener('keydown', move, false);
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|
||||||
var ntm = setInterval(function(){
|
var ntm = setInterval(function(){
|
||||||
x2 = Math.floor(Math.random() * 11);
|
x2 = Math.floor(Math.random() * 11);
|
||||||
|
@ -205,28 +201,23 @@ var ntm = setInterval(function(){
|
||||||
if (y2 == y){
|
if (y2 == y){
|
||||||
y2 = y+1;
|
y2 = y+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ciblex < maxX && cibley < maxY){
|
if(ciblex < maxX && cibley < maxY){
|
||||||
console.log(ciblex+' pour '+maxX);
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
var ciblex = x2,
|
var ciblex = x2,
|
||||||
cibley = y2,
|
cibley = y2,
|
||||||
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;
|
cibleValue = cibleValue + 1;
|
||||||
if (cibleValue>=3){
|
if (cibleValue>=3){
|
||||||
alert("TAS PERDU");
|
alert("TAS PERDU");
|
||||||
clearInterval(ntm);
|
clearInterval(ntm);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
document.addEventListener('keydown', move, false);
|
document.addEventListener('keydown', move, false);
|
||||||
setPosition(x, y, direction);
|
setPosition(x, y, direction);
|
||||||
=======
|
|
||||||
|
|
||||||
|
|
||||||
}, 3000);
|
|
||||||
>>>>>>> Stashed changes
|
|
Loading…
Reference in New Issue