-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventorySlot.py
109 lines (86 loc) · 3.41 KB
/
InventorySlot.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pygame
import pygame.font
class InventorySlot:
def __init__(self,itemID,image,item,amount,durability):
pygame.font.init()
LENGTH = 1216
WIDTH = 704
TILE_SIZE = 64
self.display = False
self.itemID = itemID
self.amount = amount
self.percantage = 1
self.width = 64
self.height = 20
self.green = pygame.Rect(LENGTH/2 - (TILE_SIZE * 1.5),WIDTH/2 + self.width - (TILE_SIZE * 0.5),self.width,self.height)
self.red = pygame.Rect(LENGTH/2 - (TILE_SIZE * 1.5),WIDTH/2 + self.width - (TILE_SIZE * 0.5),self.width,self.height)
self.image = pygame.image.load(image).convert_alpha()
self.rect = self.image.get_rect()
self.rect.topleft = (0, 64)
self.font = pygame.font.Font('freesansbold.ttf',16)
self.item = item
self.selected = False
self.startingDurability = durability
self.durability = durability
self.durabilityStatus = True
def getImage(self):
return self.image
def getID(self):
return self.itemID
def getSelection(self):
return self.selected
def updateSelection(self,bool):
self.selected = bool
def updateDurability(self,x):
LENGTH = 1216
WIDTH = 704
TILE_SIZE = 64
print(self.durability)
if (x + self.durability) <= 0 and self.amount > 1: #if we run out of durability but still have the item
self.durability = self.startingDurability
self.amount -= 1
elif (x + self.durability) <= 0 and self.amount <= 1: #if we run out of durability and dont have anymore items
self.durabilityStatus = False
else: #if we arent out yet
self.durability += x
#sets the durability
self.percantage = self.durability/self.startingDurability
if self.percantage == 1:
self.green = pygame.Rect(LENGTH/2 - (TILE_SIZE * 1.5),WIDTH/2 + self.width - (TILE_SIZE * 0.5),self.width,self.height)
else:
#print(64 * self.percantage)
difference = self.width * self.percantage
self.green = pygame.Rect(LENGTH/2 - (TILE_SIZE * 1.5),WIDTH/2 + self.width - (TILE_SIZE * 0.5),difference,self.height)
def geDurability(self):
return self.durability
def getDurabilityStatus(self):
return self.durabilityStatus
def renderObject(self,display):
self.item.render(display)
def setObject(self,x,y):
self.item.set(x,y)
def updateObject(self,x,y):
self.item.update(x,y)
def getObject(self):
return self.item
def getObjectX(self):
return (self.item).getX()
def getObjectY(self):
return (self.item).getY()
def updateAmount(self,x):
self.amount += x
def getAmount(self):
return self.amount
#def updateObjecet(self,x,y):
#self.item.update()
def render(self, display,x,y):
TILE_SIZE = 64
if self.selected:
pygame.draw.rect(display,(255,0,0),self.red)
pygame.draw.rect(display,(0,255,0),self.green)
if self.selected:
text = self.font.render(str(self.amount), True, (255,0,0))
else:
text = self.font.render(str(self.amount), True, (0,0,0))
display.blit(self.image, (x,y))
display.blit(text,(x + TILE_SIZE,y + TILE_SIZE))