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