add bicycle to game over screen

Co-authored-by: Laura Januleviciute <januleviciute.laura@gmail.com>
This commit is contained in:
2021-11-05 23:12:52 +01:00
parent 247a766772
commit 9b049d3704
3 changed files with 36 additions and 0 deletions

32
Bicycle.py Normal file
View File

@@ -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)

View File

@@ -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)

BIN
sprites/bicycle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB