Mercurial > sypikslang
annotate gamelib/main.py @ 38:7e18a67995f6
fixed pep8 issues
author | Rizmari Versfeld <rizziepit@gmail.com> |
---|---|
date | Mon, 07 May 2012 00:13:11 +0200 |
parents | 9c4bf1f15431 |
children | d82d3e54a4ef |
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 |
9 from pygame.locals import * | |
10 from pygame.event import * | |
11 from pygame.time import Clock | |
12 from pygame import Surface | |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
13 |
37 | 14 from gamelib import data |
15 | |
16 from gamelib.gui_base import * | |
17 from gamelib.gui import * | |
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 |
37 | 20 pygame.init() |
21 | |
22 FPS = 30 | |
23 | |
24 GAME_IS_RUNNING = True | |
25 | |
26 WINDOW_STACK = [] | |
27 | |
28 # input variables | |
29 MOUSE_DOWN = False | |
38 | 30 |
31 | |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
32 def main(): |
38 | 33 clock = Clock() |
34 screen = pygame.display.set_mode((800, 600)) | |
35 window = Window(screen) | |
36 window.background_colour = (0, 0, 0) | |
37 button1 = BigButton(((800 - 128) / 2, 200), 'Start') | |
38 window.add_child(button1) | |
39 WINDOW_STACK.append(window) | |
40 while GAME_IS_RUNNING: | |
41 process_input() | |
42 draw(screen) | |
43 clock.tick(FPS) | |
37 | 44 |
38 | 45 |
37 | 46 def draw(screen): |
38 | 47 for view in WINDOW_STACK: |
48 view.draw(screen) | |
49 pygame.display.flip() | |
50 | |
51 | |
37 | 52 def process_input(): |
38 | 53 global MOUSE_DOWN |
54 global GAME_IS_RUNNING | |
55 for event in pygame.event.get(): | |
56 if MOUSE_DOWN: | |
57 if event.type == MOUSEBUTTONUP: | |
58 MOUSE_DOWN = False | |
59 WINDOW_STACK[len(WINDOW_STACK) - 1].on_mouse_up(event.pos) | |
60 elif event.type == MOUSEMOTION: | |
61 WINDOW_STACK[len(WINDOW_STACK) - 1].on_mouse_move(event.pos) | |
62 elif not MOUSE_DOWN and event.type == MOUSEBUTTONDOWN: | |
63 MOUSE_DOWN = True | |
64 WINDOW_STACK[len(WINDOW_STACK) - 1].on_mouse_down(event.pos) | |
65 elif event.type == QUIT: | |
66 GAME_IS_RUNNING = False |