-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.py
43 lines (33 loc) · 1.49 KB
/
inventory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pyray
class Inventory:
def __init__(self):
self.items = []
self.selected_index = 0
def add_item(self, item):
self.items.append(item)
def remove_item(self, item):
self.items.remove(item)
def select_next_item(self):
self.selected_index = (self.selected_index + 1) % len(self.items)
def select_previous_item(self):
self.selected_index = (self.selected_index - 1) % len(self.items)
def get_selected_item(self):
if self.items:
return self.items[self.selected_index]
return None
def render(self, screen_width, screen_height):
hotbar_width = screen_width//2
hotbar_height = screen_height//15
item_width = hotbar_width // len(self.items)
hotbar_x = (screen_width - hotbar_width) // 2
hotbar_y = screen_height - hotbar_height - 10
for i, item in enumerate(self.items):
item_x = hotbar_x + i * item_width
item_y = hotbar_y
color = pyray.GRAY if i == self.selected_index else pyray.DARKGRAY
pyray.draw_rectangle(item_x, item_y, item_width, hotbar_height, color)
pyray.draw_text(item.name, item_x + 10, item_y + 10, 20, pyray.WHITE)
if hasattr(item, 'ammo'):
pyray.draw_text(f"Ammo: {item.ammo}", item_x + 10, item_y + 30, 20, pyray.RED)
if i == self.selected_index:
pyray.draw_rectangle_lines(item_x, item_y, item_width, hotbar_height, pyray.YELLOW)