feat(item): add cost attribute and getter function
This commit is contained in:
+5
-1
@@ -11,6 +11,7 @@ class Item:
|
|||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.item_type = item_type
|
self.item_type = item_type
|
||||||
|
self.cost = random.randint(5, 10)
|
||||||
|
|
||||||
# collision rect for player (2 times item size for width and height)
|
# collision rect for player (2 times item size for width and height)
|
||||||
self.rect = pygame.Rect(self.x, self.y, ITEM_SIZE, ITEM_SIZE)
|
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, draw_rect)
|
||||||
pygame.draw.rect(screen, COLOR_HP_BAR_BG, draw_rect, 2)
|
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
|
# try 50 times to find a free position to spawn item
|
||||||
def _random_position(room_rect, blocked_rects):
|
def _random_position(room_rect, blocked_rects):
|
||||||
@@ -130,4 +134,4 @@ class ItemManager:
|
|||||||
# clear items when changing room
|
# clear items when changing room
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.items = []
|
self.items = []
|
||||||
self.last_spawn_time = pygame.time.get_ticks()
|
self.last_spawn_time = pygame.time.get_ticks()
|
||||||
|
|||||||
Reference in New Issue
Block a user