You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. import pygame
  2. class Shooter(pygame.sprite.Sprite):
  3. def __init__(self, window, texture, colour=(255,255,255), width=55, height=25):
  4. super().__init__()
  5. self.width = width
  6. self.height = height
  7. self.colour = colour
  8. self.texture = texture
  9. self.image = pygame.transform.scale(self.texture.get_texture("PLAYER"), (self.width, self.height))
  10. self.rect = self.image.get_rect()
  11. self.speed = 3
  12. self.window_rect = window.get_rect()
  13. self.score = 0
  14. self.OP = False
  15. self.level = 0
  16. self.lives = 3
  17. self.powerup = ""
  18. def set_position(self,x,y):
  19. self.rect.x, self.rect.y = x, y
  20. def move(self, value):
  21. self.rect.x += value
  22. self.rect.clamp_ip(self.window_rect)
  23. def update(self):
  24. self.image.fill(self.colour)
  25. self.rect = self.image.get_rect()
  26. def change_colour(self, colour):
  27. x,y = self.rect.x, self.rect.y
  28. self.image.fill(colour)
  29. self.rect = self.image.get_rect()
  30. self.set_position(x,y)
  31. def reset_image(self):
  32. x,y = self.rect.x, self.rect.y
  33. self.image = pygame.transform.scale(self.texture.get_texture("PLAYER"), (self.width, self.height))
  34. self.rect = self.image.get_rect()
  35. self.set_position(x,y)