/
main.py
executable file
·105 lines (92 loc) · 3.47 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# main.py
#
# Guitar game using DSP.
# Main file. Reads command line options, initializes
# the graphics system, the scene director and hands
# over the control to the latter.
#
# Copyright (c) 2008-09 Jonne Mickelin & Jakob Florell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import error
######################
# Standard library #
######################
import sys, os
import optparse
######################
# Required libraries #
######################
error.debug("Attempting to import pyglet")
try:
import pyglet
except ImportError, err:
# put an error on the log
error.critical("This game requires pyglet. If you are using Windows, seeing this message is a BUG. Please file a bug report on http://guitarlegend.googlecode.com. Linux and OS X users should download Pyglet from http://www.pyglet.org.")
error.bail_out(err)
error.debug("Success!")
######################
# Game modules #
######################
error.debug("Importing options")
import options
error.debug("Success!")
error.debug("Importing manager stuffs")
from manager import game_manager, BasicWindow, MainWindow
error.debug("Success!")
def main():
# Parse the command line options
parser = optparse.OptionParser()
parser.add_option("--debug",
action="store_true",
dest="debug",
default=False,
help="start game in debugging mode")
parser.add_option("--show-fps",
action="store_true",
dest="show_fps",
default=False,
help="start game in debugging mode")
(opts, args) = parser.parse_args()
options.DEBUG = opts.debug
options.SHOW_FRAMERATE = opts.show_fps
# Setup a custom data directory
pyglet.resource.path = ["data"]
pyglet.resource.reindex()
error.debug("Importing scene")
import scene # Imported here, because it depends on the options used
error.debug("Success!")
error.debug("Importing menu")
import menu
error.debug("Success!")
# Add two windows
game_manager.add_window(MainWindow(width=options.window_width, height=options.window_height,
caption=options.__appname__, resizable=True),
"game_draw")
if options.DEBUG: game_manager.add_window(BasicWindow(caption="Debug"), "debug_draw")
# Add one scene
game_manager.push(menu.MainMenu())
# Start sound recordning here. Something is wrong with wonderful,
# leading to strange segfaults. I'm gonna see if this fixes it.
import wonderful
wonderful.init(options.SAMPLE_RATE, options.DFT_SIZE)
# Hand control over to the Game manager
error.debug("Hiya, I'm gonna hand control over to the game manager")
game_manager.run()
wonderful.terminate()
if __name__ == "__main__":
main()