/
main.py
105 lines (96 loc) · 3.37 KB
/
main.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
# Copyright (c) 2012 Bailey Mihajlich
# Licensed under the GNU GPL v.2
# See license.txt for licence information
import sys
from os import getcwd, listdir
from os.path import join
from constants import *
from globalvars import *
from world import *
import sprites
import pc
from monsters import *
import menu
import pygame
# initialization
pygame.mixer.init()
pygame.display.set_caption("Mechanical Failure")
pygame.display.set_icon(globalvars.images["misc" + "logo"])
menu.title()
while True:
if globalvars.newgame:
# load save game
globalvars.hero = pc.PC("Cole", CENTERCENTER)
globalvars.heroGroup.empty()
globalvars.heroGroup.add(globalvars.hero)
globalvars.solidGroup.empty()
globalvars.solidGroup.add(globalvars.hero)
globalvars.attackGroup.empty()
globalvars.itemGroup.empty()
path = join(getcwd(), "savedata")
savelist = listdir(path)
if len(savelist) > 1:
if menu.dialogue("Do you want to load the saved game?"):
menu.load("save1.py")
else:
menu.get_name()
else:
menu.get_name()
# set up groups
world = World()
globalvars.newgame = False
# handle game events
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
elif event.key == K_RETURN:
world.music.pause()
textSurface = FONT.render("PAUSED", True, WHITE, BLACK)
rect = textSurface.get_rect()
rect.center = CENTERCENTER
globalvars.window.blit(textSurface, rect)
pygame.display.update()
paused = True
while paused:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_RETURN:
paused = False
world.music.unpause()
# update the sprites
moveval = globalvars.hero.update()
world.update()
globalvars.attackGroup.update()
# update the groups from the queues
globalvars.solidGroup.add(globalvars.solidQ)
world.currentmap.surfaceGroup.add(globalvars.backgroundQ)
globalvars.attackGroup.add(globalvars.attackQ)
globalvars.solidGroup.add(globalvars.attackQ)
globalvars.solidQ.empty()
globalvars.backgroundQ.empty()
globalvars.attackQ.empty()
globalvars.itemGroup.add(globalvars.itemQ)
world.currentmap.itemGroup.add(globalvars.itemQ)
globalvars.itemQ.empty()
# Update map if hero moved off the edge of the screen
if moveval == "north" or \
moveval == "south" or \
moveval == "east" or \
moveval == "west" or \
moveval == "up" or \
moveval == "down":
world.load(moveval)
# update the screen
draw_hud()
world.draw(globalvars.window)
globalvars.heroGroup.draw(globalvars.window)
pygame.display.update()
globalvars.clock.tick(FPS)