Adding + removing players
This commit is contained in:
		
							parent
							
								
									7f84496398
								
							
						
					
					
						commit
						4731216d3a
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		
							
								
								
									
										17
									
								
								js/game.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								js/game.js
									
									
									
									
									
								
							|  | @ -53,6 +53,23 @@ function game() { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 		let playersToAdd = Net.getPlayersToAdd(); | ||||||
|  | 		if (playersToAdd.length!=0) | ||||||
|  | 			console.log("added ",playersToAdd.length); | ||||||
|  | 		players.concat(playersToAdd); | ||||||
|  | 		let playerToRemove = Net.getPlayersToRemove(); | ||||||
|  | 		for(let id in playerToRemove) | ||||||
|  | 		{ | ||||||
|  | 			console.log("deleting ",id); | ||||||
|  | 			for(let i = 0;i<players.length;i++) | ||||||
|  | 			{ | ||||||
|  | 				if (players[i].id==id) | ||||||
|  | 				{ | ||||||
|  | 					players.splice(i,1); | ||||||
|  | 					break; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 		player.update([],[], dt); | 		player.update([],[], dt); | ||||||
| 		for (var i = players.length - 1; i >= 0; i--) { | 		for (var i = players.length - 1; i >= 0; i--) { | ||||||
| 			players[i].update([],[], dt);//squares, circles
 | 			players[i].update([],[], dt);//squares, circles
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue