feat(item): add cost attribute and getter function

This commit is contained in:
Niklas Haiden
2026-05-08 16:43:55 +02:00
parent 6463d3d215
commit 538be47bc5
+4
View File
@@ -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):