diff --git a/Bubble.py b/Bubble.py index ab69995..4d14665 100644 --- a/Bubble.py +++ b/Bubble.py @@ -2,16 +2,17 @@ import pygame import random class Bubble: - def __init__(self, posX, posY, radius = 1, color=(0,0,255), direction=(1,1)): + def __init__(self, posX, posY, image, radius = 1, color=(0,0,255), direction=(1,1)): self.posX = posX self.posY = posY self.radius = radius self.color = color self.directionX = direction[0] self.directionY = direction[1] + self.image = image def draw(self, screen): - pygame.draw.circle(screen, self.color, (self.posX, self.posY), self.radius) + screen.blit(self.image, (self.posX - self.radius, self.posY - self.radius)) def update(self, screen): diff --git a/Car.py b/Car.py index 5a63be9..7a945a6 100644 --- a/Car.py +++ b/Car.py @@ -13,9 +13,11 @@ class Car: self.game_objects = game_objects self.bubble_spawn_time_ms = 1000 self.time_of_last_spawn = 0 + self.BUBBLE_IMAGE = pygame.image.load("sprites/bubble.png") def draw(self, screen): pygame.draw.rect(screen, self.color, pygame.Rect(self.posX, self.posY, self.width, self.height)) + def update(self, screen): self.posX += self.directionX @@ -25,6 +27,9 @@ class Car: if self.bubble_spawn_time_ms + self.time_of_last_spawn < pygame.time.get_ticks(): bubble_y_direction = random.uniform(-1, 1) bubble_x_speeddiff = random.uniform(0, 0.9) - bubble_radius = random.uniform(5, 10) - self.game_objects.append(Bubble(self.posX, self.posY + self.height - bubble_radius, radius=bubble_radius, direction=(-self.directionX * bubble_x_speeddiff,bubble_y_direction))) + bubble_radius = 16 + self.game_objects.append(Bubble(self.posX, self.posY + self.height - bubble_radius, + self.BUBBLE_IMAGE, + radius=bubble_radius, + direction=(-self.directionX * bubble_x_speeddiff,bubble_y_direction))) self.time_of_last_spawn = pygame.time.get_ticks() diff --git a/sprites/bubble.png b/sprites/bubble.png new file mode 100644 index 0000000..9cd8d0a Binary files /dev/null and b/sprites/bubble.png differ