changeset 223:527a5d4e3fa3

Disable tools at night.
author Simon Cross <hodgestar@gmail.com>
date Fri, 04 Sep 2009 22:39:19 +0000
parents 322e6d3a46e4
children c279ad59b8e2
files gamelib/engine.py gamelib/gameboard.py
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/engine.py	Fri Sep 04 22:38:48 2009 +0000
+++ b/gamelib/engine.py	Fri Sep 04 22:39:19 2009 +0000
@@ -105,7 +105,7 @@
     def init(self):
         """Add some chickens to the farm"""
         sound.stop_background_music()
-        self.game.gameboard.tv.sun(True)
+        self.game.gameboard.start_day()
 
         sound.play_sound("daybreak.ogg")
         # disable timer
@@ -147,8 +147,7 @@
     def init(self):
         """Add some foxes to the farm"""
         sound.stop_background_music()
-        self.game.gameboard.tv.sun(False)
-        self.game.gameboard.reset_states()
+        self.game.gameboard.start_night()
 
         sound.play_sound("nightfall.ogg")
         # Add a timer to the event queue
--- a/gamelib/gameboard.py	Fri Sep 04 22:38:48 2009 +0000
+++ b/gamelib/gameboard.py	Fri Sep 04 22:39:19 2009 +0000
@@ -223,6 +223,7 @@
         self.days = 0
         self.killed_foxes = 0
         self.add_cash(constants.STARTING_CASH)
+        self.day, self.night = True, False
 
         self.fix_buildings()
 
@@ -248,6 +249,8 @@
         self.tv.loop()
 
     def set_selected_tool(self, tool, cursor):
+        if not self.day:
+            return
         self.selected_tool = tool
         if self.animal_to_place:
             # Clear any highlights
@@ -276,6 +279,16 @@
         tile_pos = self.tv.screen_to_tile(e.pos)
         self.sprite_cursor.set_pos(tile_pos)
 
+    def start_night(self):
+        self.day, self.night = False, True
+        self.tv.sun(False)
+        self.reset_states()
+
+    def start_day(self):
+        self.day, self.night = True, False
+        self.tv.sun(True)
+        self.reset_states()
+
     def in_bounds(self, pos):
         """Check if a position is within the game boundaries"""
         if pos.x < 0 or pos.y < 0:
@@ -286,6 +299,8 @@
         return True
 
     def use_tool(self, e):
+        if not self.day:
+            return
         if e.button == 3: # Right button
             self.selected_tool = None
             self.set_cursor()