from ..constants import SCREEN_SIZE
from ..widgets import ImageButton
+from ..turnip import Turnip
class DayScene(BaseScene):
self._space = pymunk.Space()
self._obstacles = ObstacleManager(self._space, gamestate)
self._lights = LightManager(self._space, gamestate)
+ self._turnips = []
+ self._seeds = gamestate.seeds
+ self._harvested = gamestate.harvested
+ self._tool = None
+ for turnip_data in gamestate.turnips:
+ turnip = Turnip(**turnip_data)
+ # Turnips grow at dawn
+ seeds = turnip.grow()
+ if seeds:
+ self._seeds += seeds
+ self._harvested += 1
+ else:
+ self._turnips.append(turnip)
+ print 'Seeds', self._seeds
# Toolbar
self._tools = [
ImageButton('32', 'seed.png', name='seed',
def exit(self, gamestate):
self._unset_cursor()
+ gamestate.seeds = self._seeds
+ gamestate.harvested = self._harvested
+ turnip_data = [turnip.serialize() for turnip in self._turnips]
+ gamestate.turnips = turnip_data
@debug_timer("day.render")
def render(self, surface, gamestate):
self._lights.render_light(surface)
self._obstacles.render(surface)
self._lights.render_fittings(surface)
+ for turnip in self._turnips:
+ turnip.render(surface)
for tool in self._tools:
tool.render(surface)
self._draw_cursor(surface)
# Check tools
for tool in self._tools:
if tool.pressed(ev):
- print 'tool', tool.name
if tool.name == 'reset tool':
self._unset_cursor()
+ self._tool = None
else:
+ self._tool = tool.name
self._set_cursor(tool.name)
return
- # Not tool, so check lights
- self._lights.toggle_nearest(ev.pos, surfpos=True)
- print self._lights.lit_by(ev.pos, surfpos=True)
+ if self._tool == "seed":
+ if self._seeds > 0:
+ # plant seed
+ turnip = Turnip(age=0, pos=ev.pos)
+ self._turnips.append(turnip)
+ self._seeds -= 1
+ self._update_toolbar
+ else:
+ # Not tool, so check lights
+ self._lights.toggle_nearest(ev.pos, surfpos=True)
+ print self._lights.lit_by(ev.pos, surfpos=True)
@debug_timer("day.tick")
def tick(self, gamestate):
self._lights.tick()
+
+ def _update_toolbar(self):
+ pass