update js

master
sundowndev 2017-12-09 05:11:28 +01:00
parent b74d6cabb5
commit a38ac8a985
3 changed files with 56 additions and 34 deletions

View File

@ -151,8 +151,6 @@ body{
animation: cibleBroken 0.3s 3; animation: cibleBroken 0.3s 3;
} }
<<<<<<< Updated upstream
=======
.cible{ .cible{
background: url(../img/bg_cible.png) no-repeat; background: url(../img/bg_cible.png) no-repeat;
} }
@ -162,7 +160,6 @@ body{
animation: cibleBroken 0.3s 3; animation: cibleBroken 0.3s 3;
} }
>>>>>>> Stashed changes
@keyframes cibleBroken{ @keyframes cibleBroken{
0%{ 0%{
opacity: 1; opacity: 1;

View File

@ -3,10 +3,16 @@ var player = document.querySelector('#player');
var maxX = document.querySelectorAll('.line-1 .col').length; var maxX = document.querySelectorAll('.line-1 .col').length;
var maxY = document.querySelectorAll('.line').length; var maxY = document.querySelectorAll('.line').length;
var score = document.querySelectorAll('.textScore');
score.forEach(function(e){
e.textContent = 0;
});
var x = 1; var x = 1;
var y = 5; var y = 5;
var cibleValue = 0; var cibleValue = 0;
var score = 0; var playing = true;
var controls = { var controls = {
up: 'z', up: 'z',
@ -28,6 +34,12 @@ var bulletX = 0;
var bulletY = 0; var bulletY = 0;
var bulletDir = direction; var bulletDir = direction;
function set_score (){
score.forEach(function(e){
e.textContent = 0;
});
}
function setPosition (posX, posY, dir) { function setPosition (posX, posY, dir) {
gridX = x; gridX = x;
gridY = y; gridY = y;
@ -94,21 +106,25 @@ function tirer () {
function move(event) { function move(event) {
var k = event.key; var k = event.key;
if(k == controls.up && y > 1){ if(playing == true){
var newY = y-1; if(k == controls.up && y > 1){
setPosition(x, newY, rotation.up); var newY = y-1;
} else if (k == controls.down && y < maxY){ setPosition(x, newY, rotation.up);
var newY = y+1; } else if (k == controls.down && y < maxY){
setPosition(x, newY, rotation.down); var newY = y+1;
} else if (k == controls.left && x > 1){ setPosition(x, newY, rotation.down);
var newX = x-1; } else if (k == controls.left && x > 1){
setPosition(newX, y, rotation.left); var newX = x-1;
} else if (k == controls.right && x < maxX){ setPosition(newX, y, rotation.left);
var newX = x+1; } else if (k == controls.right && x < maxX){
setPosition(newX, y, rotation.right); var newX = x+1;
} else if (event.keyCode == 32){ setPosition(newX, y, rotation.right);
event.preventDefault(); } else if (event.keyCode == 32){
tirer(); event.preventDefault();
tirer();
}
}else{
return;
} }
} }
@ -126,8 +142,9 @@ setInterval(function(){
if(bulletDestination.classList.contains('cible')){ if(bulletDestination.classList.contains('cible')){
bulletDestination.classList.remove('cible'); bulletDestination.classList.remove('cible');
cibleValue = cibleValue - 1; cibleValue = cibleValue - 1;
score = score + 100 ; score.forEach(function(e){
console.log(score); e.textContent = Number(e.textContent)+100;
});
bulletDestination.classList.add('cible-touchee'); bulletDestination.classList.add('cible-touchee');
bulletX = 0; bulletX = 0;
bulletY = 0; bulletY = 0;
@ -173,8 +190,9 @@ setInterval(function(){
if(bulletDestination.classList.contains('cible')){ if(bulletDestination.classList.contains('cible')){
bulletDestination.classList.remove('cible'); bulletDestination.classList.remove('cible');
cibleValue = cibleValue - 1; cibleValue = cibleValue - 1;
score = score + 100 ; score.forEach(function(e){
console.log(score); e.textContent = Number(e.textContent)+100;
});
bulletDestination.classList.add('cible-touchee'); bulletDestination.classList.add('cible-touchee');
bulletX = 0; bulletX = 0;
bulletY = 0; bulletY = 0;
@ -194,11 +212,11 @@ setInterval(function(){
}, 32.12); }, 32.12);
var ntm = setInterval(function(){ var ntm = 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;
} }
@ -215,11 +233,18 @@ var ntm = setInterval(function(){
emplacement.classList.add('cible'); emplacement.classList.add('cible');
cibleValue = cibleValue + 1; cibleValue = cibleValue + 1;
if (cibleValue>=4){ if (cibleValue>=4){
// game over var gameover = document.querySelector('.gameover');
console.log("TAS PERDU"); gameover.style.display = 'block';
playing = false;
clearInterval(ntm); clearInterval(ntm);
} }
}, 1000); }, 1600);
document.addEventListener('keydown', move, false); document.addEventListener('keydown', move, false);
setPosition(x, y, direction); setPosition(x, y, direction);
var replay = document.querySelector('.replay');
replay.addEventListener('onclick', function(){
alert('test');
});

View File

@ -13,12 +13,12 @@
<section class="map"> <section class="map">
<div class="score"> <div class="score">
<h3>SCORE</h3> <h3>SCORE</h3>
<h5>999</h5> <h5><span class="textScore"></span></h5>
</div> </div>
<div class="gameover"> <div class="gameover">
<h1>GAME OVER</h1> <h1>GAME OVER</h1>
<h4>Votre score : 999</h4> <h4>Votre score : <span class="textScore"></span></h4>
<a href="#">Rejouer</a> <a href="#" class="replay">Rejouer</a>
</div> </div>
<div class="line line-1"> <div class="line line-1">
<div class="col col-1"></div> <div class="col col-1"></div>
@ -206,7 +206,7 @@
<div class="col col-7"></div> <div class="col col-7"></div>
<div class="col col-8"></div> <div class="col col-8"></div>
<div class="col col-9"></div> <div class="col col-9"></div>
<div class="col col-10 cible-touchee"></div> <div class="col col-10"></div>
<div class="col col-11"></div> <div class="col col-11"></div>
<div class="col col-12"></div> <div class="col col-12"></div>
<div class="col col-13"></div> <div class="col col-13"></div>