Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit e02b66129dc1b6450d357b9df29de10bf35c42fe

Update README.
README.txt
(102 / 22)
  
11== Sugargame ==
22
3Sugargame allows Pygame programs to run well under Sugar. It is fork of the
4olcpgames framework, which is no longer maintained.
3Sugargame is a Python package which allows [http://www.pygame.org/ Pygame]
4programs to run well under Sugar.
5It is fork of the olcpgames framework, which is no longer maintained.
56
6Sugargame embeds the Pygame window into a GTK window, and translates GTK
7events to Pygame events.
8
97What it does:
108
11 * Wraps a Sugar activity around an existing Pygame program with few changes
12 * Allows Sugar toolbars and other widgets to be added to the activity UI
13 * Provides hooks for saving to and restoring from the Journal
9* Wraps a Sugar activity around an existing Pygame program with few changes
10* Allows Sugar toolbars and other widgets to be added to the activity UI
11* Provides hooks for saving to and restoring from the Journal
1412
15Advantages vs olpcgames:
13==== Differences between Sugargame and olpcgames ====
1614
17 * Simpler code
18 * More elegant interface between Pygame and GTK
19 * Runs as a single thread: no thread related segfaults
15The olpcgames framework provides a wrapper around Pygame which attempts to
16allow a Pygame program to run mostly unmodified under Sugar. To this end,
17the Pygame program is run in a separate thread with its own Pygame message
18loop while the main thread runs the GTK message loop. Also, olpcgames wraps
19Sugar APIs such as the journal and mesh into a Pygame-like API.
2020
21 == Using Sugargame ==
22
23To use Sugargame in an activity, copy the sugargame folder into the activity's
24source directory.
25
21Sugargame takes a simpler approach; it provides a way to embed Pygame into a
22GTK widget. The Sugar APIs are used to interact with Sugar, the Pygame APIs
23are used for the game.
24
25Sugargame advantages:
26
27* Simpler code
28* More elegant interface between Pygame and GTK
29* Runs as a single thread: no thread related segfaults
30* Possible to use Sugar widgets with Pygame
31
32Sugargame limitations:
33
34* No support for Pango or SVG sprites (yet)
35
36== Using Sugargame ==
37
38See also [[Development Team/Sugargame/Examples]].
39
40==== Wrapping a Pygame program ====
41
42To use Sugargame to Sugarize a Pygame program, set up an activity directory and
43copy the Sugargame package to it.
44
2645The activity directory should look something like this:
2746
2847 activity/ - Activity directory: activity.info, SVG icon, etc.
4949 MyActivity.py - Activity class
5050 mygame.py - Pygame code
5151 setup.py - Install script
52
53To make the Activity class, start with test/TestActivity.py.
5452
53To make the Activity class, start with test/TestActivity.py from the Sugargame
54distribution.
55
56The activity should create a single PygameCanvas widget and call run_pygame on it.
57Pass the main loop function of the Pygame program.
58
59 self._canvas = sugargame.canvas.PygameCanvas(self)
60 self.set_canvas(self._canvas)
61
62 # Start the game running.
63 self._canvas.run_pygame(self.game.run)
64
65In your Pygame main loop, pump the GTK message loop:
66
67 while gtk.events_pending():
68 gtk.main_iteration()
69
70==== Adding Pygame to a PyGTK activity ====
71
72To add Pygame to an existing Sugar activity, create a PygameCanvas widget and call
73run_pygame on it.
74
75 widget = sugargame.canvas.PygameCanvas(self)
76 vbox.pack_start(widget)
77
78 widget.run_pygame(self.game.run)
79
80Due to limitations of Pygame and SDL, there can only be one PygameCanvas in the
81entire activity.
82
83The argument to run_pygame is a function structured like a Pygame program. In the
84main loop, remember to dispatch GTK messages using gtk.main_iteration().
85
86 def main_loop():
87 clock = pygame.time.Clock()
88 screen = pygame.display.get_surface()
89
90 while self.running:
91 # Pump GTK messages.
92 while gtk.events_pending():
93 gtk.main_iteration()
94
95 # Pump PyGame messages.
96 for event in pygame.event.get():
97 if event.type == pygame.QUIT:
98 return
99
100 # Clear Display
101 screen.fill((255,255,255)) #255 for white
102
103 # Draw stuff here
104 .................
105
106 # Flip Display
107 pygame.display.flip()
108
109 # Try to stay at 30 FPS
110 self.clock.tick(30)
111
55112== Support ==
56113
57114For help with Sugargame, please email the Sugar Labs development list:
58115
59 sugar-devel@lists.sugarlabs.org
116: sugar-devel@lists.sugarlabs.org
60117
61== Author ==
62
63118Sugargame is developed by Wade Brainerd <wadetb@gmail.com>.
119
64120It is loosely based on the source code to the olpcgames framework, developed by
65121the One Laptop Per Child project.
122
123=== Changelog ===
124
125====v1.0====
126Initial version of Sugargame