Mercurial > sypikslang
annotate gamelib/main.py @ 163:80cce62f29fb
Add placeholder icons for now
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 11 May 2012 23:19:23 +0200 |
parents | 74ce25ec2073 |
children | 75033f790e7d |
rev | line source |
---|---|
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
1 '''Game main module. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
2 |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
3 Contains the entry point used by the run_game.py script. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
4 |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
5 Feel free to put all your game code here, or in other modules in this "gamelib" |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
6 package. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
7 ''' |
37 | 8 import pygame |
61
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
9 import optparse |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
10 import sys |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
11 |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
12 from gamelib.engine import Engine |
163
80cce62f29fb
Add placeholder icons for now
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
13 from gamelib.data import load_image |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
52
diff
changeset
|
14 from gamelib.mainmenu import MainMenu |
52
1d3d20bdc8b9
Move engine stuff into it's own file
Neil Muller <drnlmuller@gmail.com>
parents:
51
diff
changeset
|
15 |
163
80cce62f29fb
Add placeholder icons for now
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
16 from gamelib.constants import (SCREEN, FREQ, BITSIZE, CHANNELS, BUFFER, |
80cce62f29fb
Add placeholder icons for now
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
17 WINDOW_ICON) |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
18 |
1
c90a6586cd66
PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents:
0
diff
changeset
|
19 |
61
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
20 def parse_args(args): |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
21 parser = optparse.OptionParser() |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
22 |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
23 parser.add_option('--no-sound', action="store_false", default=True, |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
24 dest="sound", help="disable sound") |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
25 |
88 | 26 parser.add_option('--load', type="string", default=None, |
27 dest="load", help="Save game to load") | |
28 | |
61
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
29 return parser.parse_args(args) |
37 | 30 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
31 |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
32 def main(): |
61
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
33 opts, args = parse_args(sys.argv) |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
34 pygame.display.init() |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
35 pygame.font.init() |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
36 if opts.sound: |
a253fae32a6f
Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
37 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
38 screen = pygame.display.set_mode(SCREEN) |
163
80cce62f29fb
Add placeholder icons for now
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
39 pygame.display.set_icon(load_image(WINDOW_ICON)) |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
40 engine = Engine(screen) |
88 | 41 window = MainMenu(screen, opts.load) |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
42 engine.run(window) |