This repository was archived by the owner on Jul 1, 2026. It is now read-only.
forked from jcrawfordobanner/FinalProj
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
Latest commit
146 lines (118 loc) · 4.91 KB
/
Copy pathclasses.py
File metadata and controls
146 lines (118 loc) · 4.91 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
importpygame
frompygame.localsimport*
importtime
classBackdrop(object):
def__init__(self, image_name, size):
im=pygame.image.load(image_name)
self.size= (size[0], int(size[1]*4/5))
self.image=pygame.transform.scale(im, self.size)
self.rect=self.image.get_rect()
defdraw(self, scrn, loc= (0,0)):
scrn.blit(self.image, loc)
classTextbox(pygame.Surface):
"""Changed so that it now takes text argument as a tuple,
to make printing lines on the same thing easier"""
# Constructor. Pass in the color of the block,
# and its x and y position
def__init__(self, size, text):
pygame.Surface.__init__(self,size)
pygame.sprite.Sprite.__init__(self)
self.width=size[0]
self.height=size[1]/5
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.imageout=pygame.Surface((self.width,self.height))
self.imageout.fill((0, 50, 60))
# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rectout=self.imageout.get_rect()
self.rectout.x=0
self.rectout.y=size[1]-self.height
pygame.sprite.Sprite.__init__(self)
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.imagein=pygame.Surface((self.width*0.9,self.height*0.75))
self.imagein.fill((250,255,255))
# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rectin=self.imagein.get_rect()
self.rectin.x=int((self.width-self.width*0.9)/2)
self.rectin.y=size[1]-self.height+int((self.height-self.height*0.75)/2)
pygame.font.init()
self.font=pygame.font.SysFont('Comic Sans MS', 28)
self.text=text
defdraw(self, screen):
screen.blit(self.imageout, (0, self.rectout.y))
self.imagein.fill((250,255,255))
ifisinstance(self.text, tuple):
loc_y=5
forlineinself.text:
self.textsurface=self.font.render(line, False,(0,0,0))
self.imagein.blit(self.textsurface,(5,loc_y))
loc_y+=25
elifisinstance(self.text, str):
self.textsurface=self.font.render(self.text, False,(0,0,0))
self.imagein.blit(self.textsurface,(5,5))
screen.blit(self.imagein, (self.rectin.x,self.rectin.y))
defupdate(self, words):
self.text=words
classItem(pygame.sprite.Sprite):
def__init__(self, name, loc, scl, filename=None, take=False):
pygame.sprite.Sprite.__init__(self)
ifnotfilename==None:
im=pygame.image.load(filename)
orig_size=im.get_rect()
image=pygame.transform.scale(im, (int(orig_size.w*scl), int(orig_size.h*scl)))
self.image=image
self.Rect=pygame.Rect(self.image.get_rect()).move(loc)
else:
self.image=pygame.Surface((int(160*scl), int(210*scl)) , pygame.SRCALPHA, 32)
self.Rect=pygame.Rect(self.image.get_rect()).move(loc)
# self.image.fill((20,20,140))
self.name=name
self.loc=loc
self.hidd=False
self.take=take
defdraw(self, scrn):
scrn.blit(self.image, self.loc)
defclick(self,pos):
ifpygame.Rect(self.Rect).collidepoint(pos[0], pos[1]):
returnself.name
print(self.name)
ifpos[0] inrange(self.loc[0], self.loc[0] +self.Rect.width):
ifpos[1] inrange(self.loc[1], self.loc[1]+self.Rect.height):
returnself.name
else:
returnFalse
defupdate(self, pos):
ifself.click(pos):
ifself.take:
self.hidd=True
classInventory(pygame.sprite.Group):
def__init__(self):
pygame.sprite.Group.__init__(self)
self.items= []
defadd_item(self, item):
self.items.append(item.name)
self.add(item)
classRoom(pygame.sprite.LayeredUpdates):
def__init__(self, items, backdrops):
pygame.sprite.LayeredUpdates.__init__(self)
self.items= []
foriteminitems:
self.add(item)
self.items.append(item)
self.backdrop=backdrops
self.items_vis= []
foriteminself.items:
ifnotitem.hidd:
self.items_vis.append(item)
defdraw(self, scrn):
self.backdrop.draw(scrn)
foriteminself.items_vis:
item.draw(scrn)
defupdate(self, pos):
foriteminself.items_vis:
ifitem.click(pos) anditem.take:
self.items_vis.remove(item)
item.update(pos)