diff --git a/build/Jeu.js b/build/Jeu.js index 0779a36..8c54a12 100644 --- a/build/Jeu.js +++ b/build/Jeu.js @@ -11,19 +11,40 @@ class Jeu extends Scene { this.compteurMonnaie = 0; } start() { + this.start_ = new Start(document.getElementById("starting"), this); + } + partieCommencer() { + this.creerJoueur(); + this.afficherRegles(); + this.afficherShop(); + this.creerObject(); + } + creerJoueur() { this.joueur_ = new Joueur(document.createElement("img"), this); this.joueur_.setImage("img/joe.png", 60, 80); this.joueur_.setX(this.zoneDeJeu_.getWidth() / 2 - this.joueur_.getWidth() / 2); this.joueur_.setY(this.zoneDeJeu_.getHeight() / 2 - this.joueur_.getHeight() / 2); this.appendChild(this.joueur_); this.joueur_.animer(); + } + afficherRegles() { this.regles_ = new Regles(document.getElementById("regles"), this); + } + afficherShop() { this.shop_ = new Shop(document.getElementById("Shop"), this); + } + creerObject() { this.objet_ = new Objet(document.createElement("img"), this); - setInterval(() => { this.objet_.creerFruit(); }, 3000); - setInterval(() => { this.objet_.creerPoison(); }, 3000); - setInterval(() => { this.objet_.creerPlante(); }, 3000); - setInterval(() => { this.joueur_.collisionObjet(); }, 1000 / 144); + this.intervalFruit = setInterval(() => { this.objet_.creerFruit(); }, 3000); + this.intervalPoison = setInterval(() => { this.objet_.creerPoison(); }, 3000); + this.intervalPlante = setInterval(() => { this.objet_.creerPlante(); }, 3000); + this.intervalCollision = setInterval(() => { this.joueur_.collisionObjet(); }, 1000 / 144); + } + figerObjet() { + clearInterval(this.intervalFruit); + clearInterval(this.intervalPoison); + clearInterval(this.intervalPlante); + clearInterval(this.intervalCollision); } augmenterScore() { this.compteurScore += 100; diff --git a/build/Joueur.js b/build/Joueur.js index 2035436..5b29e80 100644 --- a/build/Joueur.js +++ b/build/Joueur.js @@ -24,6 +24,7 @@ class Joueur extends Sprite { } if (this.scene_.objet_.listeObjets_[i] == this.scene_.objet_.recupPoison_) { console.log("tu as touché du poison"); + this.scene_.reduireScore(); this.popUpPoison(); this.imagePopUpPoison(); this.scene_.objet_.listeObjets_[i].setXY(-10000, -10000); diff --git a/build/Objet.js b/build/Objet.js index f185b78..783db52 100644 --- a/build/Objet.js +++ b/build/Objet.js @@ -19,8 +19,8 @@ class Objet extends Sprite { 'img/objet/plantes/origan.png', ]; this.scene_ = scene; - this.limitesX = 500; - this.limitesY = 500; + this.limitesX = 100; + this.limitesY = 100; this.listeObjets_ = []; this.widthX = this.scene_.getWidth() - this.limitesX; this.heightY = this.scene_.getHeight() - this.limitesY; diff --git a/build/Regles.js b/build/Regles.js index 7bf9ed6..a0c93bf 100644 --- a/build/Regles.js +++ b/build/Regles.js @@ -37,6 +37,7 @@ class Regles extends Sprite { } cacher() { if (this.reglesDiv_) { + this.scene_.creerObject(); this.fermetureMenu_.play(); this.reglesDiv_.hide(); this.menu_.style.display = 'block'; @@ -44,6 +45,7 @@ class Regles extends Sprite { } montrer() { if (this.menu_) { + this.scene_.figerObjet(); this.ouvertureMenu_.play(); this.musiqueDeFond.play(); this.reglesDiv_.show(); diff --git a/build/Shop.js b/build/Shop.js index 6f7d4fd..f694a1b 100644 --- a/build/Shop.js +++ b/build/Shop.js @@ -22,6 +22,7 @@ class Shop extends Sprite { } cacher() { if (this.shopDiv_) { + this.scene_.creerObject(); this.fermetureMenu_.play(); this.shopDiv_.hide(); this.menu_.style.display = 'block'; @@ -29,6 +30,7 @@ class Shop extends Sprite { } montrer() { if (this.menu_) { + this.scene_.figerObjet(); this.ouvertureMenu_.play(); this.shopDiv_.show(); this.menu_.style.display = 'none'; diff --git a/build/Start.js b/build/Start.js new file mode 100644 index 0000000..186091d --- /dev/null +++ b/build/Start.js @@ -0,0 +1,21 @@ +"use strict"; +class Start extends Sprite { + constructor(element, scene) { + super(element); + this.scene_ = scene; + this.StartDiv_ = new Sprite(document.getElementById('starting')); + this.bouton_ = new Sprite(document.getElementById('demarrer')); + this.son = document.getElementById('son'); + this.sonOui = document.getElementById('sonOui'); + this.musiqueDeFond = document.getElementById('musiqueFond'); + this.setX(document.documentElement.clientWidth / 2 - this.getWidth() / 2); + this.setY(document.documentElement.clientHeight / 2 - this.getHeight() / 2); + this.bouton_.addEventListener('click', this.demarrerPartie.bind(this)); + this.musiqueDeFond.play(); + } + demarrerPartie() { + this.StartDiv_.hide(); + this.scene_.partieCommencer(); + this.musiqueDeFond.play(); + } +} diff --git a/build/index.htm b/build/index.htm index a25fbd3..7064b82 100644 --- a/build/index.htm +++ b/build/index.htm @@ -4,12 +4,21 @@ Template Jeu + + + + + + + + +