def move(self): Shooter.move(self) self.x += self.speed if self.x < 0 or self.x > width: self.speed *= -1 if self.x < 0: self.x = width
elif e.type == pygame.KEYDOWN: if e.key == pygame.K_LEFT: s.rect = s.rect.move((-s.dx, 0)) elif e.key == pygame.K_RIGHT: s.rect = s.rect.move((s.dx, 0)) elif e.key == pygame.K_UP: s.rect = s.rect.move((0, -s.dx)) elif e.key == pygame.K_DOWN: s.rect = s.rect.move((0, +s.dx)) s.checkBoundaries() screen.blit(bg, (0, 0)) if pygame.sprite.spritecollideany(s, game_map.mushrooms, False): print("OLD :", oldpos) curpos = pygame.math.Vector2(s.rect.x, s.rect.y) print("CUR :", curpos) s.move(curpos - oldpos) for mushroom in game_map.mushrooms: m_hit = pygame.sprite.spritecollideany(mushroom, s.bullets, False) if m_hit: m_hit.kill() mushroom.inc_state() for mushroom in game_map.mushrooms: mushroom.update() mushroom.draw() s.update() s.draw() pygame.display.flip() clock.tick(30)