Mercurial > sypikslang
comparison 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 |
comparison
equal
deleted
inserted
replaced
35:2754c453b39b | 37:9c4bf1f15431 |
---|---|
3 Contains the entry point used by the run_game.py script. | 3 Contains the entry point used by the run_game.py script. |
4 | 4 |
5 Feel free to put all your game code here, or in other modules in this "gamelib" | 5 Feel free to put all your game code here, or in other modules in this "gamelib" |
6 package. | 6 package. |
7 ''' | 7 ''' |
8 import pygame | |
9 from pygame.locals import * | |
10 from pygame.event import * | |
11 from pygame.time import Clock | |
12 from pygame import Surface | |
8 | 13 |
9 import data | 14 from gamelib import data |
15 | |
16 from gamelib.gui_base import * | |
17 from gamelib.gui import * | |
10 | 18 |
11 | 19 |
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 | |
12 def main(): | 32 def main(): |
13 print "Hello from your game's main()" | 33 #print data.load('sample.txt').read() |
14 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 |