Mercurial > rinkhals
annotate gamelib/engine.py @ 141:dc4bb10cc54c
Fix crash.
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 23:01:50 +0000 |
parents | 1d73de63bd71 |
children | 1597081e5a84 |
rev | line source |
---|---|
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
1 """Game engine and states.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
2 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
3 from pgu.engine import Game, State, Quit |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
4 import pygame |
31
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
5 from pygame.locals import USEREVENT, QUIT, KEYDOWN, K_ESCAPE, K_n, K_d, K_s |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
6 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
7 import gameboard |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
8 import gameover |
94 | 9 import sound |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
10 import constants |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
11 import mainmenu |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
12 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
13 class Engine(Game): |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
14 def __init__(self, main_app): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
15 self.main_app = main_app |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
16 self.clock = pygame.time.Clock() |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
17 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
18 def tick(self): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
19 """Tic toc.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
20 pygame.time.wait(10) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
21 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
22 def create_game_board(self): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
23 self.gameboard = gameboard.GameBoard() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
24 |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
25 def set_main_menu(self): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
26 """Create the main menu""" |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
27 mainmenu.add_main_menu(self.main_app) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
28 |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
29 def generate_score(self): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
30 """Create the Game Over state""" |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
31 gameover.add_game_over(self.main_app, self.gameboard) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
32 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
33 class MainMenuState(State): |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
34 def init(self): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
35 self.game.set_main_menu() |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
36 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
37 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
38 if events_equal(e, START_DAY): |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
39 self.game.create_game_board() |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
40 return DayState(self.game) |
31
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
41 elif e.type is KEYDOWN: |
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
42 if e.key == K_ESCAPE: |
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
43 return Quit(self.game) |
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
44 elif e.key == K_s: |
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
45 self.game.create_game_board() |
3c4db7bba432
Add 's' as a key for starting the game from the menu.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
46 return DayState(self.game) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
47 elif e.type is not QUIT: |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
48 self.game.main_app.event(e) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
49 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
50 def paint(self, screen): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
51 screen.fill((0,0,0)) |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
52 self.game.main_app.paint(screen) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
53 pygame.display.flip() |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
54 |
15
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
55 def update(self, screen): |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
56 update = self.game.main_app.update(screen) |
15
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
57 pygame.display.update(update) |
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
58 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
59 class DayState(State): |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
60 def init(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
61 """Add some chickens to the farm""" |
99
f5d56688943b
Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents:
98
diff
changeset
|
62 sound.stop_background_music() |
30 | 63 self.game.gameboard.tv.sun(True) |
64 | |
98
725b292ca07b
Added sounds killing foxes and chickens, and nightfall
David Fraser <davidf@sjsoft.com>
parents:
94
diff
changeset
|
65 sound.play_sound("daybreak.ogg") |
29 | 66 # disable timer |
67 pygame.time.set_timer(MOVE_FOX_ID, 0) | |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
68 self.game.gameboard.advance_day() |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
69 self.game.gameboard.clear_foxes() |
99
f5d56688943b
Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents:
98
diff
changeset
|
70 sound.background_music("daytime.ogg") |
116
d539ef5a3333
Add basic chicken->egg cycle
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
71 self.game.gameboard.hatch_eggs() |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
72 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
73 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
74 if events_equal(e, START_NIGHT): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
75 return NightState(self.game) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
76 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
77 return MainMenuState(self.game) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
78 elif e.type is KEYDOWN and e.key == K_n: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
79 return pygame.event.post(START_NIGHT) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
80 elif events_equal(e, GO_MAIN_MENU): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
81 return MainMenuState(self.game) |
14 | 82 elif e.type is not QUIT: |
83 self.game.gameboard.event(e) | |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
84 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
85 def paint(self, screen): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
86 self.game.gameboard.paint(screen) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
87 pygame.display.flip() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
88 |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
89 def update(self, screen): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
90 update = self.game.gameboard.update(screen) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
91 pygame.display.update(update) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
92 |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
93 def loop(self): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
94 self.game.gameboard.loop() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
95 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
96 class NightState(State): |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
97 def init(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
98 """Add some foxes to the farm""" |
99
f5d56688943b
Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents:
98
diff
changeset
|
99 sound.stop_background_music() |
30 | 100 self.game.gameboard.tv.sun(False) |
101 | |
98
725b292ca07b
Added sounds killing foxes and chickens, and nightfall
David Fraser <davidf@sjsoft.com>
parents:
94
diff
changeset
|
102 sound.play_sound("nightfall.ogg") |
29 | 103 # Add a timer to the event queue |
104 self.cycle_count = 0 | |
69
18db99fda6bd
Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
31
diff
changeset
|
105 pygame.time.set_timer(MOVE_FOX_ID, 200) |
18db99fda6bd
Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
31
diff
changeset
|
106 self.game.gameboard.spawn_foxes() |
99
f5d56688943b
Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents:
98
diff
changeset
|
107 sound.background_music("nighttime.ogg") |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
108 |
116
d539ef5a3333
Add basic chicken->egg cycle
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
109 self.game.gameboard.lay_eggs() |
d539ef5a3333
Add basic chicken->egg cycle
Neil Muller <drnlmuller@gmail.com>
parents:
99
diff
changeset
|
110 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
111 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
112 if events_equal(e, START_DAY): |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
113 if self.game.gameboard.is_game_over(): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
114 return GameOver(self.game) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
115 return DayState(self.game) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
116 elif e.type is KEYDOWN and e.key == K_d: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
117 return pygame.event.post(START_DAY) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
118 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
119 return MainMenuState(self.game) |
29 | 120 elif e.type is MOVE_FOX_ID: |
121 self.cycle_count += 1 | |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
122 if self.cycle_count > constants.NIGHT_LENGTH: |
29 | 123 return pygame.event.post(START_DAY) |
122
d2b19131d537
Don't continue the night if we're not doing anything anymore
Neil Muller <drnlmuller@gmail.com>
parents:
118
diff
changeset
|
124 if self.game.gameboard.move_foxes(): |
d2b19131d537
Don't continue the night if we're not doing anything anymore
Neil Muller <drnlmuller@gmail.com>
parents:
118
diff
changeset
|
125 # All foxes are gone/safe, so dawn happens |
d2b19131d537
Don't continue the night if we're not doing anything anymore
Neil Muller <drnlmuller@gmail.com>
parents:
118
diff
changeset
|
126 return pygame.event.post(START_DAY) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
127 elif e.type is not QUIT: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
128 self.game.gameboard.event(e) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
129 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
130 def loop(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
131 self.game.gameboard.loop() |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
132 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
133 def paint(self, screen): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
134 self.game.gameboard.paint(screen) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
135 pygame.display.flip() |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
136 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
137 def update(self, screen): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
138 update = self.game.gameboard.update(screen) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
139 pygame.display.update(update) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
140 |
139
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
141 class GameOver(State): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
142 def init(self): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
143 """Setup everything""" |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
144 self.game.generate_score() |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
145 |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
146 def event(self, e): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
147 if e.type is KEYDOWN: |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
148 if e.key == K_ESCAPE: |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
149 return MainMenuState(self.game) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
150 elif events_equal(e, GO_MAIN_MENU): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
151 return MainMenuState(self.game) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
152 elif e.type is not QUIT: |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
153 self.game.main_app.event(e) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
154 |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
155 def paint(self, screen): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
156 screen.fill((0,0,0)) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
157 self.game.main_app.paint(screen) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
158 pygame.display.flip() |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
159 |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
160 def update(self, screen): |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
161 update = self.game.main_app.update(screen) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
162 pygame.display.update(update) |
1d73de63bd71
Add basic game over screen
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
163 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
164 # pygame events |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
165 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
166 def events_equal(e1, e2): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
167 """Compare two user events.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
168 return (e1.type is e2.type and e1.name == e2.name) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
169 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
170 START_DAY = pygame.event.Event(USEREVENT, name="START_DAY") |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
171 START_NIGHT = pygame.event.Event(USEREVENT, name="START_NIGHT") |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
172 GO_MAIN_MENU = pygame.event.Event(USEREVENT, name="GO_MAIN_MENU") |
29 | 173 MOVE_FOX_ID = USEREVENT + 1 |
174 MOVE_FOXES = pygame.event.Event(MOVE_FOX_ID, name="MOVE_FOXES") | |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
175 QUIT = pygame.event.Event(QUIT) |