mirror of
https://github.com/13hannes11/outyard-hackathon-rush-hour-co2.git
synced 2024-09-03 20:10:59 +02:00
add drawing of lanes
Co-authored-by: Laura Januleviciute <januleviciute.laura@gmail.com>
This commit is contained in:
18
Lane.py
Normal file
18
Lane.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Lane:
|
||||||
|
def __init__(self, posY, width, height, add_markings=True):
|
||||||
|
self.posX = 0
|
||||||
|
self.posY = posY
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.add_markings = add_markings
|
||||||
|
|
||||||
|
def draw(self, screen):
|
||||||
|
pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(self.posX, self.posY, self.width, self.height))
|
||||||
|
if self.add_markings:
|
||||||
|
for i in range(6):
|
||||||
|
pygame.draw.rect(screen, (70, 70, 70), pygame.Rect(self.posX + i * 150, self.posY + self.height-5, 70, 5))
|
||||||
|
|
||||||
|
def update(self, screen):
|
||||||
|
pass
|
||||||
30
main.py
30
main.py
@@ -5,6 +5,7 @@ from pygame.locals import *
|
|||||||
|
|
||||||
from Car import Car
|
from Car import Car
|
||||||
from Vacuum import Vacuum
|
from Vacuum import Vacuum
|
||||||
|
from Lane import Lane
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.font.init()
|
pygame.font.init()
|
||||||
@@ -20,16 +21,25 @@ TEXT_RECT = TEXT_SCREEN.get_rect(center=(SCREEN_WIDTH/2, SCREEN_HEIGHT/2))
|
|||||||
BUBBLE_LIMIT = 100
|
BUBBLE_LIMIT = 100
|
||||||
|
|
||||||
SCREEN = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
|
SCREEN = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||||
BACKGROUND = (0,0,0)
|
BACKGROUND = (70,70,70)
|
||||||
SCREEN.fill(BACKGROUND)
|
SCREEN.fill(BACKGROUND)
|
||||||
CLOCK = pygame.time.Clock()
|
CLOCK = pygame.time.Clock()
|
||||||
|
|
||||||
game_objects = []
|
game_objects = []
|
||||||
bubble_objects = []
|
bubble_objects = []
|
||||||
for i in range(4):
|
for i in range(3):
|
||||||
game_objects.append(Car(random.uniform(0, SCREEN_WIDTH), i * 80 + 10, bubble_objects, directionX=random.uniform(1, 5)))
|
markings = True
|
||||||
for i in range(4, 7):
|
if i == 2:
|
||||||
game_objects.append(Car(random.uniform(0, SCREEN_WIDTH), i * 80 + 10, bubble_objects, directionX= - random.uniform(1, 5)))
|
markings = False
|
||||||
|
game_objects.append(Lane(i * 80 + 50, SCREEN_WIDTH, 80, add_markings=markings))
|
||||||
|
game_objects.append(Car(random.uniform(0, SCREEN_WIDTH), i * 80 + 50, bubble_objects, directionX=random.uniform(1, 5)))
|
||||||
|
|
||||||
|
for i in range(3, 6):
|
||||||
|
markings = True
|
||||||
|
if i == 5:
|
||||||
|
markings = False
|
||||||
|
game_objects.append(Lane(i * 80 + 60, SCREEN_WIDTH, 80, add_markings=markings))
|
||||||
|
game_objects.append(Car(random.uniform(0, SCREEN_WIDTH), i * 80 + 60, bubble_objects, directionX= - random.uniform(1, 5)))
|
||||||
|
|
||||||
game_objects.append(Vacuum(bubble_objects))
|
game_objects.append(Vacuum(bubble_objects))
|
||||||
|
|
||||||
@@ -38,14 +48,14 @@ while True:
|
|||||||
pygame.display.set_caption("Rush Hour CO2")
|
pygame.display.set_caption("Rush Hour CO2")
|
||||||
|
|
||||||
if len(bubble_objects) < BUBBLE_LIMIT:
|
if len(bubble_objects) < BUBBLE_LIMIT:
|
||||||
for game_object in bubble_objects:
|
for game_object in game_objects:
|
||||||
game_object.update(SCREEN)
|
game_object.update(SCREEN)
|
||||||
for game_object in bubble_objects:
|
for game_object in game_objects:
|
||||||
game_object.draw(SCREEN)
|
game_object.draw(SCREEN)
|
||||||
|
|
||||||
for game_object in game_objects:
|
for game_object in bubble_objects:
|
||||||
game_object.update(SCREEN)
|
game_object.update(SCREEN)
|
||||||
for game_object in game_objects:
|
for game_object in bubble_objects:
|
||||||
game_object.draw(SCREEN)
|
game_object.draw(SCREEN)
|
||||||
else:
|
else:
|
||||||
# TODO game over screen with message to reduce driving cars
|
# TODO game over screen with message to reduce driving cars
|
||||||
|
|||||||
Reference in New Issue
Block a user