feature: item
- add Item base class with collision rect, spawn timer, and sprite loading
This commit is contained in:
+30
@@ -46,3 +46,33 @@ def update(self, room_rect, blocked_rects):
|
|||||||
|
|
||||||
# replace the old list with the new temp_list
|
# replace the old list with the new temp_list
|
||||||
self.items = remaining_items
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user