diff --git a/Bicycle.py b/Bicycle.py new file mode 100644 index 0000000..ea11113 --- /dev/null +++ b/Bicycle.py @@ -0,0 +1,32 @@ +import pygame +import random +from Bubble import Bubble + +class Bicycle: + def __init__(self, posX, posY, directionX=random.uniform(1, 3)): + self.posX = posX + self.posY = posY + self.directionX = directionX + self.width = 73 + self.height = 40 + self.image = pygame.image.load("sprites/bicycle.png") + + if directionX < 0: + self.image = pygame.transform.flip(self.image, True, False) + + def draw(self, screen): + screen.blit(self.image, (self.posX, self.posY)) + + + def update(self, screen): + self.posX += self.directionX + screen_width, screen_height = screen.get_size() + if self.directionX > 0: + if self.posX + self.width + self.directionX > screen_width: + self.directionX = -random.uniform(1, 3) + self.image = pygame.transform.flip(self.image, True, False) + else: + if self.posX + self.directionX < 0: + self.directionX = random.uniform(1, 3) + self.image = pygame.transform.flip(self.image, True, False) + diff --git a/main.py b/main.py index 537bf3c..e96b2d0 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from pygame.locals import * from Car import Car from Vacuum import Vacuum from Lane import Lane +from Bicycle import Bicycle pygame.init() pygame.font.init() @@ -48,6 +49,7 @@ for i in range(3, 6): game_objects.append(Car(random.uniform(0, SCREEN_WIDTH), i * 80 + 60, bubble_objects, directionX= - random.uniform(1, 5))) vacuum = Vacuum(bubble_objects) +bicycle = Bicycle(0, SCREEN_HEIGHT - 40) while True: SCREEN.fill(BACKGROUND) @@ -69,6 +71,8 @@ while True: SCREEN.blit(TEXT_SCREEN, TEXT_RECT) SCREEN.blit(SUBTITLE_TEXT_SCREEN, SUBTITLE_TEXT_RECT) SCREEN.blit(SUBTITLE_TEXT_SCREEN2, SUBTITLE_TEXT_RECT2) + bicycle.update(SCREEN) + bicycle.draw(SCREEN) diff --git a/sprites/bicycle.png b/sprites/bicycle.png new file mode 100644 index 0000000..c0d9101 Binary files /dev/null and b/sprites/bicycle.png differ