Mercurial > touhou
annotate pytouhou/ui/gamerunner.pyx @ 463:11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 11 Sep 2013 00:36:52 +0200 |
parents | 6e733ed817bd |
children | 36bc577b2392 |
rev | line source |
---|---|
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
438
diff
changeset
|
15 from pytouhou.lib cimport sdl |
146
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
16 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
17 from .window cimport Window, Runner |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
18 from .gamerenderer cimport GameRenderer |
379
e0e284fcb288
Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
19 from .music import MusicPlayer, SFXPlayer, NullPlayer |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
20 |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
21 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
22 cdef class GameRunner(Runner): |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
23 cdef object game, background |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
24 cdef GameRenderer renderer |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
25 cdef Window window |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
26 cdef object replay_level, save_keystates |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
27 cdef long keystate |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
28 cdef bint skip, use_fixed_pipeline |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
29 |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
30 def __init__(self, window, resource_loader, bint skip=False): |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
31 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
32 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
33 self.renderer = GameRenderer(resource_loader, self.use_fixed_pipeline) |
419
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
34 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
35 self.window = window |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
36 self.replay_level = None |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
37 self.skip = skip |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
38 self.keystate = 0 |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
330
diff
changeset
|
39 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
40 self.width = window.width #XXX |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
41 self.height = window.height #XXX |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
42 |
330
16ed1ab1e14b
Add a GameRunner.load_game method to allow level changes.
Thibaut Girka <thib@sitedethib.com>
parents:
323
diff
changeset
|
43 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
44 def load_game(self, game=None, background=None, bgms=None, replay=None, save_keystates=None): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
45 self.game = game |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
46 self.background = background |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
47 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
48 self.renderer.texture_manager.load(game.resource_loader.instanced_anms.values()) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
49 self.renderer.load_background(background) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
50 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
51 self.set_input(replay) |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
52 if replay and replay.levels[game.stage - 1]: |
341
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
53 game.players[0].state.lives = self.replay_level.lives |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
54 game.players[0].state.power = self.replay_level.power |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
55 game.players[0].state.bombs = self.replay_level.bombs |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
56 game.difficulty = self.replay_level.difficulty |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
57 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
58 self.save_keystates = save_keystates |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
59 |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
60 null_player = NullPlayer() |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
61 if bgms: |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
62 game.music = MusicPlayer(game.resource_loader, bgms) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
63 game.music.play(0) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
64 else: |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
65 game.music = null_player |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
66 |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
67 game.sfx_player = SFXPlayer(game.resource_loader) if not self.skip else null_player |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
341
diff
changeset
|
68 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
69 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
70 def set_input(self, replay=None): |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
71 if not replay or not replay.levels[self.game.stage-1]: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
72 self.replay_level = None |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
73 else: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
74 self.replay_level = replay.levels[self.game.stage-1] |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
75 self.keys = self.replay_level.iter_keystates() |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
76 |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
77 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
78 cdef void start(self) except *: |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
79 cdef long width, height |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
80 width = self.game.interface.width if self.game is not None else 640 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
81 height = self.game.interface.height if self.game is not None else 480 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
82 if width != self.width or height != self.height: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
83 self.window.set_size(width, height) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
84 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
85 self.renderer.start(self.game) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
86 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
87 |
463
11708a1d0a1a
Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
88 cdef bint update(self) except *: |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
89 cdef long keystate |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
90 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
91 if self.background: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
146
diff
changeset
|
92 self.background.update(self.game.frame) |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
93 for event in sdl.poll_events(): |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
94 type_ = event[0] |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
95 if type_ == sdl.KEYDOWN: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
96 scancode = event[1] |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
97 if scancode == sdl.SCANCODE_ESCAPE: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
98 return False #TODO: implement the pause. |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
99 elif type_ == sdl.QUIT: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
100 return False |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
101 if self.game: |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
102 if self.replay_level is None: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
103 #TODO: allow user settings |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
104 keys = sdl.get_keyboard_state() |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
105 keystate = 0 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
106 if keys[sdl.SCANCODE_Z]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
107 keystate |= 1 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
108 if keys[sdl.SCANCODE_X]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
109 keystate |= 2 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
110 if keys[sdl.SCANCODE_LSHIFT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
111 keystate |= 4 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
112 if keys[sdl.SCANCODE_UP]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
113 keystate |= 16 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
114 if keys[sdl.SCANCODE_DOWN]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
115 keystate |= 32 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
116 if keys[sdl.SCANCODE_LEFT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
117 keystate |= 64 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
118 if keys[sdl.SCANCODE_RIGHT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
119 keystate |= 128 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
120 if keys[sdl.SCANCODE_LCTRL]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
121 keystate |= 256 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
122 else: |
374
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
123 try: |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
124 keystate = self.keys.next() |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
125 except StopIteration: |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
126 keystate = 0 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
127 if self.skip: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
128 self.set_input() |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
129 self.skip = False |
379
e0e284fcb288
Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
130 self.game.sfx_player = SFXPlayer(self.game.resource_loader) |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
131 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
132 if self.save_keystates is not None: |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
133 self.save_keystates.append(keystate) |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
134 |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
330
diff
changeset
|
135 self.game.run_iter(keystate) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
136 self.game.interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
137 if not self.skip: |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
138 self.renderer.render(self.game) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
139 return True |