Mercurial > rinkhals
annotate gamelib/engine.py @ 25:6d6ab0c1479d
Add placing some chickens and foxes
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 18:14:07 +0000 |
parents | b69d954f2f1d |
children | 2e88c680672c |
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 |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
5 from pygame.locals import USEREVENT, QUIT, KEYDOWN, K_ESCAPE, K_n, K_d |
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 |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
8 import animal |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
9 import random |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
10 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
11 class Engine(Game): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
12 def __init__(self, main_menu_app): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
13 self.main_menu_app = main_menu_app |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
14 self.clock = pygame.time.Clock() |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
15 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
16 def tick(self): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
17 """Tic toc.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
18 pygame.time.wait(10) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
19 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
20 def create_game_board(self): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
21 self.gameboard = gameboard.GameBoard() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
22 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
23 class MainMenuState(State): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
24 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
25 if events_equal(e, START_DAY): |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
26 self.game.create_game_board() |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
27 return DayState(self.game) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
28 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
29 return Quit(self.game) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
30 elif e.type is not QUIT: |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
31 self.game.main_menu_app.event(e) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
32 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
33 def paint(self, screen): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
34 screen.fill((0,0,0)) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
35 self.game.main_menu_app.paint(screen) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
36 pygame.display.flip() |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
37 |
15
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
38 def update(self, screen): |
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
39 update = self.game.main_menu_app.update(screen) |
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
40 pygame.display.update(update) |
b69d954f2f1d
Add update call to main menu event
Neil Muller <drnlmuller@gmail.com>
parents:
14
diff
changeset
|
41 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
42 class DayState(State): |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
43 def init(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
44 """Add some chickens to the farm""" |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
45 # Very simple, we walk around the tilemap, and, for each farm tile, |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
46 # we randomly add a chicken (1 in 10 chance) until we have 5 chickens |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
47 # or we run out of board |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
48 self.game.gameboard.clear_foxes() |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
49 chickens = len(self.game.gameboard.chickens) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
50 x, y = 0, 0 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
51 width, height = self.game.gameboard.tv.size |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
52 while chickens < 5: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
53 if x < width: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
54 tile = self.game.gameboard.tv.get((x, y)) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
55 else: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
56 y += 1 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
57 if y >= height: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
58 break |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
59 x = 0 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
60 continue |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
61 # See if we place a chicken |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
62 if tile == 1: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
63 # Farmland |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
64 roll = random.randint(1, 10) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
65 # We don't place within a tile of the fence, this is to make things |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
66 # easier |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
67 for xx in range(x-1, x+2): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
68 if xx >= height or xx < 0: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
69 continue |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
70 for yy in range(y-1, y+2): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
71 if yy >= height or yy < 0: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
72 continue |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
73 neighbour = self.game.gameboard.tv.get((xx, yy)) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
74 if neighbour == 2: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
75 # Fence |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
76 roll = 10 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
77 if roll == 1: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
78 # Create a chicken |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
79 chickens += 1 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
80 chick = animal.Chicken((x, y)) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
81 self.game.gameboard.add_chicken(chick) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
82 x += 1 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
83 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
84 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
85 if events_equal(e, START_NIGHT): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
86 return NightState(self.game) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
87 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
88 return MainMenuState(self.game) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
89 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
|
90 return pygame.event.post(START_NIGHT) |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
91 elif events_equal(e, GO_MAIN_MENU): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
92 return MainMenuState(self.game) |
14 | 93 elif e.type is not QUIT: |
94 self.game.gameboard.event(e) | |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
95 |
12
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
96 def paint(self, screen): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
97 self.game.gameboard.paint(screen) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
98 pygame.display.flip() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
99 |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
100 def update(self, screen): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
101 update = self.game.gameboard.update(screen) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
102 pygame.display.update(update) |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
103 |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
104 def loop(self): |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
105 self.game.gameboard.loop() |
8a7319e4853a
Hooked in the game board.
Jeremy Thurgood <firxen@gmail.com>
parents:
11
diff
changeset
|
106 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
107 class NightState(State): |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
108 def init(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
109 """Add some foxes to the farm""" |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
110 # Very simple, we walk around the tilemap, and, for each farm tile, |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
111 # we randomly add a chicken (1 in 10 chance) until we have 5 chickens |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
112 # or we run out of board |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
113 foxes = len(self.game.gameboard.foxes) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
114 x, y = 0, 0 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
115 width, height = self.game.gameboard.tv.size |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
116 while foxes < 5: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
117 if x < width: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
118 tile = self.game.gameboard.tv.get((x, y)) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
119 else: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
120 y += 1 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
121 if y >= height: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
122 break |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
123 x = 0 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
124 continue |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
125 # See if we place a fox |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
126 if tile == 0: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
127 # Forest |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
128 roll = random.randint(1, 10) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
129 if roll == 1: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
130 # Create a fox |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
131 foxes += 1 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
132 fox = animal.Fox((x, y)) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
133 self.game.gameboard.add_fox(fox) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
134 x += 5 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
135 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
136 def event(self, e): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
137 if events_equal(e, START_DAY): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
138 return DayState(self.game) |
25
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
139 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
|
140 return pygame.event.post(START_DAY) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
141 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
|
142 return MainMenuState(self.game) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
143 elif e.type is not QUIT: |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
144 self.game.gameboard.event(e) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
145 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
146 def loop(self): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
147 self.game.gameboard.loop() |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
148 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
149 def paint(self, screen): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
150 self.game.gameboard.paint(screen) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
151 pygame.display.flip() |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
152 |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
153 def update(self, screen): |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
154 update = self.game.gameboard.update(screen) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
155 pygame.display.update(update) |
6d6ab0c1479d
Add placing some chickens and foxes
Neil Muller <drnlmuller@gmail.com>
parents:
15
diff
changeset
|
156 |
11
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
157 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
158 # pygame events |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
159 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
160 def events_equal(e1, e2): |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
161 """Compare two user events.""" |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
162 return (e1.type is e2.type and e1.name == e2.name) |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
163 |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
164 START_DAY = pygame.event.Event(USEREVENT, name="START_DAY") |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
165 START_NIGHT = pygame.event.Event(USEREVENT, name="START_NIGHT") |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
166 GO_MAIN_MENU = pygame.event.Event(USEREVENT, name="GO_MAIN_MENU") |
5d58a5b13731
Extremely rudimentary game engine.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
167 QUIT = pygame.event.Event(QUIT) |