Mercurial > sypikslang
annotate gamelib/main.py @ 37:9c4bf1f15431
gui stuff
author | Rizmari Versfeld <rizziepit@gmail.com> |
---|---|
date | Sun, 06 May 2012 22:05:40 +0200 |
parents | c90a6586cd66 |
children | 7e18a67995f6 |
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 | |
30 | |
31 | |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
32 def main(): |
37 | 33 #print data.load('sample.txt').read() |
34 clock = Clock() | |
35 screen = pygame.display.set_mode((800, 600)) | |
36 window = Window(screen) | |
37 window.background_colour = (0,0,0) | |
38 button1 = MainMenuButton(((800-128)/2, 200), 'Start') | |
39 window.add_child(button1) | |
40 WINDOW_STACK.append(window) | |
41 while GAME_IS_RUNNING: | |
42 process_input() | |
43 draw(screen) | |
44 clock.tick(FPS) | |
45 | |
46 | |
47 def draw(screen): | |
48 for view in WINDOW_STACK: | |
49 view.draw(screen) | |
50 pygame.display.flip() | |
51 | |
52 | |
53 def process_input(): | |
54 global MOUSE_DOWN | |
55 global GAME_IS_RUNNING | |
56 for event in pygame.event.get(): | |
57 if MOUSE_DOWN: | |
58 if event.type == MOUSEBUTTONUP: | |
59 MOUSE_DOWN = False | |
60 WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_up(event.pos) | |
61 elif event.type == MOUSEMOTION: | |
62 WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_move(event.pos) | |
63 elif not MOUSE_DOWN and event.type == MOUSEBUTTONDOWN: | |
64 MOUSE_DOWN = True | |
65 WINDOW_STACK[len(WINDOW_STACK)-1].on_mouse_down(event.pos) | |
66 elif event.type == QUIT: | |
67 GAME_IS_RUNNING = False | |
68 | |
69 | |
70 |