Mercurial > rinkhals
comparison gamelib/engine.py @ 99:f5d56688943b
Added background music support, and daytime and night time music (really animal sounds, not music)
author | David Fraser <davidf@sjsoft.com> |
---|---|
date | Wed, 02 Sep 2009 12:50:28 +0000 |
parents | 725b292ca07b |
children | d539ef5a3333 |
comparison
equal
deleted
inserted
replaced
98:725b292ca07b | 99:f5d56688943b |
---|---|
43 pygame.display.update(update) | 43 pygame.display.update(update) |
44 | 44 |
45 class DayState(State): | 45 class DayState(State): |
46 def init(self): | 46 def init(self): |
47 """Add some chickens to the farm""" | 47 """Add some chickens to the farm""" |
48 sound.stop_background_music() | |
48 self.game.gameboard.tv.sun(True) | 49 self.game.gameboard.tv.sun(True) |
49 | 50 |
50 sound.play_sound("daybreak.ogg") | 51 sound.play_sound("daybreak.ogg") |
51 # disable timer | 52 # disable timer |
52 pygame.time.set_timer(MOVE_FOX_ID, 0) | 53 pygame.time.set_timer(MOVE_FOX_ID, 0) |
53 self.game.gameboard.clear_foxes() | 54 self.game.gameboard.clear_foxes() |
54 self.game.gameboard.update_chickens() | 55 self.game.gameboard.update_chickens() |
56 sound.background_music("daytime.ogg") | |
55 | 57 |
56 def event(self, e): | 58 def event(self, e): |
57 if events_equal(e, START_NIGHT): | 59 if events_equal(e, START_NIGHT): |
58 return NightState(self.game) | 60 return NightState(self.game) |
59 elif e.type is KEYDOWN and e.key == K_ESCAPE: | 61 elif e.type is KEYDOWN and e.key == K_ESCAPE: |
77 self.game.gameboard.loop() | 79 self.game.gameboard.loop() |
78 | 80 |
79 class NightState(State): | 81 class NightState(State): |
80 def init(self): | 82 def init(self): |
81 """Add some foxes to the farm""" | 83 """Add some foxes to the farm""" |
84 sound.stop_background_music() | |
82 self.game.gameboard.tv.sun(False) | 85 self.game.gameboard.tv.sun(False) |
83 | 86 |
84 sound.play_sound("nightfall.ogg") | 87 sound.play_sound("nightfall.ogg") |
85 # Add a timer to the event queue | 88 # Add a timer to the event queue |
86 self.cycle_count = 0 | 89 self.cycle_count = 0 |
87 pygame.time.set_timer(MOVE_FOX_ID, 200) | 90 pygame.time.set_timer(MOVE_FOX_ID, 200) |
88 self.game.gameboard.spawn_foxes() | 91 self.game.gameboard.spawn_foxes() |
92 sound.background_music("nighttime.ogg") | |
89 | 93 |
90 def event(self, e): | 94 def event(self, e): |
91 if events_equal(e, START_DAY): | 95 if events_equal(e, START_DAY): |
92 return DayState(self.game) | 96 return DayState(self.game) |
93 elif e.type is KEYDOWN and e.key == K_d: | 97 elif e.type is KEYDOWN and e.key == K_d: |