update: movement
This commit is contained in:
		
							parent
							
								
									ec9b9c90ef
								
							
						
					
					
						commit
						81404a51da
					
				
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										32
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								main.py
									
									
									
									
									
								
							| @ -35,25 +35,43 @@ class SNAKE(): | |||||||
|     def add_dody(self): |     def add_dody(self): | ||||||
|         self.body[len(self.body)-1].type = "body" |         self.body[len(self.body)-1].type = "body" | ||||||
|         last_body = self.body[len(self.body)-1] |         last_body = self.body[len(self.body)-1] | ||||||
|  | 
 | ||||||
|         new_body = body(0,0, last_body.rotate, "tail") |         new_body = body(0,0, last_body.rotate, "tail") | ||||||
|         v_x = int(-math.sin(-last_body.rotate * math.pi / 180)) |         v_x = int(-math.sin(-last_body.rotate * math.pi / 180)) | ||||||
|         new_body.x = -v_x + last_body.x |         new_body.x = -v_x + last_body.x | ||||||
|         v_y = int(math.cos(-last_body.rotate * math.pi / 180)) |         v_y = int(math.cos(-last_body.rotate * math.pi / 180)) | ||||||
|         new_body.y = -v_y + last_body.y |         new_body.y = -v_y + last_body.y | ||||||
|  | 
 | ||||||
|         self.body.append(new_body) |         self.body.append(new_body) | ||||||
| 
 | 
 | ||||||
|     def move(self, vector): |     def move(self, vector): | ||||||
|         self.body[0].rotate = vector * 90 |         self.body[0].rotate = vector * 90 | ||||||
|  |          | ||||||
|  | 
 | ||||||
|         i = len(self.body)-1 |         i = len(self.body)-1 | ||||||
|  |         self.body[len(self.body)-1].type = "tail" | ||||||
|  |         self.body[i].x = self.body[i-1].x | ||||||
|  |         self.body[i].y = self.body[i-1].y | ||||||
|  |         self.body[i].rotate = self.body[i-1].rotate | ||||||
|  | 
 | ||||||
|  |         i-=1 | ||||||
|         while i > 0: |         while i > 0: | ||||||
|             if self.body[i].type == "body" or self.body[i].type == "tail": |             self.body[i].x = self.body[i-1].x | ||||||
|                 self.body[i].x = self.body[i-1].x |             self.body[i].y = self.body[i-1].y | ||||||
|                 self.body[i].y = self.body[i-1].y |  | ||||||
|                 self.body[i].rotate = self.body[i-1].rotate  |  | ||||||
|             i = i - 1 |  | ||||||
|              |              | ||||||
|         self.body[0].x = int(-math.sin(-self.body[0].rotate * math.pi / 180)) + self.body[0].x | 
 | ||||||
|         self.body[0].y = int(math.cos(-self.body[0].rotate * math.pi / 180)) + self.body[0].y |             if abs(math.cos(self.body[i+1].rotate)) == abs(math.cos(self.body[i-1].rotate)) or abs(math.sin(self.body[i+1].rotate)) == abs(math.sin(self.body[i-1].rotate)): | ||||||
|  |                 self.body[i].type = "body" | ||||||
|  |                 self.body[i].rotate = self.body[i-1].rotate | ||||||
|  |             else: | ||||||
|  |                 self.body[i].type = "body-rotate" | ||||||
|  |                 self.body[i].rotate = (self.body[i+1].rotate - 90) % 360 | ||||||
|  |                  | ||||||
|  |              | ||||||
|  | 
 | ||||||
|  |             i = i - 1 | ||||||
|  |         self.body[0].x = int(-math.sin(-(vector * 90) * math.pi / 180)) + self.body[0].x | ||||||
|  |         self.body[0].y = int(math.cos(-(vector * 90) * math.pi / 180)) + self.body[0].y | ||||||
| 
 | 
 | ||||||
|         # print(f"Move {vector}") |         # print(f"Move {vector}") | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user