From 8626b33b920d5537fc31cc8a2d2e0c643cbe5353 Mon Sep 17 00:00:00 2001 From: KuhlMatthis Date: Thu, 17 Mar 2022 11:35:05 +0100 Subject: [PATCH] instance boxes et une decrementation de vision color --- index.html | 1 + js/Chemin.js | 2 +- js/Dude.js | 2 ++ js/Sale.js | 6 +++--- js/main.js | 25 ++++++++++++++++++++++--- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index d710017..ec7f848 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,7 @@ + diff --git a/js/Chemin.js b/js/Chemin.js index 07380ee..66e5e06 100644 --- a/js/Chemin.js +++ b/js/Chemin.js @@ -64,7 +64,7 @@ export default class Chemin { } copyBox(mypos){ - this.boxes[this.boxes.length+1] = this.box.clone(); + this.boxes[this.boxes.length+1] = this.box.createInstance("copyCheminbox"); this.boxes[this.boxes.length-1].position.x = mypos[0]*10; this.boxes[this.boxes.length-1].position.z = mypos[1]*10; } diff --git a/js/Dude.js b/js/Dude.js index df8a208..925da76 100644 --- a/js/Dude.js +++ b/js/Dude.js @@ -38,6 +38,8 @@ export default class Dude { this.dudeMesh.rotation.y += 0.06; this.dudeMesh.frontVector = new BABYLON.Vector3(Math.sin(this.dudeMesh.rotation.y), 0, Math.cos(this.dudeMesh.rotation.y)); } + + if(inputStates.up || inputStates.down || inputStates.left || inputStates.right){ this.animation(scene,1); }else{ diff --git a/js/Sale.js b/js/Sale.js index d62509a..e1854cc 100644 --- a/js/Sale.js +++ b/js/Sale.js @@ -42,13 +42,13 @@ export default class Sale { for(let z = 0; z < this.width; z++){ if(x==0 || x==this.length-1 || z==0 || z==this.width-1){ if(this.porte[0]<=x && x<=this.porte[2] && this.porte[1]<=z && z<=this.porte[3]){ - boxes[nb] = box1.clone(); + boxes[nb] = box1.createInstance("copySalebox"+nb); boxes[nb].position.x += x*this.taille; boxes[nb].position.z += z*this.taille; nb+=1; }else{ for(let y = 0; y < this.height; y++){ - boxes[nb] = box2.clone(); + boxes[nb] = box2.createInstance("copySalebox"+nb); boxes[nb].position.x += x*this.taille; boxes[nb].position.z += z*this.taille; boxes[nb].position.y += y*this.taille; @@ -56,7 +56,7 @@ export default class Sale { } } }else{ - boxes[nb] = box1.clone(); + boxes[nb] = box1.createInstance("copySalebox"+nb); boxes[nb].position.x += x*this.taille; boxes[nb].position.z += z*this.taille; nb+=1; diff --git a/js/main.js b/js/main.js index 9a5899d..d5e00c5 100644 --- a/js/main.js +++ b/js/main.js @@ -19,6 +19,7 @@ function startGame() { engine = new BABYLON.Engine(canvas, true); scene = createScene(); modifySettings(); + // main animation loop 60 times/s engine.runRenderLoop(() => { let picatchu = scene.getMeshByName("mypicatchu"); @@ -34,8 +35,11 @@ function createScene() { let groundMatrial = new BABYLON.StandardMaterial("mat", scene); var texture = new BABYLON.Texture("img/sole1.jpg", scene); groundMatrial.diffuseTexture = texture; - ground.material = groundMatrial; + scene.fogMode = BABYLON.Scene.FOGMODE_EXP; + scene.fogColor = new BABYLON.Color3(0, 0, 0); + scene.fogDensity = 0.01; + //var skybox = BABYLON.Mesh.CreateBox("BackgroundSkybox", 500, scene, undefined, BABYLON.Mesh.BACKSIDE); // Create and tweak the background material. @@ -232,7 +236,14 @@ function modifySettings() { inputStates.right = true; } else if ((event.key === "ArrowDown")|| (event.key === "s")|| (event.key === "S")) { inputStates.down = true; - } else if (event.key === " ") { + }else if (event.key === "f") { + inputStates.fire1 = true; + }else if (event.key === "g"){ + inputStates.fire2 = true; + }else if(event.key === "h"){ + inputStates.fight = true; + } + else if (event.key === " ") { inputStates.space = true; } }, false); @@ -247,7 +258,15 @@ function modifySettings() { inputStates.right = false; } else if ((event.key === "ArrowDown")|| (event.key === "s")|| (event.key === "S")) { inputStates.down = false; - } else if (event.key === " ") { + }else if (event.key === "f") { + inputStates.fire1 = false; + }else if (event.key === "g"){ + inputStates.fire2 = false; + }else if(event.key === "h"){ + inputStates.fight = false; + }else if (event.key === " ") { + inputStates.space = false; + }else if (event.key === " ") { inputStates.space = false; } }, false);