def __init__(self, coordinate, screen_w: int, screen_h: int): super().__init__(screen_w, screen_h) self.color0 = (82, 33, 0, 50) self.color1 = (65, 33, 0, 0) self.color2 = (90, 40, 0, 0) self.rectangle = Rectangle(coordinate) self.resize(screen_w, screen_h)
class Recipe_widget(Object_display): def __init__(self, w, h, recipe): super().__init__(w, h) self.coordinate = Rectangle((0.75, 0.1, 0.9, 0.7)) self.recipe = recipe self.recipe_widget = [] self.position = self.coordinate.copy() self.position = self.position * Point((w, h)) self.recipe_widget.append( List_recipe(self.coordinate, w, h, self.recipe.name, is_title=True)) for i, product in enumerate(self.recipe.ingredient): self.recipe_widget.append( Product_list(self.coordinate, product, i + 1, w, h)) self.button = Button_ok(self.coordinate, w, h, recipe) self.recipe_widget.append(self.button) def draw(self): pygame.draw.rect(self.screen, (150, 160, 200), (self.position.to_rectangle())) for i in self.recipe_widget: i.draw() def resize(self, w: int, h: int): self.position = self.coordinate.copy() self.position = self.position * Point((w, h)) for i in self.recipe_widget: i.resize(w, h) def click(self, event): return self.button.click(event)
def __init__(self, w: int, h: int, cord: tuple): super().__init__(w, h) self.par = Rectangle(cord) self.counter_cor = Rectangle((0.8, 0.9, 1, 0.99)) self.price = Price() self.resize(w, h) pygameAssets.Button.screen = self.screen self.elements = []
def __init__(self, w, h, coordinate): super().__init__(w, h) self.coordinate = Rectangle(coordinate) self.position = self.coordinate * Point((w, h)) self.nominal = [50, 20, 10, 5, 2, 1] self.zl_count = [] self.gr_count = [] self.coins = []
def __init__(self, coordinate: tuple, w: int, h: int, product: Product_data): super().__init__(product.price) self.product = product self.number = product.number_recipe c = Rectangle(coordinate) for i in range(self.product.number): self.images.append(Product_image(copy.deepcopy(c.get_coordinate()), w, h, product=product, name=product.name)) c.move(Point((-0.004, -0.008)))
def __init__(self, coordinate, w, h): super().__init__(w, h) self.on_counter = False self.start_coordinate = Rectangle(coordinate) self.position = self.start_coordinate.copy() * Point((self.screen_w, self.screen_h)) #self.position.move(Point((random.randint(50, 70), random.randint(0, 10)))) self.im = pygame.transform.scale(self.image, self.position.size.to_int()) self.dp = Point((0, 0)) self.is_clicked = False
def __init__(self, id: int, coordinate: tuple, screen_w: int, screen_h: int): super().__init__(screen_w, screen_h) self.id = id self.rectangle = Rectangle(coordinate) self.image = Shelf_image(coordinate, screen_w, screen_h) self.product = [] self.nmbr_product = 0 self.product_start = self.rectangle.copy() self.product_start.setsize(self.product_start.size.x / 5, self.product_start.size.x / 5 * screen_w / screen_h) self.product_start.move(Point((self.product_start.size.x * 0.8, -self.product_start.size.y * 0.5)))
class Recipe_button(Object_display): def __init__(self, receipe: Recipe_data, w: int, h: int): Button.screen = Object_display.screen super().__init__(w, h) self.receipe = receipe self.ID = int(receipe.id) self.color = (100, 0, 0) if receipe.difficulty == 0: self.color = (0, 80, 0) elif receipe.difficulty == 1: self.color = (80, 90, 0) self.resize(w, h) def draw(self) -> None: if self.receipe.completed: clr = (50, 255, 50) else: clr = (255, 50, 50) pygame.draw.rect(Object_display.screen, clr, self.frame.to_rectangle(), 0) self.button.draw() def click(self, pos: tuple) -> bool: return self.frame.is_in_area(Point(pos)) def run(self): Object_display.data.insert_product_to_receipe(self.receipe.id) Level(self.receipe.id).run() def resize(self, w, h): self.frame = Rectangle((0, 0, w // 10, w // 10)) self.frame.move( Point((self.frame.size.x * (self.ID % 10), self.frame.size.y * (self.ID // 10)))) self.frame.scale( Point((self.frame.size.x // 10, self.frame.size.y // 10))) self.square = self.frame.copy() self.square.scale( Point((self.square.size.x // 20, self.square.size.y // 20))) self.square.move( Point((self.square.size.x // 2, self.square.size.y // 2))) self.button = Button(self.square.point.x, self.square.point.y, self.square.size.x, self.square.size.y, text=self.receipe.name, color=self.color)
class Shelf_image(Object_display): def __init__(self, coordinate, screen_w: int, screen_h: int): super().__init__(screen_w, screen_h) self.color0 = (82, 33, 0, 50) self.color1 = (65, 33, 0, 0) self.color2 = (90, 40, 0, 0) self.rectangle = Rectangle(coordinate) self.resize(screen_w, screen_h) def resize(self, w, h): self.screen_w, self.screen_h = w, h rec = self.rectangle.copy() * Point((w, h)) self.tempx = (rec.end_coordinate.y - rec.point.y) / math.tan(0.5) temp_depth = (rec.end_coordinate.y - rec.point.y) * 0.3 self.points0 = numpy.array([(rec.point.x, rec.point.y), (rec.end_coordinate.x, rec.point.y), (rec.end_coordinate.x + self.tempx, rec.end_coordinate.y), (rec.point.x + self.tempx, rec.end_coordinate.y)]) self.points1 = numpy.array([(rec.point.x, rec.point.y), (rec.point.x + self.tempx, rec.end_coordinate.y), (rec.point.x + self.tempx, rec.end_coordinate.y + temp_depth), (rec.point.x, rec.point.y + temp_depth)]) self.points2 = numpy.array([(rec.point.x + self.tempx, rec.end_coordinate.y), (rec.end_coordinate.x + self.tempx, rec.end_coordinate.y), (rec.end_coordinate.x + self.tempx, rec.end_coordinate.y + temp_depth), (rec.point.x + self.tempx, rec.end_coordinate.y + temp_depth)]) def draw(self): surface = pygame.display.get_surface() pygame.draw.polygon(surface, self.color0, self.points0) pygame.draw.polygon(surface, self.color1, self.points1) pygame.draw.polygon(surface, self.color2, self.points2)
def __init__(self, w, h, recipe): super().__init__(w, h) self.coordinate = Rectangle((0.75, 0.1, 0.9, 0.7)) self.recipe = recipe self.recipe_widget = [] self.position = self.coordinate.copy() self.position = self.position * Point((w, h)) self.recipe_widget.append( List_recipe(self.coordinate, w, h, self.recipe.name, is_title=True)) for i, product in enumerate(self.recipe.ingredient): self.recipe_widget.append( Product_list(self.coordinate, product, i + 1, w, h)) self.button = Button_ok(self.coordinate, w, h, recipe) self.recipe_widget.append(self.button)
class Counter(Object_display): def __init__(self, w: int, h: int, cord: tuple): super().__init__(w, h) self.par = Rectangle(cord) self.counter_cor = Rectangle((0.8, 0.9, 1, 0.99)) self.price = Price() self.resize(w, h) pygameAssets.Button.screen = self.screen self.elements = [] def draw(self) -> None: pygame.draw.rect(Object_display.screen, (0, 153, 153), self.position.to_rectangle()) self.counter.draw() def resize(self, w: int, h: int) -> None: self.position = self.par.copy() * Point((w, h)) self.counter_pos = self.counter_cor.copy() * Point((w, h)) self.counter = pygameAssets.Button(self.counter_pos[0], self.counter_pos[1], self.counter_pos[2], self.counter_pos[3], color=(0, 0, 0), text=str(self.price)) def test_product(self, element: Element, lay: bool = None) -> None: if self.position.is_in_area(element.current_image.position.point): if lay is True: self.elements.append(element.current_image) element.current_image.on_counter = True element.lay() elif lay is False: element.current_image.on_counter = False self.elements.remove(element.current_image) self.price.clear() for i in self.elements: if i.on_counter: self.price += i.price self.counter.setText(str(self.price)) else: element.current_image.on_counter = False if lay is True: element.lay()
def resize(self, w, h): self.frame = Rectangle((0, 0, w // 10, w // 10)) self.frame.move( Point((self.frame.size.x * (self.ID % 10), self.frame.size.y * (self.ID // 10)))) self.frame.scale( Point((self.frame.size.x // 10, self.frame.size.y // 10))) self.square = self.frame.copy() self.square.scale( Point((self.square.size.x // 20, self.square.size.y // 20))) self.square.move( Point((self.square.size.x // 2, self.square.size.y // 2))) self.button = Button(self.square.point.x, self.square.point.y, self.square.size.x, self.square.size.y, text=self.receipe.name, color=self.color)
class Moveable_object(Object_display): def __init__(self, coordinate, w, h): super().__init__(w, h) self.on_counter = False self.start_coordinate = Rectangle(coordinate) self.position = self.start_coordinate.copy() * Point((self.screen_w, self.screen_h)) #self.position.move(Point((random.randint(50, 70), random.randint(0, 10)))) self.im = pygame.transform.scale(self.image, self.position.size.to_int()) self.dp = Point((0, 0)) self.is_clicked = False def resize(self, w: int, h: int) -> None: self.position = self.position * Point((1 / self.screen_w, 1 / self.screen_h)) self.position = self.position * Point((w, h)) self.im = pygame.transform.scale(self.image, self.position.size.to_int()) self.screen_w, self.screen_h = w, h def draw(self) -> None: Object_display.screen.blit(self.im, self.position.point.to_int()) def click(self, pos: tuple): if self.position.is_in_area(Point(pos)): self.is_clicked = True self.cursor = Point(pos) return self def lay(self) -> None: self.position = self.start_coordinate.copy() self.position = self.position * Point((self.screen_w, self.screen_h)) self.is_clicked = False def move(self, pos: tuple): if self.is_clicked: point = Point(pos) self.dp = Point(pos) - self.cursor self.position.move(self.dp) self.cursor = point
def __init__(self, screen_w, screen_h, count, recipe): self.screen_w = screen_w self.screen_h = screen_h self.recipe = recipe self.label = TextBox(screen_w // 2, 50, "Do zapłaty: " + str(count), color=(150, 200, 200)) self.counter = Counter(screen_w, screen_h, (0.3, 0.1, 0.7, 0.5)) self.pocket = Pocket(screen_w, screen_h, (0.4, 0.6, 0.7, 0.8)) self.pocket.count(copy.deepcopy(count)) self.pocket.create() from button import Button_pay self.button = Button_pay(Rectangle((0.85, 0.85, 1, 1)), screen_w, screen_h, count)
class Pocket(Object_display): def __init__(self, w, h, coordinate): super().__init__(w, h) self.coordinate = Rectangle(coordinate) self.position = self.coordinate * Point((w, h)) self.nominal = [50, 20, 10, 5, 2, 1] self.zl_count = [] self.gr_count = [] self.coins = [] def count(self, sum): self.price = sum.copy() for i in self.nominal: zl_temp = sum.zl // i gr_temp = sum.gr // i self.zl_count.append(zl_temp) self.gr_count.append(gr_temp) sum.zl -= zl_temp * i sum.gr -= gr_temp * i def create(self): coordinate = self.coordinate.copy() coordinate.setsize(self.coordinate.size.x - 0.1, self.coordinate.size.y - 0.1) for idx, nom in enumerate(self.nominal): self.coins.append(Coin(self.screen_w, self.screen_h, coordinate, values=Price(nom), number=self.zl_count[idx])) self.coins.append(Coin(self.screen_w, self.screen_h, coordinate, values=Price(nom / 100), number=self.gr_count[idx])) def draw(self): pygame.draw.rect(Object_display.screen, (50, 205, 50), self.position.to_rectangle()) for i in self.coins: i.draw() def resize(self, w, h): self.position = self.coordinate * Point((w, h)) for i in self.coins: i.resize(w, h) def click(self, event=None, pos=None): if event is not None: pass if pos is not None: for i in self.coins: coin = i.click(pos) if coin is not None: return coin
def __init__(self, rec: Rectangle, w: int, h: int, name: str, i: int = 0, fontsize: int = 40, is_title: bool = False): super().__init__(w, h) self.coordinate = rec.copy() self.coordinate.move( Point((self.coordinate.size.x / 2, 0.05 * (i + 1)))) if is_title is True: self.name = name.upper() else: self.name = name self.font_size = fontsize self.resize(w, h)
class Shelf(Object_display): def __init__(self, id: int, coordinate: tuple, screen_w: int, screen_h: int): super().__init__(screen_w, screen_h) self.id = id self.rectangle = Rectangle(coordinate) self.image = Shelf_image(coordinate, screen_w, screen_h) self.product = [] self.nmbr_product = 0 self.product_start = self.rectangle.copy() self.product_start.setsize(self.product_start.size.x / 5, self.product_start.size.x / 5 * screen_w / screen_h) self.product_start.move(Point((self.product_start.size.x * 0.8, -self.product_start.size.y * 0.5))) def draw(self): self.image.draw() for i in self.product: i.draw() def add_product(self, product: Product_data): if self.nmbr_product > 3: return p = Product(self.product_start.get_coordinate(), self.screen_w, self.screen_h, product) p.check() self.product.append(p) self.product_start.move(Point((self.product_start.size.x * 1.3, 0))) self.nmbr_product += 1 def resize(self, w:int, h:int): self.image.resize(w, h) for i in self.product: i.resize(w, h) def click(self, pos:tuple): for i in self.product: product = i.click(pos) if product is not None: self.is_clicked = True return product self.is_clicked = False
def __init__(self, w: int, h: int, coordinate: Rectangle): super().__init__(w, h) self.coordinate: Rectangle = coordinate.copy() pygameAssets.Button.setScreen(Object_display.screen)