diff --git a/src/item.py b/src/item.py index 4be10a6..4fa2ec1 100644 --- a/src/item.py +++ b/src/item.py @@ -30,7 +30,7 @@ def _random_position(room_rect, blocked_rects): return x, y attempts += 1 - + # no spot after 50 attempts -> return return None @@ -46,3 +46,33 @@ def update(self, room_rect, blocked_rects): # replace the old list with the new temp_list self.items = remaining_items + + +class Item: + def __init__(self, x, y, item_type): + self.x = x + self.y = y + self.item_type = item_type + + # collision rect for player (2 times item size for width and height) + self.rect = pygame.Rect(self.x, self.y, ITEM_SIZE, ITEM_SIZE) + + # timer to store time when item appeared + self.spawn_time = pygame.time.get_ticks() + + # try to load sprite + try: + path = f"assets/items/{item_type}.png" + self.image = pygame.image.load(path).convert_alpha() + self.image = pygame.transform.scale(self.image, (ITEM_SIZE, ITEM_SIZE)) + except Exception as e: + print(f"Error loading item sprite {item_type}: {e}") + self.image = None + + + + + + + +