class Apple(pygame.sprite.Sprite):
def init(self, cfg, snake_coords, **kwargs):
pygame.sprite.Sprite.init(self)
self.cfg = cfg
while True:
self.coord = [random.randint(0, cfg.GAME_MATRIX_SIZE[0]-1), random.randint(0, cfg.GAME_MATRIX_SIZE[1]-1)]
if self.coord not in snake_coords:
break
self.color = (255, 0, 0)
'''画到屏幕上'''
def draw(self, screen):
cx, cy = int((self.coord[0] + 0.5) * self.cfg.BLOCK_SIZE), int((self.coord[1] + 0.5) * self.cfg.BLOCK_SIZE)
pygame.draw.circle(screen, self.color, (cx, cy), self.cfg.BLOCK_SIZE//2-2)
这是python写的贪吃蛇食物代码帮我分析一下
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-