-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
208 lines (199 loc) · 10.6 KB
/
data.py
File metadata and controls
208 lines (199 loc) · 10.6 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import pygame
from entity import weapon_prototype,armor_prototype,unit_prototype
ptext = []
wflavours = []
weapons = []
enemies = []
gui = []
armors = []
saveslots = [None,None,None,None]
def load_player():
for each in [pygame.image.load("resources/pup.png").convert_alpha(),
pygame.image.load("resources/pupright.png").convert_alpha(),
pygame.image.load("resources/pright.png").convert_alpha(),
pygame.image.load("resources/pdownright.png").convert_alpha(),
pygame.image.load("resources/pdown.png").convert_alpha(),
pygame.image.load("resources/pdownleft.png").convert_alpha(),
pygame.image.load("resources/pleft.png").convert_alpha(),
pygame.image.load("resources/pupleft.png").convert_alpha()
]:
ptext.append(each)
def load_worlds():
for each in [[pygame.image.load("resources/worlds/cave/world1.png").convert(),
pygame.image.load("resources/worlds/cave/wallv.png").convert(),
pygame.image.load("resources/worlds/cave/wallh.png").convert(),
pygame.image.load("resources/worlds/cave/door.png").convert_alpha(),
pygame.image.load("resources/worlds/cave/dooractive.png").convert_alpha(),
pygame.image.load("resources/worlds/cave/trap.png").convert_alpha(),
pygame.image.load("resources/worlds/cave/chest.png").convert_alpha(),
pygame.image.load("resources/worlds/cave/obstacle1.png").convert_alpha(),
["cave"]],
[pygame.image.load("resources/worlds/forest/world1.png").convert(),
pygame.image.load("resources/worlds/forest/wallv.png").convert(),
pygame.image.load("resources/worlds/forest/wallh.png").convert(),
pygame.image.load("resources/worlds/forest/door.png").convert_alpha(),
pygame.image.load("resources/worlds/forest/dooractive.png").convert_alpha(),
pygame.image.load("resources/worlds/forest/trap.png").convert_alpha(),
pygame.image.load("resources/worlds/forest/chest.png").convert_alpha(),
pygame.image.load("resources/worlds/forest/obstacle1.png").convert_alpha(),
["forest"]]
]:
wflavours.append(each)
def load_weapons():
weapons.append(weapon_prototype(pygame.image.load("resources/sword.png").convert_alpha(),pygame.image.load("resources/bullet.png").convert_alpha(),[40,50],[0.4,0.5],pygame.image.load("resources/sworddis.png").convert_alpha()))
weapons.append(weapon_prototype(pygame.image.load("resources/sword.png").convert_alpha(),None,[80,100],[0.4,0,4],pygame.image.load("resources/sworddis.png").convert_alpha()))
def load_armors():
armors.append(armor_prototype(pygame.image.load("resources/sword.png").convert_alpha(),[0,100],[40,50],'head',pygame.image.load("resources/sworddis.png").convert_alpha()))
armors.append(armor_prototype(pygame.image.load("resources/sword.png").convert_alpha(),[0,100],[40,50],'torso',pygame.image.load("resources/sworddis.png").convert_alpha()))
armors.append(armor_prototype(pygame.image.load("resources/sword.png").convert_alpha(),[0,100],[40,50],'legs',pygame.image.load("resources/sworddis.png").convert_alpha()))
armors.append(armor_prototype(pygame.image.load("resources/sword.png").convert_alpha(),[0,100],[40,50],'feet',pygame.image.load("resources/sworddis.png").convert_alpha()))
armors.append(armor_prototype(pygame.image.load("resources/sword.png").convert_alpha(),[0,100],[40,50],'arms',pygame.image.load("resources/sworddis.png").convert_alpha()))
def load_enemies():
enemies.append(unit_prototype('Goblin',pygame.image.load("resources/monsterc.png").convert_alpha(),120,1,[80,50,2,20,100,0,0],"cave"))
enemies.append(unit_prototype('Animal',pygame.image.load("resources/monster.png").convert_alpha(),80,1,[0,0,0,0,0,0,0],"forest"))
def load_gui():
gui.append(pygame.image.load("resources/inventory.png").convert_alpha())
gui.append(pygame.image.load("resources/invslot.png").convert_alpha())
def load_saveslots():
currslot = 0
names = ["Bob","Bob","Bob","Bob"]
working = [False,False,False,False]
done = [False,False,False,False]
levels = [1,1,1,1]
gear = [[-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1]]
fin = open("resources/data.txt")
for line in fin:
temp = line.split("<")
for i in temp:
temp2 = i.split(">")[0]
temp2 = temp2.split(":")
if temp2[0]=="slot":
try:
currslot = int(temp2[1])
if done[currslot-1]:
working[currslot-1] = False
else:
working[currslot-1] = True
done[currslot-1] = True
except ValueError:
currslot = 0
elif currslot>0 and currslot<5 and working[currslot-1]:
if temp2[0]=="name":
names[currslot-1] = temp2[1]
elif temp2[0]=="level":
try:
levels[currslot-1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="main":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(weapons):
gear[currslot-1][0] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="off":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(weapons):
gear[currslot-1][1] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="head":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(armors):
gear[currslot-1][2] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="torso":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(armors):
gear[currslot-1][3] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="legs":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(armors):
gear[currslot-1][4] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="feet":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(armors):
gear[currslot-1][5] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
elif temp2[0]=="arms":
try:
temp2[1] = int(temp2[1])
except ValueError:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
if temp2[1]>=-1 and temp2[1]<len(armors):
gear[currslot-1][6] = temp2[1]
else:
names[currslot-1] = "Corrupted"
working[currslot-1] = False
#elif temp2[0]=="stash":
pls = []
for i in range(len(names)):
pls.append([names[i],working[i],levels[i],gear[i]])
return pls
def load_resources():
load_player()
load_worlds()
load_weapons()
load_armors()
load_enemies()
load_gui()
return load_saveslots()
def resize_resources(screenh,screenw):
nsize = min(int((screenh/16.0)),48)
if nsize == 512:
return
for i in range(len(weapons)):
#for each in weapons[i].text ...
weapons[i].text = pygame.transform.scale(weapons[i].text,(int((nsize*weapons[i].text.get_width())/(float(ptext[0].get_width()))),int((nsize*weapons[i].text.get_height())/(float(ptext[0].get_width())))))
sizex = int((screenw*weapons[i].image.get_width())/1920.0)
weapons[i].image = pygame.transform.scale(weapons[i].image,(sizex,int((sizex*weapons[i].image.get_height())/float(weapons[i].image.get_width()))))
for i in range(len(armors)):
#for each in armors[i].text ...
armors[i].text = pygame.transform.scale(armors[i].text,(int((nsize*armors[i].text.get_width())/(float(ptext[0].get_width()))),int((nsize*armors[i].text.get_height())/(float(ptext[0].get_width())))))
sizex = int((screenw*armors[i].image.get_width())/1920.0)
armors[i].image = pygame.transform.scale(armors[i].image,(sizex,int((sizex*armors[i].image.get_height())/float(armors[i].image.get_width()))))
for i in range(len(ptext)):
ptext[i] = pygame.transform.scale(ptext[i],(nsize-1,nsize-1))
for each in range(len(wflavours)):
for i in range(3,len(wflavours[each])-1):
wflavours[each][i] = pygame.transform.scale(wflavours[each][i],(nsize,nsize))
for i in range(len(enemies)):
enemies[i].image = pygame.transform.scale(enemies[i].image,(nsize,nsize))