From 538be47bc5c37ead0dcf1d911fc47bc6d027aba3 Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Fri, 8 May 2026 16:43:55 +0200 Subject: [PATCH] feat(item): add cost attribute and getter function --- src/item.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/item.py b/src/item.py index e0cec9e..09be957 100644 --- a/src/item.py +++ b/src/item.py @@ -11,6 +11,7 @@ class Item: self.x = x self.y = y self.item_type = item_type + self.cost = random.randint(5, 10) # collision rect for player (2 times item size for width and height) self.rect = pygame.Rect(self.x, self.y, ITEM_SIZE, ITEM_SIZE) @@ -50,6 +51,9 @@ class Item: pygame.draw.rect(screen, color, draw_rect) pygame.draw.rect(screen, COLOR_HP_BAR_BG, draw_rect, 2) + def get_cost(self): + return self.cost + # try 50 times to find a free position to spawn item def _random_position(room_rect, blocked_rects): @@ -130,4 +134,4 @@ class ItemManager: # clear items when changing room def clear(self): self.items = [] - self.last_spawn_time = pygame.time.get_ticks() \ No newline at end of file + self.last_spawn_time = pygame.time.get_ticks()