Madra_smieciarka/main.py

68 lines
2.3 KiB
Python
Raw Normal View History

import time
2024-03-10 14:32:06 +01:00
import classes.Household
from generators import *
W = 30
H = 20
MULT = 50
SIZE = (MULT*W, MULT*H)
2024-03-10 14:32:06 +01:00
pygame.init()
2024-03-25 11:21:23 +01:00
screen = pygame.display.set_mode(SIZE)
tilemap = Tilemap(Tileset("sprites/TIles/1 Tiles/FieldsTile_38.png", mult=MULT), mult=MULT, size=(W, H))
targimage = pygame.image.load("sprites/X.png").convert_alpha()
targimage = pygame.transform.scale(targimage, (MULT, MULT))
2024-03-10 18:04:48 +01:00
trashcans = trashcanGenerator(MULT)
houses = householdGenerator(MULT)
garbagetruck = Garbagetruck(MULT).setHouses(houses).setTrashcans(trashcans)
garbagetruck.setFirstTarget()
# print("Kolejność danych do drzewa:")
# print("Pora roku - Pora dnia - Typ śmieci - Zapełnienie kosza - Zapełnienie śmieciarki - Zapłacone - Ostatnio zabrane "
# "- Pogoda")
2024-03-10 14:32:06 +01:00
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
garbagetruck.executeMovement()
2024-03-25 11:21:23 +01:00
screen.fill((0, 0, 0))
tilemap.render(MULT)
2024-03-25 11:21:23 +01:00
screen.blit(tilemap.image, tilemap.rect)
for i in trashcans:
screen.blit(i.getImage(), i.printme())
for h in houses:
screen.blit(h.getImage(), h.printme())
bruh = garbagetruck.target
bruhlist = [i*MULT for i in bruh]
screen.blit(targimage, bruhlist)
screen.blit(garbagetruck.getImage(), garbagetruck.printme())
2024-03-25 11:21:23 +01:00
pygame.display.update()
garbagetruck.scanTile()
state = garbagetruck.getState()
garbagetruck.goDumpTrash()
# print(type(state))
while garbagetruck.getAnalising():
garbagetruck.pickTrash()
if not garbagetruck.movesequence:
moves = garbagetruck.graphsearch()
garbagetruck.setMovesequence(moves)
if state:
if isinstance(state, classes.Household.Household) and state.getFinal():
# print([trash.getTtype() for trash in state.getGarbage().getContent()])
garbagetruck.switchAnalising()
garbagetruck.getState().switchFinal()
elif isinstance(state, classes.Trashcan.Trashcan) and state.getFinal():
print("Wyrzucam")
garbagetruck.throwGarbage()
print([trash.getTtype() for trash in garbagetruck.getTrash()])
garbagetruck.getState().switchFinal()
if not garbagetruck.movesequence and not garbagetruck.getAnalising():
garbagetruck.setTarget()
time.sleep(0.25)
2024-03-10 14:32:06 +01:00
pygame.quit()