File: main.py

package info (click to toggle)
solarwolf 1.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,348 kB
  • ctags: 371
  • sloc: python: 2,640; makefile: 56; sh: 31
file content (88 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download
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
"""main module, starts game and main loop"""

try:
    import sys
    import pygame
    import game, gfx, snd, input
    import allmodules
    import FpsClock
    import players
#except ImportError, msg:
#    import messagebox
#    messagebox.error('Error Initializing', msg.args[0])
#    raise
except RuntimeError: raise

#at this point, all needed pygame modules should
#be imported, so they can be initialized at the
#start of main()



def main(args):
    try:
        gamemain(args)
    except KeyboardInterrupt:
        print 'Keyboard Interrupt (Control-C)...'
        print 'Exiting'


class MyFpsClock(FpsClock.FpsClock):
    def report(self):
        #FpsClock.FpsClock.report(self)
        if gfx.starobj: gfx.starobj.recalc_num_stars(self.current_fps)


def gamemain(args):
    #initialize all our code (not load resources)
    pygame.init()
    game.clock = MyFpsClock(40, 1)

    size = 800, 600
    full = '-window' not in args
    gfx.initialize(size, full)
    pygame.display.set_caption('SolarWolf')        

    if not '-nosound' in args:
        snd.initialize()
    input.init()
    players.load_players()

    #create the starting game handler
    from gameinit import GameInit
    from gamefinish import GameFinish
    game.handler = GameInit(GameFinish(None))

    
    #main game loop
    lasthandler = None
    while game.handler:
        handler = game.handler
        if handler != lasthandler:
            lasthandler = handler
            if hasattr(handler, 'starting'):
                handler.starting()
        for event in pygame.event.get():
            inputtype = input.translate(event)
            if inputtype:
                handler.input(inputtype)
            elif event.type == pygame.QUIT:
                game.handler = None
                break
            handler.event(event)
        handler.run()
        game.clock.tick() #note, tick can cause stars to erase
        gfx.update()
        while not pygame.display.get_active():
            pygame.time.delay(100)
            pygame.event.pump()

        #pygame.time.delay(18)

    #game is finished at this point, do any
    #uninitialization needed
    players.save_players()
    pygame.quit()