comparison pytouhou/ui/gamerunner.pyx @ 635:80687f258001

Make sdl.Window inherit from gui.Window, so we can swap implementations.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 14 Apr 2016 21:18:03 +0100
parents a6af3ff86612
children
comparison
equal deleted inserted replaced
634:5270c34b4c00 635:80687f258001
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 cimport cython 15 cimport cython
16 16
17 from pytouhou.lib cimport sdl 17 from pytouhou.lib.gui cimport EXIT, PAUSE, SCREENSHOT, RESIZE, FULLSCREEN
18 18
19 from .window cimport Window, Runner 19 from .window cimport Window, Runner
20 from .music import BGMPlayer, SFXPlayer 20 from .music import BGMPlayer, SFXPlayer
21 from pytouhou.game.game cimport Game 21 from pytouhou.game.game cimport Game
22 from pytouhou.game.music cimport MusicPlayer 22 from pytouhou.game.music cimport MusicPlayer
118 cdef long keystate 118 cdef long keystate
119 capture = False 119 capture = False
120 120
121 if self.background is not None: 121 if self.background is not None:
122 self.background.update(self.game.frame) 122 self.background.update(self.game.frame)
123 for event in sdl.poll_events(): 123 for event, args in self.window.get_events():
124 type_ = event[0] 124 if event == EXIT:
125 if type_ == sdl.KEYDOWN:
126 scancode = event[1]
127 if scancode == sdl.SCANCODE_ESCAPE:
128 return False #TODO: implement the pause.
129 elif scancode == sdl.SCANCODE_P or scancode == sdl.SCANCODE_HOME:
130 capture = True
131 elif type_ == sdl.QUIT:
132 return False 125 return False
133 elif type_ == sdl.WINDOWEVENT: 126 elif event == PAUSE:
134 event_ = event[1] 127 return False # TODO: implement the pause.
135 if event_ == sdl.WINDOWEVENT_RESIZED: 128 elif event == FULLSCREEN:
136 self.set_renderer_size(event[2], event[3]) 129 self.window.toggle_fullscreen()
137 if self.window is not None: 130 elif event == SCREENSHOT:
138 self.window.set_size(event[2], event[3]) 131 capture = True
132 elif event == RESIZE:
133 width, height = args
134 self.set_renderer_size(width, height)
135 if self.window is not None:
136 self.window.set_size(width, height)
139 if self.replay_level is None: 137 if self.replay_level is None:
140 #TODO: allow user settings 138 keystate = self.window.get_keystate()
141 keys = sdl.keyboard_state
142 keystate = 0
143 if keys[sdl.SCANCODE_Z]:
144 keystate |= 1
145 if keys[sdl.SCANCODE_X]:
146 keystate |= 2
147 if keys[sdl.SCANCODE_LSHIFT]:
148 keystate |= 4
149 if keys[sdl.SCANCODE_UP]:
150 keystate |= 16
151 if keys[sdl.SCANCODE_DOWN]:
152 keystate |= 32
153 if keys[sdl.SCANCODE_LEFT]:
154 keystate |= 64
155 if keys[sdl.SCANCODE_RIGHT]:
156 keystate |= 128
157 if keys[sdl.SCANCODE_LCTRL]:
158 keystate |= 256
159 else: 139 else:
160 try: 140 try:
161 keystate = self.keys.next() 141 keystate = self.keys.next()
162 except StopIteration: 142 except StopIteration:
163 keystate = 0 143 keystate = 0