Update inventory.py
parent
754ffcd5d9
commit
2ff1f83c24
17
inventory.py
17
inventory.py
|
|
@ -1,6 +1,6 @@
|
|||
import pygame
|
||||
from settings import *
|
||||
from items import ITEMS, get_item
|
||||
from items import get_item
|
||||
|
||||
|
||||
class Inventory:
|
||||
|
|
@ -25,6 +25,13 @@ class Inventory:
|
|||
else:
|
||||
self.slots[item_id] = amount
|
||||
|
||||
def remove_item(self, item_id, amount=1):
|
||||
"""Remove item from inventory"""
|
||||
if item_id in self.slots:
|
||||
self.slots[item_id] -= amount
|
||||
if self.slots[item_id] <= 0:
|
||||
del self.slots[item_id]
|
||||
|
||||
def draw(self, screen):
|
||||
font = pygame.font.SysFont("consolas", 18)
|
||||
title_font = pygame.font.SysFont("consolas", 24)
|
||||
|
|
@ -88,3 +95,11 @@ class Inventory:
|
|||
screen.blit(tooltip, (mouse[0] + 10, mouse[1] + 10))
|
||||
|
||||
index += 1
|
||||
screen.blit(amount_text, (cell_rect.x + 2, cell_rect.y + 2))
|
||||
|
||||
# Tooltip on hover
|
||||
if cell_rect.collidepoint(mouse):
|
||||
tooltip = font.render(item.name, True, (255, 255, 0))
|
||||
screen.blit(tooltip, (mouse[0] + 10, mouse[1] + 10))
|
||||
|
||||
index += 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue