Mercurial > touhou
annotate scripts/pytouhou @ 554:653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 30 May 2014 04:06:09 +0200 |
parents | 8f51e34d911c |
children | bafe6361c0af |
rev | line source |
---|---|
414
b0b8825296d0
Follow the PEP-0394 guidelines, migrating from python to python2.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
407
diff
changeset
|
1 #!/usr/bin/env python2 |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
2 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
3 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
4 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
5 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
6 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
7 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
8 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
9 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
10 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
13 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
14 ## |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 |
186
84da28ae7ee4
Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
162
diff
changeset
|
16 import argparse |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 import os |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 |
416
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
19 |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
20 pathsep = os.path.pathsep |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
21 default_data = (pathsep.join(('CM.DAT', 'th06*_CM.DAT', '*CM.DAT', '*cm.dat')), |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
22 pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')), |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
23 pathsep.join(('IN.DAT', 'th6*IN.DAT', '*IN.DAT', '*in.dat')), |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
24 pathsep.join(('MD.DAT', 'th6*MD.DAT', '*MD.DAT', '*md.dat')), |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
25 pathsep.join(('102h.exe', '102*.exe', '東方紅魔郷.exe', '*.exe'))) |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
26 |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
27 |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
28 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.') |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
130
diff
changeset
|
29 |
416
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
30 parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files') |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
31 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
32 parser.add_argument('--debug', action='store_true', help='Set unlimited continues, and perhaps other debug features.') |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
33 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.') |
534
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
34 |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
35 game_group = parser.add_argument_group('Game options') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
36 game_group.add_argument('-s', '--stage', metavar='STAGE', type=int, default=None, help='Stage, 1 to 7 (Extra), nothing means story mode.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
37 game_group.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
38 game_group.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
39 game_group.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
40 game_group.add_argument('--game', metavar='GAME', choices=['EoSD'], default='EoSD', help='Select the game engine to use.') |
549
56bca8ce4b68
Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
41 game_group.add_argument('--interface', metavar='INTERFACE', choices=['EoSD', 'Sample'], default='EoSD', help='Select the interface to use.') |
534
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
42 game_group.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
43 |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
44 replay_group = parser.add_argument_group('Replay options') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
45 replay_group.add_argument('--replay', metavar='REPLAY', help='Select a file to replay.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
46 replay_group.add_argument('--save-replay', metavar='REPLAY', help='Save the upcoming game into a replay file.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
47 replay_group.add_argument('--skip-replay', action='store_true', help='Skip the replay and start to play when it’s finished.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
48 |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
49 netplay_group = parser.add_argument_group('Netplay options') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
50 netplay_group.add_argument('--port', metavar='PORT', type=int, default=0, help='Local port to use.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
51 netplay_group.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
52 netplay_group.add_argument('--friendly-fire', action='store_true', help='Allow friendly-fire during netplay.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
53 |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
54 graphics_group = parser.add_argument_group('Graphics options') |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
55 graphics_group.add_argument('--backend', metavar='BACKEND', choices=['opengl', 'sdl'], default=['opengl', 'sdl'], nargs='*', help='Which backend to use (opengl or sdl).') |
534
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
56 graphics_group.add_argument('--fps-limit', metavar='FPS', default=-1, type=int, help='Set fps limit. A value of 0 disables fps limiting, while a negative value limits to 60 fps if and only if vsync doesn’t work.') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
57 graphics_group.add_argument('--no-background', action='store_false', help='Disable background display (huge performance boost on slow systems).') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
58 graphics_group.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).') |
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
59 graphics_group.add_argument('--no-sound', action='store_false', help='Disable music and sound effects.') |
416
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
60 |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
61 opengl_group = parser.add_argument_group('OpenGL backend options') |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
62 opengl_group.add_argument('--gl-flavor', choices=['core', 'es', 'compatibility', 'legacy'], default='compatibility', help='OpenGL profile to use.') |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
63 opengl_group.add_argument('--gl-version', default=2.1, type=float, help='OpenGL version to use.') |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
64 |
554
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
65 double_buffer = opengl_group.add_mutually_exclusive_group() |
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
66 double_buffer.add_argument('--double-buffer', dest='double_buffer', action='store_true', default=None, help='Enable double buffering.') |
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
67 double_buffer.add_argument('--single-buffer', dest='double_buffer', action='store_false', default=None, help='Disable double buffering.') |
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
68 |
416
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
69 args = parser.parse_args() |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
70 |
e23871eddb7a
Importing everything makes the --help slow, call parse_args before the imports.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
415
diff
changeset
|
71 |
338
65453340ae95
Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
337
diff
changeset
|
72 import sys |
363
cb1460b9b6cf
Enable debug messages when using --debug
Thibaut Girka <thib@sitedethib.com>
parents:
352
diff
changeset
|
73 import logging |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 |
543
fb837b32c3dd
Automatically fallback on the SDL renderer if the OpenGL one can’t be imported.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
534
diff
changeset
|
75 |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
546
diff
changeset
|
76 if args.game == 'EoSD': |
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
546
diff
changeset
|
77 from pytouhou.games.eosd import EoSDCommon as Common, EoSDGame as Game |
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
546
diff
changeset
|
78 |
548
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
79 if args.interface == 'EoSD': |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
80 from pytouhou.interfaces.eosd import EoSDInterface as Interface |
549
56bca8ce4b68
Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
81 elif args.interface == 'Sample': |
56bca8ce4b68
Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
548
diff
changeset
|
82 from pytouhou.interfaces.sample import SampleInterface as Interface |
548
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
83 |
512
b39ad30c6620
Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
508
diff
changeset
|
84 |
531
a7dc55ad9380
Display important messages in popups, instead of the terminal.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
530
diff
changeset
|
85 from pytouhou.lib.sdl import SDL, show_simple_message_box |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
86 from pytouhou.ui.window import Window |
97 | 87 from pytouhou.resource.loader import Loader |
205
ee6dfd14a785
Rename pytouhou.opengl to pytouhou.ui, makes much more sense that way.
Thibaut Girka <thib@sitedethib.com>
parents:
196
diff
changeset
|
88 from pytouhou.ui.gamerunner import GameRunner |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
89 from pytouhou.game.player import GameOver |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
90 from pytouhou.formats.t6rp import T6RP, Level |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
91 from pytouhou.utils.random import Random |
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
92 from pytouhou.vm.msgrunner import NextStage |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
93 from pytouhou.formats.hint import Hint |
486 | 94 from pytouhou.network import Network |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
95 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
96 |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
97 from importlib import import_module |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
98 for backend in args.backend: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
99 if backend == 'opengl': |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
100 options = { |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
101 'flavor': args.gl_flavor, |
554
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
102 'version': args.gl_version, |
653a9f087673
Make both double- and single-buffer available on the CLI, but default to SDL’s default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
553
diff
changeset
|
103 'double-buffer': args.double_buffer, |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
104 } |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
105 else: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
106 options = {} |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
107 |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
546
diff
changeset
|
108 try: |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
109 backend = import_module('pytouhou.ui.%s.backend' % backend) |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
110 except ImportError as e: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
111 continue |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
546
diff
changeset
|
112 |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
113 try: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
114 backend.init(options) |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
115 except Exception as e: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
116 print('Backend', backend, 'failed to initialize:', e) |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
117 pass |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
118 else: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
119 GameRenderer = backend.GameRenderer |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
120 break |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
121 else: |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
122 show_simple_message_box(u'No graphical backend could be used, continuing with a windowless game.') |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
123 backend = None |
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
124 GameRenderer = None |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 |
454
a502887557ac
Add an option to choose which game to play; currently only EoSD is supported.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
127 class GameBossRush(Game): |
499 | 128 def run_iter(self, keystates): |
337
bc162f60f0a0
Skip dialogs in the boss rush mode, and make boss rush skipping faster
Thibaut Girka <thib@sitedethib.com>
parents:
334
diff
changeset
|
129 for i in range(20): |
344
eab591728abf
Minor fix in boss rush mode
Thibaut Girka <thib@sitedethib.com>
parents:
341
diff
changeset
|
130 skip = not (self.enemies or self.items or self.lasers |
eab591728abf
Minor fix in boss rush mode
Thibaut Girka <thib@sitedethib.com>
parents:
341
diff
changeset
|
131 or self.bullets or self.cancelled_bullets) |
eab591728abf
Minor fix in boss rush mode
Thibaut Girka <thib@sitedethib.com>
parents:
341
diff
changeset
|
132 if skip: |
499 | 133 keystates = [k & ~1 for k in keystates] |
134 Game.run_iter(self, [0 if i else k | 256 for k in keystates]) | |
340
39bc59953dfa
Increase player's power stats during skipped frames in boss rush mode.
Thibaut Girka <thib@sitedethib.com>
parents:
339
diff
changeset
|
135 if not self.enemies and self.frame % 90 == 0: |
39bc59953dfa
Increase player's power stats during skipped frames in boss rush mode.
Thibaut Girka <thib@sitedethib.com>
parents:
339
diff
changeset
|
136 for player in self.players: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
137 if player.power < 128: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
138 player.power += 1 |
344
eab591728abf
Minor fix in boss rush mode
Thibaut Girka <thib@sitedethib.com>
parents:
341
diff
changeset
|
139 if not skip: |
332 | 140 break |
141 | |
142 def cleanup(self): | |
372
704bea2e4360
Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
143 boss_wait = any(ecl_runner.boss_wait for ecl_runner in self.ecl_runners) |
704bea2e4360
Use a future-proof ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
144 if not (self.boss or self.msg_wait or boss_wait): |
332 | 145 self.enemies = [enemy for enemy in self.enemies |
499 | 146 if enemy.boss_callback or enemy.frame > 1] |
500
777544d11578
[Boss rush] Mark removed lasers as such
Thibaut Girka <thib@sitedethib.com>
parents:
499
diff
changeset
|
147 for laser in self.lasers: |
777544d11578
[Boss rush] Mark removed lasers as such
Thibaut Girka <thib@sitedethib.com>
parents:
499
diff
changeset
|
148 if laser.frame <= 1: |
777544d11578
[Boss rush] Mark removed lasers as such
Thibaut Girka <thib@sitedethib.com>
parents:
499
diff
changeset
|
149 laser.removed = True |
332 | 150 self.lasers = [laser for laser in self.lasers if laser.frame > 1] |
151 self.bullets = [bullet for bullet in self.bullets if bullet.frame > 1] | |
454
a502887557ac
Add an option to choose which game to play; currently only EoSD is supported.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
452
diff
changeset
|
152 Game.cleanup(self) |
332 | 153 |
154 | |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
155 def main(window, path, data, stage_num, rank, character, replay, save_filename, |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
156 skip_replay, boss_rush, debug, enable_background, enable_particles, |
530
64d9117b9209
Replace the --no-music option with --no-sound, disabling sound rendering altogether.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
157 hints, verbosity, port, remote, friendly_fire): |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
158 |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
159 resource_loader = Loader(path) |
338
65453340ae95
Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
337
diff
changeset
|
160 |
65453340ae95
Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
337
diff
changeset
|
161 try: |
65453340ae95
Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
337
diff
changeset
|
162 resource_loader.scan_archives(data) |
65453340ae95
Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
337
diff
changeset
|
163 except IOError: |
531
a7dc55ad9380
Display important messages in popups, instead of the terminal.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
530
diff
changeset
|
164 show_simple_message_box(u'Some data files were not found, did you forget the -p option?') |
a7dc55ad9380
Display important messages in popups, instead of the terminal.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
530
diff
changeset
|
165 sys.exit(1) |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
166 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
167 if stage_num is None: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
168 story = True |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
169 stage_num = 1 |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
170 continues = 3 |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
171 else: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
172 story = False |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
173 continues = 0 |
339
7a05edbab88a
Implement continues when the lives fall bellow 0.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
338
diff
changeset
|
174 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
175 if debug: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
176 if not verbosity: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
177 verbosity = 'DEBUG' |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
178 continues = -1 # Infinite lives |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
179 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
180 if verbosity: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
181 logging.basicConfig(level=logging.__getattribute__(verbosity)) |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
182 |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
183 if replay: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
184 with open(replay, 'rb') as file: |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
185 replay = T6RP.read(file) |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
186 rank = replay.rank |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
187 character = replay.character |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
188 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
189 save_keystates = None |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
190 if save_filename: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
191 save_replay = T6RP() |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
192 save_replay.rank = rank |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
193 save_replay.character = character |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
186
diff
changeset
|
194 |
487
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
195 difficulty = 16 |
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
196 |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
197 if port != 0: |
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
198 if remote: |
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
199 remote_addr, remote_port = remote.split(':') |
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
200 addr = remote_addr, int(remote_port) |
479
1de67f332f00
Fix several synchro issues
Thibaut Girka <thib@sitedethib.com>
parents:
476
diff
changeset
|
201 selected_player = 0 |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
202 else: |
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
203 addr = None |
479
1de67f332f00
Fix several synchro issues
Thibaut Girka <thib@sitedethib.com>
parents:
476
diff
changeset
|
204 selected_player = 1 |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
205 |
476 | 206 prng = Random(0) |
479
1de67f332f00
Fix several synchro issues
Thibaut Girka <thib@sitedethib.com>
parents:
476
diff
changeset
|
207 con = Network(port, addr, selected_player) |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
208 characters = [1, 3] |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
209 else: |
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
210 con = None |
487
711c75115675
Various netplay-related fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
486
diff
changeset
|
211 selected_player = 0 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
212 characters = [character] |
475
9d4d52793eca
Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
213 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
214 if hints: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
215 with open(hints, 'rb') as file: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
216 hints = Hint.read(file) |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
217 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
218 game_class = GameBossRush if boss_rush else Game |
332 | 219 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
220 common = Common(resource_loader, characters, continues, stage_num - 1) |
548
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
221 interface = Interface(resource_loader, common.players[0]) #XXX |
1e9ea6519f3c
Make EoSDInterface separate from EoSD game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
222 common.interface = interface #XXX |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
223 renderer = GameRenderer(resource_loader, window) if GameRenderer is not None else None |
508
1bc014f9d572
Make GameRunner entirely independent of Window or GameRenderer, so we can run a game without display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
224 runner = GameRunner(window, renderer, common, resource_loader, skip_replay, con) |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
500
diff
changeset
|
225 window.set_runner(runner) |
508
1bc014f9d572
Make GameRunner entirely independent of Window or GameRenderer, so we can run a game without display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
226 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
227 while True: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
228 first_player = common.players[0] |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
229 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
230 if replay: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
231 level = replay.levels[stage_num - 1] |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
232 if not level: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
233 raise Exception |
262
8fa660da5f0c
Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents:
231
diff
changeset
|
234 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
235 prng = Random(level.random_seed) |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
236 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
237 #TODO: apply the replay to the other players. |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
238 #TODO: see if the stored score is used or if it’s the one from the previous stage. |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
239 if stage_num != 1 and stage_num - 2 in replay.levels: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
240 previous_level = replay.levels[stage_num - 1] |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
241 first_player.score = previous_level.score |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
242 first_player.effective_score = previous_level.score |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
243 first_player.points = level.point_items |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
244 first_player.power = level.power |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
245 first_player.lives = level.lives |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
246 first_player.bombs = level.bombs |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
247 difficulty = level.difficulty |
486 | 248 elif port == 0: |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
249 prng = Random() |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
250 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
251 if save_filename: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
252 if not replay: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
253 save_replay.levels[stage_num - 1] = level = Level() |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
254 level.random_seed = prng.seed |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
255 level.score = first_player.score |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
256 level.point_items = first_player.points |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
257 level.power = first_player.power |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
258 level.lives = first_player.lives |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
259 level.bombs = first_player.bombs |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
260 level.difficulty = difficulty |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
261 save_keystates = [] |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
262 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
263 hints_stage = hints.stages[stage_num - 1] if hints else None |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
264 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
492
diff
changeset
|
265 game = game_class(resource_loader, stage_num, rank, difficulty, |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
500
diff
changeset
|
266 common, prng, hints_stage, friendly_fire) |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
267 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
268 if not enable_particles: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
269 def new_particle(pos, anim, amp, number=1, reverse=False, duration=24): |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
270 pass |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
271 game.new_particle = new_particle |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
272 |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
273 background = game.background if enable_background else None |
530
64d9117b9209
Replace the --no-music option with --no-sound, disabling sound rendering altogether.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
274 runner.load_game(game, background, game.std.bgms, replay, save_keystates) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
275 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
276 try: |
530
64d9117b9209
Replace the --no-music option with --no-sound, disabling sound rendering altogether.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
277 # Main loop |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
278 window.run() |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
279 break |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
280 except NextStage: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
281 if not story or stage_num == (7 if boss_rush else 6 if rank > 0 else 5): |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
282 break |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
283 stage_num += 1 |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
284 except GameOver: |
531
a7dc55ad9380
Display important messages in popups, instead of the terminal.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
530
diff
changeset
|
285 show_simple_message_box(u'Game over!') |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
286 break |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
287 finally: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
288 if save_filename: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
289 last_key = -1 |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
290 for time, key in enumerate(save_keystates): |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
291 if key != last_key: |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
292 level.keys.append((time, key, 0)) |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
293 last_key = key |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
294 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
295 window.set_runner(None) |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
296 |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
297 if save_filename: |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
298 with open(save_filename, 'wb+') as file: |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
372
diff
changeset
|
299 save_replay.write(file) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
300 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
301 |
530
64d9117b9209
Replace the --no-music option with --no-sound, disabling sound rendering altogether.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
302 with SDL(sound=args.no_sound): |
553
8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
549
diff
changeset
|
303 window = Window(backend, fps_limit=args.fps_limit) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
304 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
305 main(window, args.path, tuple(args.data), args.stage, args.rank, |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
306 args.character, args.replay, args.save_replay, args.skip_replay, |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
307 args.boss_rush, args.debug, args.no_background, args.no_particles, |
530
64d9117b9209
Replace the --no-music option with --no-sound, disabling sound rendering altogether.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
308 args.hints, args.verbosity, args.port, args.remote, |
534
346cbf266856
Move options to logical groups, to make the help a bit less dry; and disable friendly-fire by default.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
531
diff
changeset
|
309 args.friendly_fire) |
186
84da28ae7ee4
Parse command line with argparse.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
162
diff
changeset
|
310 |
469
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
311 import gc |
58b47e788c59
Move SDL context-manager and Window creation outside of main.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
465
diff
changeset
|
312 gc.collect() |