keyboard debug
This commit is contained in:
		
							parent
							
								
									2eb32dae29
								
							
						
					
					
						commit
						1e7da4aa41
					
				
					 3 changed files with 18 additions and 3 deletions
				
			
		|  | @ -47,6 +47,14 @@ class Player | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     changeDirection(newDirection){ | ||||
|         this.dir = newDirection; | ||||
|         if(this.dir!=0){ | ||||
|             this.visibleDir = newDirection; | ||||
|         } | ||||
|         Net.update(this); | ||||
|     } | ||||
| 
 | ||||
|     update(squares,circles)//update position
 | ||||
|     { | ||||
|         if(this.dir==0) | ||||
|  |  | |||
|  | @ -32,10 +32,10 @@ class Keyboard{ | |||
| 		}else if(this.keysDown.has('q')){ | ||||
| 			newDir = 7; | ||||
| 		} | ||||
| 		console.log(newDir) | ||||
| 		 | ||||
| 		for (var i = players.length - 1; i >= 0; i--) { | ||||
| 			if(players[i].id==playerId){ | ||||
| 				players[i].dir = newDir; | ||||
| 				players[i].changeDirection(newDir); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ class Network{ | |||
| 			case 'update': | ||||
| 				for (var i = players.length - 1; i >= 0; i--) { | ||||
| 					if(players[i].id==data.data.id){ | ||||
| 						players[i]=data.data; | ||||
| 						players[i].retrieveServerInfo(data.data.id, data.data.x, data.data.y, data.data.dir); | ||||
| 						break; | ||||
| 					}				 | ||||
| 				} | ||||
|  | @ -40,4 +40,11 @@ class Network{ | |||
| 			this.message(JSON.parse(e.data)); | ||||
| 		}) | ||||
| 	} | ||||
| 
 | ||||
| 	update(obj){ | ||||
| 		this.socket.send(JSON.stringify({ | ||||
| 			type: "update", | ||||
| 			data: obj | ||||
| 		})) | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in a new issue