Spaces:
Configuration error
Configuration error
File size: 3,882 Bytes
34ecae4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | import pygame
import random
from .constants import WIDTH, HEIGHT
class BulletRefill(pygame.sprite.Sprite):
def __init__(self, x, y, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.speed = 1
self.direction_x = random.choice([-2, 2])
self.direction_y = random.choice([-2, 2])
self.sound_effect = pygame.mixer.Sound("game_sounds/refill/bullet_refill.wav")
self.sound_effect.set_volume(0.4)
def update(self):
self.rect.y += self.speed * self.direction_y
self.rect.x += self.speed * self.direction_x
self.rect.left = max(self.rect.left, 0)
self.rect.right = min(self.rect.right, WIDTH)
self.rect.top = max(self.rect.top, 0)
self.rect.bottom = min(self.rect.bottom, HEIGHT)
if random.randint(0, 50) == 0:
self.direction_x *= - 1
self.direction_y *= - 1
def draw(self, surface):
surface.blit(self.image, self.rect)
class HealthRefill(pygame.sprite.Sprite):
def __init__(self, x, y, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.speed = 1
self.direction_x = random.choice([-2, 2])
self.direction_y = random.choice([-2, 2])
self.sound_effect = pygame.mixer.Sound("game_sounds/refill/health_refill.wav")
self.sound_effect.set_volume(0.4)
def update(self):
self.rect.y += self.speed * self.direction_y
self.rect.x += self.speed * self.direction_x
self.rect.left = max(self.rect.left, 0)
self.rect.right = min(self.rect.right, WIDTH)
self.rect.top = max(self.rect.top, 0)
self.rect.bottom = min(self.rect.bottom, HEIGHT)
if random.randint(0, 50) == 0:
self.direction_x *= - 1
self.direction_y *= - 1
def draw(self, surface):
surface.blit(self.image, self.rect)
class DoubleRefill(pygame.sprite.Sprite):
def __init__(self, x, y, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.speed = 2
self.direction_x = random.choice([-2, 2])
self.direction_y = random.choice([-2, 2])
self.sound_effect = pygame.mixer.Sound("game_sounds/refill/double_refill.mp3")
self.sound_effect.set_volume(0.4)
def update(self):
self.rect.y += self.speed * self.direction_y
self.rect.x += self.speed * self.direction_x
self.rect.left = max(self.rect.left, 0)
self.rect.right = min(self.rect.right, WIDTH)
self.rect.top = max(self.rect.top, 0)
self.rect.bottom = min(self.rect.bottom, HEIGHT)
if random.randint(0, 50) == 0:
self.direction_x *= - 1
self.direction_y *= - 1
def draw(self, surface):
surface.blit(self.image, self.rect)
class ExtraScore(pygame.sprite.Sprite):
def __init__(self, x, y, image):
super().__init__()
self.original_image = image
self.image = self.original_image.copy()
self.rect = self.image.get_rect()
self.speed = 2
self.rect.x = x
self.rect.y = y
self.direction_x = 0
self.direction_y = 1
self.sound_effect = pygame.mixer.Sound("game_sounds/refill/extra_score.mp3")
self.sound_effect.set_volume(0.4)
def update(self):
self.rect.y += self.speed * self.direction_y
if self.rect.bottom >= HEIGHT + 100:
self.kill()
def draw(self, surface):
surface.blit(self.image, self.rect)
|