接着上面,继续写下面的

动态 未结 0 98
小小草
小小草 LV1 2023年9月23日 23:40 发表
常量 self.speed = 0 self.image_index = 0 self.image = bird_images[self.image_index] self.rect = self.image.get_rect() def jump(self): self.speed = jump_speed def update(self): # 更新速度和位置 self.speed += gravity self.y += self.speed # 更新图片 self.image_index += 1 if self.image_index >= len(bird_images): self.image_index = 0 self.image = bird_images[self.image_index] # 更新矩形 self.rect.x = self.x self.rect.y = self.y def draw(self): screen.blit(self.image, self.rect) class Pipe: def __init__(self, x): self.x = x self.height = random.randint(100, 300) self.top_y = self.height - pipe_image.get_height() self.bottom_y = self.height + pipe_gap self.rect_top = pygame.Rect(self.x, self.top_y, pipe_image.get_width(), pipe_image.get_height()) self.rect_bottom = pygame.Rect(self.x, self.bottom_y, pipe_image.get_width(), pipe_image.get_height()) def update(self): self.x += pipe_speed self.rect_top.x = self.x self.rect_bottom.x = self.x def draw(self): screen.blit(pipe_image, (self.x, self.top_y)) screen.blit(pygame.transform.flip(pipe_image, False, True), (self.x, self.bottom_y)) class Base: def __init__(self): self.x = 0 self.y = screen_height - base_image.get_height() self.rect = pygame.Rect(self.x, self.y, base_image.get_width(), base_image.get_height()) def update(self): self.x += base_speed if self.x <= -base_image.get_width(): self.x += base_image.get_width() self.rect.x = self.x def draw(self): screen.blit(base_image, (self.x, self.y)) # 创建对象 bird = Bird() pipes = [Pipe(screen_width + i * 200) for i in range(3)] base = Base() # 游戏循环 while True: # 处理事件 for event in pygame.event.get():
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复