/
gamespit
executable file
·68 lines (50 loc) · 1.46 KB
/
gamespit
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
#!/usr/bin/python
# -*- coding: utf8 -*-
# gamespit
# Games suite for kids using Raspberry Pi (or equivalent)
# Author: Alfonso E.M. <alfonso@el-magnifico.org>
# License: Free (GPL2)
# Version: 1.0 - 27/Feb/2013
from configobj import ConfigObj
import imp
import sys
import os
sys.path.append("./lib")
sys.path.append("./games")
import Gui
import Controls
# Load a module or plugin dinamically
def load_game(name, conf, display, controller):
if conf.as_bool("debug"):
print("Loading game:", name)
fp, pathname, description = imp.find_module(name)
try:
module=imp.load_module(name, fp, pathname, description)
result=module.main(name, conf, display, controller)
except ValueError as e:
# except Exception as e:
print("ERROR:", e, e.args)
result="ERROR"
finally:
if fp:
fp.close()
return result
# Main
def main():
# Load main config file
CONF = ConfigObj("gamespit.conf")
# Create a Graphic User Interface
display = Gui.Display(CONF["DISPLAY"])
# Create a Controller (keyboard, joystick..)
controller = Controls.Control(CONF["CONTROL"])
while True:
# Load the main menu (main menu is a game itself)
CONF.reload()
new_game=load_game("menu", CONF, display, controller)
# Load selected game
if new_game:
display.fade(speed=90)
CONF.reload()
new_game=load_game(new_game, CONF, display, controller)
if __name__ == '__main__':
main()