annotate gamelib/main.py @ 88:74ce25ec2073

Autosave & load support
author Neil Muller <drnlmuller@gmail.com>
date Wed, 09 May 2012 20:07:14 +0200
parents a253fae32a6f
children 80cce62f29fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
9c4bf1f15431 gui stuff
Rizmari Versfeld <rizziepit@gmail.com>
parents: 1
diff changeset
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
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents: 52
diff changeset
13 from gamelib.mainmenu import MainMenu
52
1d3d20bdc8b9 Move engine stuff into it's own file
Neil Muller <drnlmuller@gmail.com>
parents: 51
diff changeset
14
61
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
15 from gamelib.constants import SCREEN, FREQ, BITSIZE, CHANNELS, BUFFER
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
16
1
c90a6586cd66 PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents: 0
diff changeset
17
61
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
18 def parse_args(args):
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
19 parser = optparse.OptionParser()
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
20
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
21 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
22 dest="sound", help="disable sound")
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
23
88
74ce25ec2073 Autosave & load support
Neil Muller <drnlmuller@gmail.com>
parents: 61
diff changeset
24 parser.add_option('--load', type="string", default=None,
74ce25ec2073 Autosave & load support
Neil Muller <drnlmuller@gmail.com>
parents: 61
diff changeset
25 dest="load", help="Save game to load")
74ce25ec2073 Autosave & load support
Neil Muller <drnlmuller@gmail.com>
parents: 61
diff changeset
26
61
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
27 return parser.parse_args(args)
37
9c4bf1f15431 gui stuff
Rizmari Versfeld <rizziepit@gmail.com>
parents: 1
diff changeset
28
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
29
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
30 def main():
61
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
31 opts, args = parse_args(sys.argv)
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
32 pygame.display.init()
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
33 pygame.font.init()
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
34 if opts.sound:
a253fae32a6f Add no-sound option (slow shutdown bug workaround)
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
35 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
48
a2980cc9a060 Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents: 44
diff changeset
36 screen = pygame.display.set_mode(SCREEN)
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
37 engine = Engine(screen)
88
74ce25ec2073 Autosave & load support
Neil Muller <drnlmuller@gmail.com>
parents: 61
diff changeset
38 window = MainMenu(screen, opts.load)
51
ac637e84f8f8 Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents: 48
diff changeset
39 engine.run(window)