weapon.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. from sprite_object import *
  2. class Weapon(AnimatedSprite):
  3. def __init__(self, game, path='resources/sprites/weapon/shotgun/0.png', scale=0.4, animation_time=90):
  4. super().__init__(game=game, path=path, scale=scale, animation_time=animation_time)
  5. self.images = deque(
  6. [pg.transform.smoothscale(img, (int(self.image.get_width() * scale), int(self.image.get_height() * scale)))
  7. for img in self.images])
  8. self.weapon_pos = (HALF_WIDTH - self.images[0].get_width() // 2, HEIGHT - self.images[0].get_height())
  9. self.reloading = False
  10. self.num_images = len(self.images)
  11. self.frame_counter = 0
  12. self.damage = 50
  13. def animate_shot(self):
  14. if self.reloading:
  15. self.game.player.shot = False
  16. if self.animation_trigger:
  17. self.images.rotate(-1)
  18. self.image = self.images[0]
  19. self.frame_counter += 1
  20. if self.frame_counter == self.num_images:
  21. self.reloading = False
  22. self.frame_counter = 0
  23. def draw(self):
  24. self.game.screen.blit(self.images[0], self.weapon_pos)
  25. def update(self):
  26. self.check_animation_time()
  27. self.animate_shot()