on peut rentrer dans un bâtiment !!
This commit is contained in:
		
							parent
							
								
									aaf755a871
								
							
						
					
					
						commit
						07fdebfcd8
					
				
					 4 changed files with 70 additions and 25 deletions
				
			
		| Before Width: | Height: | Size: 520 KiB After Width: | Height: | Size: 520 KiB | 
|  | @ -9,7 +9,7 @@ function CookiePseudo() { | ||||||
|     return null; |     return null; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Renderer = new Render("canvas", "./assets/map/map7_principale.png", "./assets/map/map7_secondaire.png"); | Renderer = new Render("canvas", "./assets/map/map_principale.png", "./assets/map/map_secondaire.png"); | ||||||
| LB = new LeaderBoard("canvas"); | LB = new LeaderBoard("canvas"); | ||||||
| let sound = new Sound("./assets/sounds/"); | let sound = new Sound("./assets/sounds/"); | ||||||
| sound.loadSounds(); | sound.loadSounds(); | ||||||
|  | @ -37,6 +37,13 @@ let dt = 1; | ||||||
| 
 | 
 | ||||||
| function update() | function update() | ||||||
| { | { | ||||||
|  | 	if(player.y>470 && player.y<480 && player.x>237 && player.x<310) { | ||||||
|  | 		player.x=2510 | ||||||
|  | 		player.y=2714 | ||||||
|  | 	} else if (player.x>2588 && player.x<2687 && player.y>2129 && player.y<2180) { | ||||||
|  | 		player.x=270 | ||||||
|  | 		player.y=250 | ||||||
|  | 	} | ||||||
| 	let playerToUpdate = Net.getPlayersToUpdate(); | 	let playerToUpdate = Net.getPlayersToUpdate(); | ||||||
| 	for (let i = 0;i<playerToUpdate.length;i++) | 	for (let i = 0;i<playerToUpdate.length;i++) | ||||||
| 	{ | 	{ | ||||||
|  |  | ||||||
|  | @ -20,8 +20,14 @@ class Input { | ||||||
|             if(this.player==null || this.bullets==null){ |             if(this.player==null || this.bullets==null){ | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |             if(this.player.x>=2000 && this.player.y>=2000 && this.mouseX<2000 && this.mouseY<2000) { | ||||||
|  |                 this.mouseX=this.mouseX+2000; | ||||||
|  |                 this.mouseY=this.mouseY+2000; | ||||||
|  |             } | ||||||
|  |              | ||||||
|             let dx = this.mouseX-this.player.x; |             let dx = this.mouseX-this.player.x; | ||||||
|             let dy = this.mouseY-this.player.y; |             let dy = this.mouseY-this.player.y; | ||||||
|  | 
 | ||||||
|             let norm = Math.sqrt(dx*dx+dy*dy); |             let norm = Math.sqrt(dx*dx+dy*dy); | ||||||
|             let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id, sound); |             let b = new Bullet(this.player.x,this.player.y,dx/norm,dy/norm,this.player.id, sound); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,8 +13,10 @@ class Render { | ||||||
| 		this.players = []; | 		this.players = []; | ||||||
| 		this.bullets = []; | 		this.bullets = []; | ||||||
| 		this.mapsrc=mapsrc; | 		this.mapsrc=mapsrc; | ||||||
|  | 		this.map2src=map2src; | ||||||
| 		this.ReloadAff(); | 		this.ReloadAff(); | ||||||
| 		this.playerid=0; | 		this.playerid=0; | ||||||
|  | 		this.map=0 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	SetPlayerId(id) { | 	SetPlayerId(id) { | ||||||
|  | @ -49,43 +51,73 @@ class Render { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	RenderPlayer(player) { | 	RenderPlayer(player) { | ||||||
| 	    this.ctx.save(); | 		let x=player.x | ||||||
| 	    this.ctx.translate(player.x, player.y); | 		let y=player.y | ||||||
| 	    this.ctx.rotate(player.angle); | 		if(x>=2000 && y>=2000 && this.map==1) { | ||||||
| 	    this.ctx.drawImage(imgPlayer, -playerSize / 2, -playerSize / 2, playerSize, playerSize); | 			x=player.x-2000 | ||||||
| 	    this.ctx.restore(); | 			y=player.y-2000 | ||||||
| 		this.ctx.fillStyle = 'white'; | 		} | ||||||
|         this.ctx.font="10pt arial"; | 
 | ||||||
|         this.ctx.fillText(player.name,player.x-player.name.length*10/3,player.y-playerSize/1.8); | 		//this.map==1 && (x<2000 || y<2000)
 | ||||||
|         if(player.id==this.playerid) { | 		if((this.map==1 && player.x>=2000 && player.y>=2000) || (this.map==0 && x<2000 && y <2000)) { | ||||||
| 			this.ctx.fillStyle = 'red'; | 			this.ctx.save(); | ||||||
| 		    this.ctx.fillRect(player.x-playerSize/2-5, player.y-playerSize/2, playerSize+10, 5); | 		    this.ctx.translate(x, y); | ||||||
| 			this.ctx.fillStyle = '#7AFF33'; | 		    this.ctx.rotate(player.angle); | ||||||
| 		    this.ctx.fillRect(player.x-playerSize/2-5, player.y-playerSize/2, player.health*(playerSize+10)/defaulthealth, 5); | 		    this.ctx.drawImage(imgPlayer, -playerSize / 2, -playerSize / 2, playerSize, playerSize); | ||||||
|         } | 		    this.ctx.restore(); | ||||||
|  | 			this.ctx.fillStyle = 'white'; | ||||||
|  | 	        this.ctx.font="10pt arial"; | ||||||
|  | 	        this.ctx.fillText(player.name,x-name.length*10/3,y-playerSize/1.8); | ||||||
|  | 	        if(player.id==this.playerid) { | ||||||
|  | 				this.ctx.fillStyle = 'red'; | ||||||
|  | 			    this.ctx.fillRect(x-playerSize/2-5, y-playerSize/2, playerSize+10, 5); | ||||||
|  | 				this.ctx.fillStyle = '#7AFF33'; | ||||||
|  | 			    this.ctx.fillRect(x-playerSize/2-5, y-playerSize/2, player.health*(playerSize+10)/defaulthealth, 5); | ||||||
|  | 	        } | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	RenderCar(x,y,angle) { | 	RenderCar(x,y,angle) { | ||||||
| 	    this.ctx.save(); | 		if(this.map==0) { | ||||||
| 	    this.ctx.translate(x, y); | 		    this.ctx.save(); | ||||||
| 	    this.ctx.rotate(angle); | 		    this.ctx.translate(x, y); | ||||||
| 	    this.ctx.drawImage(imgCar, -carSize*1513/750 / 2, -carSize / 2, carSize*1513/750, carSize); | 		    this.ctx.rotate(angle); | ||||||
| 	    this.ctx.restore(); | 		    this.ctx.drawImage(imgCar, -carSize*1513/750 / 2, -carSize / 2, carSize*1513/750, carSize); | ||||||
|  | 		    this.ctx.restore(); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	RenderBullet(bullet) { | 	RenderBullet(bullet) { | ||||||
|  | 		let x = bullet.x | ||||||
|  | 		let y = bullet.y | ||||||
|  | 		if(this.map==1) { | ||||||
|  | 			x = x-2000 | ||||||
|  | 			y = y-2000 | ||||||
|  | 		} | ||||||
| 	    this.ctx.save(); | 	    this.ctx.save(); | ||||||
| 	    this.ctx.translate(bullet.x, bullet.y); | 	    this.ctx.translate(x, y); | ||||||
| 	    this.ctx.drawImage(imgBullet, -20 / 2, -20 / 2, 20, 20); | 	    this.ctx.drawImage(imgBullet, -20 / 2, -20 / 2, 20, 20); | ||||||
| 	    this.ctx.restore(); | 	    this.ctx.restore(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	ReloadAff() { | 	ReloadAff() { | ||||||
| 		/*this.ctx.fillStyle = "red"; |  | ||||||
|    		this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height); |  | ||||||
| 		*/ |  | ||||||
| 		const fond = new Image(); | 		const fond = new Image(); | ||||||
| 		fond.src = this.mapsrc; | 		this.players.forEach((p) => { | ||||||
|  | 			if(p.id==this.playerid) { | ||||||
|  | 				//console.log(p)
 | ||||||
|  | 				if(p.x >= 2000 && p.y >=2000) { | ||||||
|  | 					this.map=1 | ||||||
|  | 				} else { | ||||||
|  | 					this.map=0 | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}) | ||||||
|  | 
 | ||||||
|  | 		if(this.map==0) { | ||||||
|  | 			fond.src = this.mapsrc; | ||||||
|  | 		} else { | ||||||
|  | 			fond.src = this.map2src; | ||||||
|  | 		} | ||||||
| 		mapWidth = fond.width; | 		mapWidth = fond.width; | ||||||
| 		mapHeith = fond.height; | 		mapHeith = fond.height; | ||||||
| 		this.ctx.canvas.width = mapWidth; | 		this.ctx.canvas.width = mapWidth; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue