Update inventory.py

main
Rihards Ševčuks 2026-02-25 06:24:04 +00:00
parent 754ffcd5d9
commit 2ff1f83c24
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import pygame import pygame
from settings import * from settings import *
from items import ITEMS, get_item from items import get_item
class Inventory: class Inventory:
@ -25,6 +25,13 @@ class Inventory:
else: else:
self.slots[item_id] = amount 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): def draw(self, screen):
font = pygame.font.SysFont("consolas", 18) font = pygame.font.SysFont("consolas", 18)
title_font = pygame.font.SysFont("consolas", 24) title_font = pygame.font.SysFont("consolas", 24)
@ -88,3 +95,11 @@ class Inventory:
screen.blit(tooltip, (mouse[0] + 10, mouse[1] + 10)) screen.blit(tooltip, (mouse[0] + 10, mouse[1] + 10))
index += 1 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