def update(self): BasePipe.update(self) if self.current_pos_y < settings.TUBE_SIZE: self.current_pos_y += 1 self.flow_rect.bottom = self.current_pos_y pygame.draw.rect(self.image, settings.FLOW_COLOR, self.flow_rect, 1) self.image.blit(utils.debug_text('August'), (3, 3))
def update(self): BasePipe.update(self) if self.flow_dir == settings.FLOW_TB: if self.current_pos_y < settings.TUBE_SIZE: self.current_pos_y += 1 self.flow_rect.bottom = self.current_pos_y else: # Dette er testkode for å sjekke alle retninger self.flow_dir = settings.FLOW_BT self.init_flow() elif self.flow_dir == settings.FLOW_BT: if self.current_pos_y > 0: self.current_pos_y -= 1 self.flow_rect.top = self.current_pos_y else: self.flow_dir = settings.FLOW_LR self.init_flow() elif self.flow_dir == settings.FLOW_LR: if self.current_pos_x < settings.TUBE_SIZE: self.current_pos_x += 1 self.flow_rect.right = self.current_pos_x else: self.flow_dir = settings.FLOW_RL self.init_flow() elif self.flow_dir == settings.FLOW_RL: if self.current_pos_x > 0: self.current_pos_x -= 1 self.flow_rect.left = self.current_pos_x else: self.flow_dir = settings.FLOW_TB self.init_flow() pygame.draw.rect(self.image, settings.FLOW_COLOR, self.flow_rect, 1) self.image.blit(utils.debug_text('Tom'), (3, 3)) font = pygame.font.SysFont('', 40) # font.render returnerer et surface font_surface = font.render('S', True, (0, 0, 0)) self.image.blit( font_surface, (settings.TUBE_SIZE / 2 - 10, settings.TUBE_SIZE / 2 - 10))
pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_UP: balloon.sprite.burn() if balloon.sprite.level_up: add_mine() surface.blit(background, (0, 0)) mines.update() mines.draw(surface) balloon.update() balloon.draw(surface) surface.blit(utils.debug_text('{}'.format(int(clock.get_fps()))), (0, 0)) display_points(int(balloon.sprite.points)) screen.blit(surface, (0, 0)) pygame.display.flip() pygame.display.update() clock.tick(settings.FPS) # Sjekker om vi traff topp eller bunn av skjermen if balloon.sprite.hit: game_over() # Sjekker om det er noen rect for sprite som overlapper mine_hit = pygame.sprite.spritecollideany(balloon.sprite, mines) if mine_hit: # Sjekker om de overlapper på pixelnivå