-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainV5.1.py
475 lines (407 loc) · 19.7 KB
/
MainV5.1.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
## V5.1
## David Duan
import sys, time, pygame
from pygame import *
from SystemFunction import *
from SystemClassV3 import *
from ObjectClassP1V3 import *
from ObjectClassP2V3 import *
from Player import *
from MrAgnew import *
from Princess import *
from Dialogue import *
from DataDict import DATADICT
from FloorMap import FloorMap
pygame.init()
screen = pygame.display.set_mode((640, 480))
WHITE = 255, 255, 255
DARKRED = 210, 15, 0
RED = 250, 150, 150
GREEN = 110, 235, 120
BLUE = 160, 180, 255
GOLD = 220, 210, 60
GREY = 165, 155, 155
YELLOW = 230, 230, 35
BROWN = 204, 102, 0
PURPLE = 178, 102, 255
playerName = ''
def main():
pygame.display.set_caption("Tower of the Sorcerer")
bgImg = pygame.image.load("./imgSource/System/bgImg.jpg").convert()
bgImg = pygame.transform.scale(bgImg, (640, 480))
pygame.mixer.music.load("./Audio/introBGM.mid")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(-1)
select = pygame.mixer.Sound("./Audio/select.ogg")
select.set_volume(0.3)
clock = pygame.time.Clock()
title = TextButton(screen, "Tower of the Sorcerer", \
"./Font/BlackDahlia.ttf", 60, WHITE, WHITE, 35, 80)
start = TextButton(screen, "Start", "./Font/BlackDahlia.ttf",\
40, GREY, GREEN, 250, 190)
load = TextButton(screen, "Continue", "./Font/BlackDahlia.ttf", \
40, GREY, GOLD, 250, 240)
info = TextButton(screen, "Information", "./Font/BlackDahlia.ttf",
40, GREY, BLUE, 250, 290)
setting = TextButton(screen, "Setting", "./Font/BlackDahlia.ttf",
40, GREY, PURPLE, 250, 340)
end = TextButton(screen, "Quit", "./Font/BlackDahlia.ttf",
40, GREY, RED, 250, 390)
start.selected = True
statusList = ['start', 'load', 'info', 'setting', 'end']
current = 0
done = False
while not done:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.mixer.music.stop()
display.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
select.play()
if current == 4:
current = 0
else:
current += 1
for elem in statusList:
code = elem + '.selected = False'
exec(code)
exec(statusList[current] + '.selected = True')
elif event.key == pygame.K_RETURN:
if current == 2:
information(screen)
elif current == 3: pass # <<Setting>>
elif current == 4:
pygame.mixer.music.stop()
display.quit()
sys.exit()
elif current == 1: pass # <<Continue>>
elif current == 0:
global playerName
#playerName = input('Enter your name: ')
#blackScreen("FLOOR ZERO", 1)
game()
screen.blit(bgImg, (0, 0))
title.display()
start.display()
load.display()
info.display()
setting.display()
end.display()
pygame.display.update()
dialogue = False
dialogueGroup = pygame.sprite.Group()
obj = None
def game():
screen = pygame.display.set_mode((900, 550))
clock = pygame.time.Clock()
bottomLayer = pygame.Surface((640, 480)).convert()
bottomLayer.fill(BLACK)
background = Background(screen)
sprites = pygame.sprite.OrderedUpdates()
sidebar = pygame.sprite.Group()
list_of_all_groups = list(pygame.sprite.Group() for x in range(4))
map_object = list(list(list(None for a in range(15)) for b in range(15))for c in range(4))
global FloorMap
for floor in range(len(FloorMap)):
for row in range(15):
for column in range(15):
if FloorMap[floor][row][column] == -11:
map_object[floor][row][column] = FlowerMore(screen, -999, -999)
if FloorMap[floor][row][column] == -12:
map_object[floor][row][column] = FlowerLess(screen, -999, -999)
if FloorMap[floor][row][column] == -4:
map_object[floor][row][column] = WallLightGrey(screen, -999, -999)
if FloorMap[floor][row][column] == -3:
map_object[floor][row][column] = WallBlue(screen, -999, -999)
if FloorMap[floor][row][column] == -2:
map_object[floor][row][column] = Grass(screen, -999, -999)
if FloorMap[floor][row][column] == -1:
map_object[floor][row][column] = WallGrey(screen, -999, -999)
if FloorMap[floor][row][column] == 0: # Wall
map_object[floor][row][column] = Wall(screen, -999, -999)
if FloorMap[floor][row][column] == 1: # Empty
pass
if FloorMap[floor][row][column] in list(range(221, 231)): # Door
data = FloorMap[floor][row][column]
map_object[floor][row][column] = Door(screen, -999, -999, data)
if FloorMap[floor][row][column] in list(range(201, 211)): # Keys
data = FloorMap[floor][row][column]
map_object[floor][row][column] = Key(screen, -999, -999, data)
if FloorMap[floor][row][column] in [11, 12]:
data = FloorMap[floor][row][column]
map_object[floor][row][column] = Potion(screen, -999, -999, data)
if FloorMap[floor][row][column] in list(range(21, 31)):
data = FloorMap[floor][row][column]
map_object[floor][row][column] = Gem(screen, -999, -999, data)
if FloorMap[floor][row][column] in list(range(501, 521)):
data = FloorMap[floor][row][column]
_data = DATADICT[FloorMap[floor][row][column]]
map_object[floor][row][column] = NormalMonster(screen, -999, -999,\
data, _data[0], _data[1], _data[2], _data[3])
if FloorMap[floor][row][column] == 801:
data = FloorMap[floor][row][column]
map_object[floor][row][column] = MrAgnewF0(screen, -999, -999, data)
if FloorMap[floor][row][column] == 99:
player = Player(screen, -999, -999)
map_object[floor][row][column] = player
if FloorMap[floor][row][column] == 101:
princess = PrincessF0(screen, -999, -999)
map_object[floor][row][column] = princess
if FloorMap[floor][row][column] in [91, 92]:
data = FloorMap[floor][row][column]
map_object[floor][row][column] = Stair(screen, -999, -999, data)
if map_object[floor][row][column] != None :
list_of_all_groups[0].add(map_object[floor][row][column])
sprites.add(background)
sprites.add(list_of_all_groups)
playerx = 7
playery = 14
player.setX(playerx)
player.setY(playery)
current_floor = 0
global playerName
global dialogueGroup, dialogue
player.name = playerName
ytracker = Icon(screen, player, "./imgSource/System/Items/ykeys.png", BLACK, 30, 260)
btracker = Icon(screen, player, "./imgSource/System/Items/bkeys.png", BLACK, 30, 300)
rtracker = Icon(screen, player, "./imgSource/System/Items/rkeys.png", BLACK, 30, 340)
goldtracker = Icon(screen, player, "./imgSource/System/Items/gold.png", BLACK, 30, 383)
lvltracker = StatusLevel(screen, player)
playericon = Icon(screen, player, 'player.getimage()', WHITE, 30, 50, (40, 40))
playername = String(screen, player, "./Font/FestivalBudayaXXXI.otf", 20, 'getname()', \
(128, 128, 128), 80, 25)
dmgtracker = Icon(screen, player, "./imgSource/System/dmgIcon.png", WHITE, 680, 43)
deftracker = Icon(screen, player, "./imgSource/System/defIcon.png", WHITE, 680, 83)
hptracker = Icon(screen, player, "./imgSource/System/hpIcon.png", WHITE, 680, 123)
getykey = YKeyNumber(screen, player)
getbkey = BKeyNumber(screen, player)
getrkey = RKeyNumber(screen, player)
getgold = GoldNumber(screen, player)
getdmg = DmgNumber(screen, player)
getdef = DefNumber(screen, player)
gethp = HpNumber(screen, player)
sidebar.add(ytracker, btracker, rtracker, getykey, getbkey, getrkey, lvltracker,\
playericon, playername, goldtracker, getgold, dmgtracker, deftracker, \
hptracker, getdmg, getdef, gethp)
x = 1
done = False
while not done:
if x == 0: # Smooth Movement but FPS lag
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
playerx = int((player.getX() - 160) / 32)
playery = int(player.getY() / 32)
keys = pygame.key.get_pressed()
if keys[K_LSHIFT] or keys[K_RSHIFT]: # if SHIFT is pressed: increase movement speed
clock.tick(30)
else:
clock.tick(12)
if keys[K_UP]:
player.changeimage(3)
if movable( player, map_object,FloorMap, current_floor,playerx, playery-1):
FloorMap[current_floor][playery-1][playerx]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery-1][playerx]= player
map_object[current_floor][playery][playerx] = None
if keys[K_DOWN]:
player.changeimage(0)
if movable( player, map_object, FloorMap, current_floor,playerx, playery+1):
FloorMap[current_floor][playery+1][playerx]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery+1][playerx]= player
map_object[current_floor][playery][playerx] = None
if keys[K_LEFT]:
player.changeimage(1)
if movable( player, map_object, FloorMap, current_floor,playerx-1, playery):
FloorMap[current_floor][playery][playerx-1]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery][playerx-1]= player
map_object[current_floor][playery][playerx] = None
if keys[K_RIGHT]:
player.changeimage(2)
if movable( player, map_object, FloorMap,current_floor,playerx+1, playery):
FloorMap[current_floor][playery][playerx+1]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery][playerx+1]= player
map_object[current_floor][playery][playerx] = None
getykey.setykey(player)
getbkey.setbkey(player)
getrkey.setrkey(player)
getgold.setgold(player)
lvltracker.setlevel(player)
for row in range(15):
for column in range(15):
if map_object[current_floor][row][column] != None:
map_object[current_floor][row][column].setX(column)
map_object[current_floor][row][column].setY(row)
else: # Normal Movement
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.mixer.music.stop()
display.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
playerx = int((player.getX() - 160) / 32)
playery = int(player.getY() / 32)
if event.key == pygame.K_UP:
player.changeimage(3)
if movable(player, map_object,FloorMap, current_floor,playerx, playery-1):
FloorMap[current_floor][playery-1][playerx]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery-1][playerx]= player
map_object[current_floor][playery][playerx] = None
if event.key == pygame.K_DOWN:
player.changeimage(0)
if movable(player, map_object, FloorMap, current_floor,playerx, playery+1):
FloorMap[current_floor][playery+1][playerx]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery+1][playerx]= player
map_object[current_floor][playery][playerx] = None
if event.key == pygame.K_LEFT:
player.changeimage(1)
if movable(player, map_object, FloorMap, current_floor,playerx-1, playery):
FloorMap[current_floor][playery][playerx-1]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery][playerx-1]= player
map_object[current_floor][playery][playerx] = None
if event.key == pygame.K_RIGHT:
player.changeimage(2)
if movable(player, map_object, FloorMap,current_floor,playerx+1, playery):
FloorMap[current_floor][playery][playerx+1]= 99
FloorMap[current_floor][playery][playerx] = 1
map_object[current_floor][playery][playerx+1]= player
map_object[current_floor][playery][playerx] = None
getykey.setykey(player)
getbkey.setbkey(player)
getrkey.setrkey(player)
getgold.setgold(player)
lvltracker.setlevel(player)
getdmg.setdmg(player)
getdef.setdef(player)
gethp.sethp(player)
for row in range(15):
for column in range(15):
if map_object[current_floor][row][column] != None:
map_object[current_floor][row][column].setX(column)
map_object[current_floor][row][column].setY(row)
sprites.clear(screen, bottomLayer)
sidebar.clear(screen, bottomLayer)
sprites.update()
sidebar.update()
sprites.draw(screen)
sidebar.draw(screen)
if dialogue:
enter = PressEnter(screen)
dialogueList = obj.dialogueList
xd = True
while dialogueList:
if dialogueList[0][0] != '!':
speakerIcon = ConvIcon(screen, obj.image)
speakerName = ConvName(screen, obj.name, obj.type)
speakerWords = ConvConv(screen, dialogueList[0])
else:
speakerIcon = ConvIcon(screen, player.icon)
speakerName = ConvName(screen, player.getname(), "Player")
speakerWords = ConvConv(screen, dialogueList[0][1:])
dialogueGroup.add(speakerIcon, speakerName, enter)
if xd:
dialogueGroup.add(speakerWords)
xd = False
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
dialogueList = dialogueList[1:]
dialogueGroup.empty()
xd = True
dialogueGroup.clear(screen, bottomLayer)
sprites.clear(screen, bottomLayer)
sidebar.clear(screen, bottomLayer)
sprites.update()
sidebar.update()
dialogueGroup.update()
sprites.draw(screen)
sidebar.draw(screen)
dialogueGroup.draw(screen)
pygame.display.flip()
dialogue = False
pygame.display.flip()
def movable(player, map_object, FloorMap, current_floor, targetx, targety):
global dialogue, obj
if targety > 14 or targetx > 14:
return False
else:
targetObj = FloorMap[current_floor][targety][targetx]
if targetObj in [0, -1]: # Wall
return False
elif targetObj == 101: # Princess
dialogue = True
obj = map_object[current_floor][targety][targetx]
return False
elif targetObj in list(range(221, 232)): # Door
if targetObj == 221:
if player.getykey() > 0:
map_object[current_floor][targety][targetx].kill()
player.updateykey(-1)
return True
else:
return False
elif targetObj == 222:
if player.getbkey() > 0:
map_object[current_floor][targety][targetx].kill()
player.updatebkey(-1)
return True
else:
return False
elif targetObj == 223:
if player.getrkey() > 0:
map_object[current_floor][targety][targetx].kill()
player.updaterkey(-1)
return True
else:
return False
elif targetObj in list(range(201, 212)): # keys
if targetObj == 201:
map_object[current_floor][targety][targetx].kill()
player.updateykey(1)
return True
elif targetObj == 202:
map_object[current_floor][targety][targetx].kill()
player.updatebkey(1)
return True
elif targetObj == 203:
map_object[current_floor][targety][targetx].kill()
player.updaterkey(1)
return True
elif targetObj in list(range(11, 13)): # potions
if targetObj == 11:
map_object[current_floor][targety][targetx].kill()
player.updatehp(10)
return True
elif targetObj == 12:
map_object[current_floor][targety][targetx].kill()
player.updatehp(20)
return True
elif targetObj in list(range(21, 31)): # gems
if targetObj == 21:
map_object[current_floor][targety][targetx].kill()
player.updatedmg(5)
return True
elif targetObj == 22:
map_object[current_floor][targety][targetx].kill()
player.updatedef(5)
return True
elif targetObj in [91, 92]: # Stairs, implemented in another function
return False
elif targetObj in list(range(501, 601)):
return False
elif targetObj in list(range(801, 810)):
dialogue = True
obj = map_object[current_floor][targety][targetx]
return False
return True
# Another change_floor function here
main()