clear du code #6
					 7 changed files with 39 additions and 55 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| function getCookie(name) {//Code from OpenClassroom
 | function getCookie(name) { | ||||||
|     nom = name + "="; |     nom = name + "="; | ||||||
|     var liste = document.cookie.split (';'); |     var liste = document.cookie.split (';'); | ||||||
|     for (var i = 0; i < liste.length; i++) { |     for (var i = 0; i < liste.length; i++) { | ||||||
|  |  | ||||||
|  | @ -175,15 +175,15 @@ let lastbulletdonjon=[0,0] | ||||||
| function Donjon() { | function Donjon() { | ||||||
|     if(player.z==10) { |     if(player.z==10) { | ||||||
|         if(lastbulletdonjon[1]>=7) { |         if(lastbulletdonjon[1]>=7) { | ||||||
|             lastbulletdonjon[1]=0 |             lastbulletdonjon[1]=0; | ||||||
|             bullets.push(new Bullet(107,95+(Date.now()*0.1)%365,10,1,0,-2, true)); |             bullets.push(new Bullet(107,95+(Date.now()*0.1)%365,10,1,0,-2, true)); | ||||||
|             bullets.push(new Bullet(107,460-(Date.now()*0.1)%365,10,1,0,-2, true)); |             bullets.push(new Bullet(107,460-(Date.now()*0.1)%365,10,1,0,-2, true)); | ||||||
|         } else { |         } else { | ||||||
|             lastbulletdonjon[1]++ |             lastbulletdonjon[1]++; | ||||||
|         } |         } | ||||||
|         if(lastbulletdonjon[0]==59 && Math.floor(Date.now()/1000)%60 !=59) { lastbulletdonjon[0]=0 } |         if(lastbulletdonjon[0]==59 && Math.floor(Date.now()/1000)%60 !=59) { lastbulletdonjon[0]=0 } | ||||||
|         if(Math.floor(Date.now()/1000)%60 > lastbulletdonjon[0]) {     |         if(Math.floor(Date.now()/1000)%60 > lastbulletdonjon[0]) {     | ||||||
|             lastbulletdonjon[0]=Math.floor(Date.now()/1000)%60 |             lastbulletdonjon[0]=Math.floor(Date.now()/1000)%60; | ||||||
|             for(let i=0;i<5;i++){ |             for(let i=0;i<5;i++){ | ||||||
|                 bullets.push(new Bullet(235,65,10,0,2,-2, true)); |                 bullets.push(new Bullet(235,65,10,0,2,-2, true)); | ||||||
|                 bullets.push(new Bullet(235,491,10,0,-2,-2, true)); |                 bullets.push(new Bullet(235,491,10,0,-2,-2, true)); | ||||||
|  | @ -199,32 +199,32 @@ function Donjon() { | ||||||
| function Lester(type, data) { | function Lester(type, data) { | ||||||
|     switch(type) { |     switch(type) { | ||||||
|         case 1: |         case 1: | ||||||
|             player.x=data[0] |             player.x=data[0]; | ||||||
|             player.y=data[1] |             player.y=data[1]; | ||||||
|             player.z=data[2] |             player.z=data[2]; | ||||||
|             net.update(player); |             net.update(player); | ||||||
|             break; |             break; | ||||||
|         case 2: |         case 2: | ||||||
|             player.health=defaulthealth |             player.health=defaulthealth; | ||||||
|             break; |             break; | ||||||
|         case 3: |         case 3: | ||||||
|             addKill(data, player.id) |             addKill(data, player.id); | ||||||
|             net.died(data, player.id) |             net.died(data, player.id); | ||||||
|             break; |             break; | ||||||
|         case 4: |         case 4: | ||||||
|             players.forEach((p) => { |             players.forEach((p) => { | ||||||
|                 if(p.id>0) { |                 if(p.id>0) { | ||||||
|                     net.died(p.id, player.id) |                     net.died(p.id, player.id); | ||||||
|                     addKill(data, player.id) |                     addKill(data, player.id); | ||||||
|                     p.death++ |                     p.death++; | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|             break; |             break; | ||||||
|         case 5: |         case 5: | ||||||
|             if(drawCollisions) { |             if(drawCollisions) { | ||||||
|                 drawCollisions=false |                 drawCollisions=false; | ||||||
|             } else { |             } else { | ||||||
|                 drawCollisions=true |                 drawCollisions=true; | ||||||
|             } |             } | ||||||
|             break; |             break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| class Input { | class Input { | ||||||
|     constructor(idCanvas) { |     constructor(idCanvas) { | ||||||
|         this.keysDown = new Set() |         this.keysDown = new Set(); | ||||||
|         this.dir = 0; |         this.dir = 0; | ||||||
|          |          | ||||||
|         this.canvas = document.getElementById(idCanvas); |         this.canvas = document.getElementById(idCanvas); | ||||||
|  | @ -33,20 +33,19 @@ class Input { | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         window.addEventListener("keydown", (e)=>{ |         window.addEventListener("keydown", (e)=>{ | ||||||
|             //blocks the action of the key (cf. Killian)
 |  | ||||||
|             if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.code)) { |             if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.code)) { | ||||||
|                 e.preventDefault(); |                 e.preventDefault(); | ||||||
|             } |             } | ||||||
|             this.keysDown.add(e.key.toLowerCase()) |             this.keysDown.add(e.key.toLowerCase()); | ||||||
|             this.updateDir(); |             this.updateDir(); | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|         document.getElementById("retour_menu").addEventListener("click", (e) => { |         document.getElementById("retour_menu").addEventListener("click", (e) => { | ||||||
|             phone.changeWindow(1) |             phone.changeWindow(1); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         window.addEventListener("keyup", (e)=>{ |         window.addEventListener("keyup", (e)=>{ | ||||||
|             this.keysDown.delete(e.key.toLowerCase()) |             this.keysDown.delete(e.key.toLowerCase()); | ||||||
|             this.updateDir(); |             this.updateDir(); | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|  | @ -97,10 +96,4 @@ class Input { | ||||||
|             net.update(player); |             net.update(player); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     /* |  | ||||||
|     calculateAngle(playerX, playerY) { |  | ||||||
|         return Math.atan2(this.mouseY - playerY, this.mouseX - playerX); |  | ||||||
|     } |  | ||||||
|     */ |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -58,14 +58,5 @@ class LeaderBoard { | ||||||
| 				this.nbjoueur++; | 				this.nbjoueur++; | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 
 |  | ||||||
| 	    /*this.ctx.fillText('1', this.px+20, this.py+120); |  | ||||||
| 	    this.ctx.fillText('Player1', this.px+50, this.py+120); |  | ||||||
| 	    this.ctx.fillText('10/20', this.px+180, this.py+120); |  | ||||||
| 
 |  | ||||||
| 	    this.ctx.fillText('2', this.px+20, this.py+120+20); |  | ||||||
| 	    this.ctx.fillText('Player2', this.px+50, this.py+120+20); |  | ||||||
| 	    this.ctx.fillText('10/2', this.px+180, this.py+120+20); |  | ||||||
| 		*/ |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -47,7 +47,7 @@ class Network{ | ||||||
| 				if(data.data.player_id == player.id){ | 				if(data.data.player_id == player.id){ | ||||||
| 					alert("Vous avez essayé de tricher, vous jouez maintenant en solo."); | 					alert("Vous avez essayé de tricher, vous jouez maintenant en solo."); | ||||||
| 				}else{ | 				}else{ | ||||||
| 					console.log("Player " + data.data.player_id.toString() + " caught cheating.") | 					console.log("Player " + data.data.player_id.toString() + " caught cheating."); | ||||||
| 				} | 				} | ||||||
| 				break; | 				break; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,39 +9,39 @@ class Phone{ | ||||||
| 		this.inputDiv = document.getElementById("chatInputDiv"); | 		this.inputDiv = document.getElementById("chatInputDiv"); | ||||||
| 		this.webview = document.getElementById("webview"); | 		this.webview = document.getElementById("webview"); | ||||||
| 
 | 
 | ||||||
| 		this.webviewName = "Erreur" | 		this.webviewName = "Erreur"; | ||||||
| 
 | 
 | ||||||
| 		this.chargeMainPage(); | 		this.chargeMainPage(); | ||||||
| 		this.changeWindow(1) | 		this.changeWindow(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	chargeMainPage() { | 	chargeMainPage() { | ||||||
| 		document.getElementById("appli-concord").addEventListener("click", (e) => { | 		document.getElementById("appli-concord").addEventListener("click", (e) => { | ||||||
|             this.changeWindow(2) |             this.changeWindow(2); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-gta6").addEventListener("click", (e) => { | 		document.getElementById("appli-gta6").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "GTA 6" |             this.webviewName = "GTA 6"; | ||||||
|             this.changeWindow("game.html") |             this.changeWindow("game.html"); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-vbuks").addEventListener("click", (e) => { | 		document.getElementById("appli-vbuks").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "Free Vbucks" |             this.webviewName = "Free Vbucks"; | ||||||
|             this.changeWindow("assets/phone/webview/vbucks.html") |             this.changeWindow("assets/phone/webview/vbucks.html"); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-fb").addEventListener("click", (e) => { | 		document.getElementById("appli-fb").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "FakeBook" |             this.webviewName = "FakeBook"; | ||||||
|             this.changeWindow("assets/phone/webview/fb.html") |             this.changeWindow("assets/phone/webview/fb.html"); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-utube").addEventListener("click", (e) => { | 		document.getElementById("appli-utube").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "uTube" |             this.webviewName = "uTube"; | ||||||
|             this.changeWindow("assets/phone/webview/utube.html") |             this.changeWindow("assets/phone/webview/utube.html"); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-goo").addEventListener("click", (e) => { | 		document.getElementById("appli-goo").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "Gogole" |             this.webviewName = "Gogole"; | ||||||
|             this.changeWindow("https://mrdoob.com/projects/chromeexperiments/google-space/") |             this.changeWindow("https://mrdoob.com/projects/chromeexperiments/google-space/"); | ||||||
|         }); |         }); | ||||||
| 		document.getElementById("appli-lest").addEventListener("click", (e) => { | 		document.getElementById("appli-lest").addEventListener("click", (e) => { | ||||||
|             this.webviewName = "Lester" |             this.webviewName = "Lester"; | ||||||
|             this.changeWindow("assets/phone/webview/lester.html") |             this.changeWindow("assets/phone/webview/lester.html"); | ||||||
|         }); |         }); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -57,11 +57,11 @@ class Phone{ | ||||||
| 
 | 
 | ||||||
| 		switch (window) { | 		switch (window) { | ||||||
| 			case 1: | 			case 1: | ||||||
| 				this.name.innerText = "Pear phone" | 				this.name.innerText = "Pear phone"; | ||||||
| 				this.content.style.display="block"; | 				this.content.style.display="block"; | ||||||
| 				break; | 				break; | ||||||
| 			case 2: | 			case 2: | ||||||
| 				this.name.innerText = "Concord" | 				this.name.innerText = "Concord"; | ||||||
| 				this.contentmsg.style.display="block"; | 				this.contentmsg.style.display="block"; | ||||||
| 				this.inputDiv.style.display="block"; | 				this.inputDiv.style.display="block"; | ||||||
| 				break; | 				break; | ||||||
|  | @ -129,7 +129,7 @@ class Phone{ | ||||||
| 			if(input.value!=''){ | 			if(input.value!=''){ | ||||||
| 				this.sendMessage(player.name, input.value); | 				this.sendMessage(player.name, input.value); | ||||||
| 				input.value = ''; | 				input.value = ''; | ||||||
| 				input.blur() | 				input.blur(); | ||||||
| 			}		 | 			}		 | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -8,6 +8,6 @@ class Sound{ | ||||||
|     play(){ |     play(){ | ||||||
|         //this.sound.pause()
 |         //this.sound.pause()
 | ||||||
|         this.sound.currentTime=0; |         this.sound.currentTime=0; | ||||||
|         this.sound.play() |         this.sound.play(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
		Reference in a new issue