/
mustyqatse.py
executable file
·114 lines (92 loc) · 3.16 KB
/
mustyqatse.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
import sys
from math import pi
from random import choice
import pygame
from src import text
from src.menu import RotatingMenu
from src.event import EventHandler
from src.game import Game
from src.editor import Editor
class Main(EventHandler):
def __init__(self):
pygame.init()
self.display = pygame.display.set_mode((960, 540))
self.clock = pygame.time.Clock()
#Then the custom event handling
self.events = [ #Arguments:
'keyDown', #unicode, key, mod
'keyUp', #key, mod
'mouseMotion', #pos, rel, buttons
'mouseButtonDown', #pos, button
'mouseButtonUp', #pos, button
'quit', #no variables
]
self.register(*self.events)
#Then the main menu
noAction = lambda: None
menuItems = {
"Exit": self.on_menu_exit,
"Options": {
"Resolution": noAction,
"FPS Limit": noAction,
},
"Start": self.on_menu_game,
"Levels": noAction,
"Editor": {
"New Level": noAction,
"Load Level": noAction,
},
}
self.menu = RotatingMenu(self, x=480, y=270, w=700, h=400, arc=pi, defaultAngle=pi/2., wrap=False, headerText="Mustyqatse", items=menuItems, on_selection=self.menu_select, backText="Back")
self.context = self.menu
def update(self):
for e in pygame.event.get():
if e.type == pygame.KEYDOWN:
self.emit('keyDown', e.key, e.mod)
elif e.type == pygame.KEYUP:
self.emit('keyUp', e.key, e.mod)
elif e.type == pygame.MOUSEMOTION:
self.emit('mouseMotion', e.pos, e.rel, e.buttons)
elif e.type == pygame.MOUSEBUTTONDOWN:
self.emit('mouseButtonDown', e.pos, e.button)
elif e.type == pygame.MOUSEBUTTONUP:
self.emit('mouseButtonUp', e.pos, e.button)
elif e.type == pygame.QUIT:
self.emit('quit')
self.context.update()
self.context.draw(self.display)
pygame.display.flip()
self.clock.tick(60) #Limit FPS
#Menu
def menu_select(self, menu):
self.context = menu
def on_menu_game(self):
game = Game(self)
game.win = self.win
game.lose = self.lose
self.context = game
game.start()
def menuLevels(self):
pass
def menuEditor(self):
editor = Editor(self)
editor.back = self.menuBack
self.context = editor
def on_menu_exit(self):
return sys.exit()
#Options Menu
def optionsResolution(self):
pass
def optionsFPSLimit(self):
pass
#Game
def win(self):
self.context = self.menu
self.menu.header.text = choice(text.on_win)
def lose(self):
self.context = self.menu
self.menu.header.text = choice(text.on_lose)
if __name__ == "__main__":
main = Main()
while True:
main.update()