2024-03-25 00:05:56 +01:00
|
|
|
import pygame
|
2024-03-25 11:39:10 +01:00
|
|
|
from classes.Trash import *
|
2024-03-25 00:05:56 +01:00
|
|
|
|
|
|
|
|
2024-03-19 18:52:31 +01:00
|
|
|
class Garbagetruck:
|
|
|
|
|
2024-03-25 00:05:56 +01:00
|
|
|
def __init__(self, file="sprites/garbage_truck.png"):
|
2024-03-19 18:52:31 +01:00
|
|
|
self.capacity: int = 20
|
|
|
|
self.trash: list = []
|
|
|
|
self.trashweight: int = 0
|
2024-03-25 00:05:56 +01:00
|
|
|
self.image = pygame.image.load(file).convert_alpha()
|
2024-03-25 11:39:10 +01:00
|
|
|
self.image = pygame.transform.scale(self.image, (32, 32))
|
|
|
|
self.position = [3, 3]
|
2024-03-25 11:21:23 +01:00
|
|
|
self.predicts: set = set()
|
2024-03-25 11:39:10 +01:00
|
|
|
self.others: set = set()
|
2024-03-25 11:21:23 +01:00
|
|
|
self.state = None
|
2024-03-19 18:52:31 +01:00
|
|
|
self.route = None
|
|
|
|
self.scanner = None
|
|
|
|
self.planner = None
|
|
|
|
self.driver = None
|
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def getOthers(self):
|
|
|
|
return self.others
|
|
|
|
|
|
|
|
def setOthers(self, others):
|
|
|
|
self.others = others
|
|
|
|
return self
|
|
|
|
|
2024-03-25 11:21:23 +01:00
|
|
|
def setPredicts(self, predicts):
|
|
|
|
self.predicts = predicts
|
|
|
|
return self
|
|
|
|
|
|
|
|
def getPredicts(self):
|
|
|
|
return self.predicts
|
|
|
|
|
2024-03-19 18:52:31 +01:00
|
|
|
def getCapacity(self) -> int:
|
|
|
|
return self.capacity
|
|
|
|
|
|
|
|
def getTrash(self) -> list:
|
|
|
|
return self.trash
|
|
|
|
|
|
|
|
def setTrash(self, trash: list) -> None:
|
|
|
|
self.trash = trash
|
|
|
|
for item in trash:
|
2024-03-25 11:39:10 +01:00
|
|
|
self.addTrashweight(item.getWaga)
|
2024-03-19 18:52:31 +01:00
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def addTrash(self, trash: Trash) -> None:
|
2024-03-19 18:52:31 +01:00
|
|
|
self.trash.append(trash)
|
2024-03-25 11:39:10 +01:00
|
|
|
self.addTrashweight(trash.getWaga())
|
2024-03-19 18:52:31 +01:00
|
|
|
|
|
|
|
def removeTrash(self, trashid: int) -> object:
|
|
|
|
trash = self.trash.pop(trashid)
|
|
|
|
self.addTrashweight(trash.getWeight * (-1))
|
|
|
|
return trash
|
|
|
|
|
|
|
|
def getTrashweight(self) -> int:
|
|
|
|
return self.trashweight
|
|
|
|
|
|
|
|
def setTrashweight(self, weight: int) -> None:
|
|
|
|
self.trashweight = weight
|
|
|
|
|
|
|
|
def addTrashweight(self, weight: int) -> None:
|
|
|
|
self.trashweight += weight
|
|
|
|
|
|
|
|
def getImage(self) -> object:
|
|
|
|
return self.image
|
|
|
|
|
|
|
|
def setImage(self, image: object) -> None:
|
|
|
|
self.image = image
|
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def getPosition(self) -> list:
|
2024-03-19 18:52:31 +01:00
|
|
|
return self.position
|
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def setPosition(self, position: list) -> object:
|
2024-03-19 18:52:31 +01:00
|
|
|
self.position = position
|
2024-03-25 11:39:10 +01:00
|
|
|
return self
|
|
|
|
|
|
|
|
def modPosiotion(self, modX, modY):
|
|
|
|
x = self.getPosition()[0] + modX
|
|
|
|
y = self.getPosition()[1] + modY
|
|
|
|
self.setPosition([x, y])
|
2024-03-19 18:52:31 +01:00
|
|
|
|
|
|
|
def getRoute(self):
|
|
|
|
return self.route
|
|
|
|
|
|
|
|
def setRoute(self, route) -> None:
|
|
|
|
self.route = route
|
|
|
|
|
|
|
|
def getScanner(self):
|
|
|
|
return self.scanner
|
|
|
|
|
|
|
|
def setScanner(self, scanner) -> None:
|
|
|
|
self.route = scanner
|
|
|
|
|
|
|
|
def getPlanner(self):
|
|
|
|
return self.planner
|
|
|
|
|
|
|
|
def setPlanner(self, planner) -> None:
|
|
|
|
self.route = planner
|
|
|
|
|
|
|
|
def getDriver(self):
|
|
|
|
return self.driver
|
|
|
|
|
|
|
|
def setDriver(self, driver) -> None:
|
|
|
|
self.route = driver
|
2024-03-25 11:39:10 +01:00
|
|
|
|
|
|
|
def distance(self, object1, object2) -> int:
|
|
|
|
lok1 = object1.getPosition()
|
|
|
|
lok2 = object2.getPosition()
|
|
|
|
|
|
|
|
dist = abs(lok1[0] - lok2[0]) + abs(lok1[1] - lok2[1])
|
|
|
|
return dist
|