Mercurial > rinkhals
comparison gamelib/engine.py @ 12:8a7319e4853a
Hooked in the game board.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 15:20:17 +0000 |
parents | 5d58a5b13731 |
children | d7f295c06a4b |
comparison
equal
deleted
inserted
replaced
11:5d58a5b13731 | 12:8a7319e4853a |
---|---|
1 """Game engine and states.""" | 1 """Game engine and states.""" |
2 | 2 |
3 from pgu.engine import Game, State, Quit | 3 from pgu.engine import Game, State, Quit |
4 import pygame | 4 import pygame |
5 from pygame.locals import USEREVENT, QUIT, KEYDOWN, K_ESCAPE | 5 from pygame.locals import USEREVENT, QUIT, KEYDOWN, K_ESCAPE |
6 | |
7 import gameboard | |
6 | 8 |
7 class Engine(Game): | 9 class Engine(Game): |
8 def __init__(self, main_menu_app): | 10 def __init__(self, main_menu_app): |
9 self.main_menu_app = main_menu_app | 11 self.main_menu_app = main_menu_app |
10 self.clock = pygame.time.Clock() | 12 self.clock = pygame.time.Clock() |
11 | 13 |
12 def tick(self): | 14 def tick(self): |
13 """Tic toc.""" | 15 """Tic toc.""" |
14 pygame.time.wait(10) | 16 pygame.time.wait(10) |
15 | 17 |
18 def create_game_board(self): | |
19 self.gameboard = gameboard.GameBoard() | |
20 | |
16 class MainMenuState(State): | 21 class MainMenuState(State): |
17 def event(self, e): | 22 def event(self, e): |
18 if events_equal(e, START_DAY): | 23 if events_equal(e, START_DAY): |
24 self.game.create_game_board() | |
19 return DayState(self.game) | 25 return DayState(self.game) |
20 elif e.type is KEYDOWN and e.key == K_ESCAPE: | 26 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
21 return Quit(self.game) | 27 return Quit(self.game) |
22 elif e.type is not QUIT: | 28 elif e.type is not QUIT: |
23 self.game.main_menu_app.event(e) | 29 self.game.main_menu_app.event(e) |
34 elif e.type is KEYDOWN and e.key == K_ESCAPE: | 40 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
35 return MainMenuState(self.game) | 41 return MainMenuState(self.game) |
36 elif events_equal(e, GO_MAIN_MENU): | 42 elif events_equal(e, GO_MAIN_MENU): |
37 return MainMenuState(self.game) | 43 return MainMenuState(self.game) |
38 | 44 |
45 def paint(self, screen): | |
46 self.game.gameboard.paint(screen) | |
47 pygame.display.flip() | |
48 | |
49 def update(self, screen): | |
50 update = self.game.gameboard.update(screen) | |
51 pygame.display.update(update) | |
52 | |
53 def loop(self): | |
54 self.game.gameboard.loop() | |
55 | |
39 class NightState(State): | 56 class NightState(State): |
40 def event(self, e): | 57 def event(self, e): |
41 if events_equal(e, START_DAY): | 58 if events_equal(e, START_DAY): |
42 return DayState(self.game) | 59 return DayState(self.game) |
43 | 60 |