Madra_smieciarka/main.py
2024-03-11 14:55:22 +01:00

101 lines
3.5 KiB
Python

import pygame
import random
from classes import *
from QOLfunc import *
pygame.init()
screen = pygame.display.set_mode((1800, 1000))
colors = {
"white": (255, 255, 255),
"black": (0, 0, 0),
"red": (255, 0, 0)
}
garbage_truck_image = pygame.image.load('garbage_truck.png')
trash_can_images = {
'paper': pygame.image.load('trash_can_papier.jpg').convert_alpha(),
'metals_and_plastics': pygame.image.load('trash_can_metale_plastik.jpg').convert_alpha(),
'mixed': pygame.image.load('trash_can_zmieszane.jpg').convert_alpha(),
'bio_waste': pygame.image.load('trash_can_bio.jpg').convert_alpha(),
'glass': pygame.image.load('trash_can_szklo.jpg').convert_alpha(),
}
new_garbage_truck_size = (120, 120)
new_trash_can_size = (90, 90)
new_house_size = (140, 120)
garbage_truck_image = garbage_truck_image.convert_alpha()
garbage_truck_image = pygame.transform.scale(garbage_truck_image, new_garbage_truck_size)
for key in trash_can_images:
trash_can_images[key] = pygame.transform.scale(trash_can_images[key], new_trash_can_size)
garbage_truck_position = [800, 500]
trash_cans = [
{'position': (1600, 300), 'type': 'paper'},
{'position': (1600, 500), 'type': 'metals_and_plastics'},
{'position': (1600, 700), 'type': 'mixed'},
{'position': (1600, 900), 'type': 'bio_waste'},
{'position': (1600, 100), 'type': 'glass'},
]
junkyard = Junkyard()
trashcans = []
typelist = ["paper", "metals_and_plastics", "mixed", "bio_waste", "glass"]
for i in range(5):
trashcan = Trashcan(i, trash_can_images[typelist[i]], trash_cans[i]["position"], trash_cans[i]["type"])
trashcan.addNeighbour(junkyard)
junkyard.addNeighbour(trashcan)
trashcans.append(trashcan)
houses = []
house_positions = [(450, 100), (250, 250), (200, 700), (850, 800), (1000, 200), (1050, 700), (800, 100), (400, 850)]
for i in range(8):
house_image = pygame.image.load(f'house_{i}.jpg')
house_image = pygame.transform.scale(house_image, new_house_size)
house = Household(i, house_image, house_positions[i])
houses.append(house)
for i in range(len(houses)):
if i%2 == 0:
neigh = chooseNeighbours(2, i)
else:
neigh = chooseNeighbours(3, i)
for num in neigh:
if len(houses[i].getNeighbours()) < 3 and len(houses[num].getNeighbours()) < 3:
houses[i].addNeighbour(houses[num])
houses[num].addNeighbour(houses[i])
if i == 7 or i == 1:
houses[i].addNeighbour(junkyard)
junkyard.addNeighbour(houses[i])
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# garbage_truck_position[0] += random.randint(-4, 4)
# garbage_truck_position[1] += random.randint(-4, 4)
screen.fill(colors["white"])
for trash_can in trashcans:
for neighbour in trash_can.getNeighbours():
pygame.draw.line(screen, colors["black"], trash_can.getPosition(), neighbour.getPosition(), 3)
screen.blit(trash_can.getImage(), trash_can.getPosition())
for house in houses:
for neighbour in house.getNeighbours():
if neighbour.getId() < house.getId():
pygame.draw.line(screen, colors["black"], house.getPosition(), neighbour.getPosition(), 3)
for house in houses:
screen.blit(house.getImage(), house.getPosition())
pygame.draw.circle(screen, colors["red"], junkyard.getPosition(), 10)
screen.blit(garbage_truck_image, junkyard.getPosition())
pygame.display.flip()
pygame.quit()