grid works + little adjustments

Signed-off-by: Neerka <jakub.markil1@gmail.com>
This commit is contained in:
Neerka 2024-03-25 14:26:41 +01:00
parent 82a1b0a82c
commit e02adf16b6
7 changed files with 36 additions and 18 deletions

View File

@ -7,15 +7,6 @@ colors = {
"red": (255, 0, 0)
}
def extractPredicts(houses: list) -> set:
preds = set()
for house in houses:
temp = [house, house.getGarbage().getPredict()]
preds.add(temp)
return preds
def allLocations(*lista):
final = set()
for _ in lista:

View File

@ -9,6 +9,7 @@ class Garbage:
self.prob: float = 0.3
self.generatePredict()
self.generateContent()
self.predict = tuple(self.predict)
def getContent(self):
return self.content
@ -55,7 +56,7 @@ class Garbage:
del bruh
def generateContent(self):
mod = random.choice([1, -1])
self.setContent(self.predict[:])
if random.random() < self.prob:
mod = random.choice([1, -1])
self.generatePredict(mod)

View File

@ -1,5 +1,6 @@
import pygame
from classes.Trash import *
from classes.Household import *
from classes.Trashcan import *
class Garbagetruck:
@ -13,7 +14,7 @@ class Garbagetruck:
self.position = [3, 3]
self.predicts: set = set()
self.others: set = set()
self.state = None
self.state = 0
self.route = None
self.scanner = None
self.planner = None
@ -110,3 +111,14 @@ class Garbagetruck:
dist = abs(lok1[0] - lok2[0]) + abs(lok1[1] - lok2[1])
return dist
def scanTile(self):
self.state = 0
for loc in self.others:
if tuple(self.position) == loc.getPosition():
self.state = loc
return
def printme(self):
x, y = self.getPosition()
return 32*x, 32*y

View File

@ -36,6 +36,10 @@ class Household:
def getGarbage(self):
return self.garbage
def printme(self):
x, y = self.getPosition()
return 32*x, 32*y
def generateHousehold(i, image, position):
"""

View File

@ -33,6 +33,10 @@ class Trashcan:
def getId(self):
return self.id
def printme(self):
x, y = self.getPosition()
return 32*x, 32*y
def generateTrashcan(newId, image, position, trashtype):
"""

View File

@ -38,7 +38,7 @@ def householdGenerator():
house_positions = [(15, 5), (17, 5), (19, 5), (21, 5), (15, 8), (17, 8), (19, 8), (21, 8)]
houses = []
for i in range(8):
house_image = pygame.image.load(f'sprites/house_{i}.jpg')
house_image = pygame.image.load(f'sprites/domek.png')
house_image = pygame.transform.scale(house_image, new_house_size)
house = generateHousehold(i, house_image, house_positions[i])
houses.append(house)

16
main.py
View File

@ -1,15 +1,16 @@
from generators import *
W = 960
H = 640
SIZE = (W, H)
W = 30
H = 20
MULT = 32
SIZE = (MULT*W, MULT*H)
pygame.init()
screen = pygame.display.set_mode(SIZE)
tilemap = Tilemap(Tileset("sprites/Tiles/1 Tiles/FieldsTile_38.png"), (30, 20))
tilemap = Tilemap(Tileset("sprites/Tiles/1 Tiles/FieldsTile_38.png"), (W, H))
trashcans = trashcanGenerator()
houses = householdGenerator()
garbagetruck = Garbagetruck().setPredicts(extractPredicts(houses)).setOthers(allLocations(trashcans, houses))
garbagetruck = Garbagetruck().setPredicts(houses).setOthers(allLocations(trashcans, houses))
running = True
while running:
@ -20,6 +21,11 @@ while running:
screen.fill((0, 0, 0))
tilemap.render()
screen.blit(tilemap.image, tilemap.rect)
screen.blit(garbagetruck.getImage(), garbagetruck.printme())
for i in trashcans:
screen.blit(i.getImage(), i.printme())
for h in houses:
screen.blit(h.getImage(), h.printme())
pygame.display.update()
pygame.quit()