def __init__(self):
self._state = {
"station": None,
+ "turnips": [],
}
+ self.harvested = 0
@property
def station(self):
return self._state["station"]
+ @property
+ def turnips(self):
+ return self._state["turnips"]
+
+ @turnips.setter
+ def turnips(self, turnip_list):
+ self._state["turnips"] = turnip_list
+
+ @property
+ def seeds(self):
+ if 'seeds' in self._state:
+ return self._state['seeds']
+ elif self._state["station"] and 'seeds' in self._state["station"]["config"]:
+ self._state['seeds'] = self._state["station"]["config"]["seeds"]
+ return self._state['seeds']
+ return 0
+
+ @seeds.setter
+ def seeds(self, value):
+ self._state['seeds'] = value
+
def load_station(self, station):
self._state["station"] = loader.load_station(station)
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
from ..enemies import Boyd
from ..events import SceneChangeEvent
from ..utils import debug_timer
+from ..turnip import Turnip
class NightScene(BaseScene):
self._obstacles = ObstacleManager(self._space, gamestate)
self._lights = LightManager(self._space, gamestate)
self._mould = Boyd(gamestate, self._space)
+ self._turnips = []
+ for turnip_data in gamestate.turnips:
+ turnip = Turnip(**turnip_data)
+ self._turnips.append(turnip)
+
@debug_timer("night.render")
def render(self, surface, gamestate):
surface.fill((0, 0, 155))
self._mould.render(surface)
+ for turnip in self._turnips:
+ turnip.render(surface)
self._lights.render_light(surface)
self._obstacles.render(surface)
self._lights.render_fittings(surface)
def tick(self, gamestate):
self._mould.tick(gamestate, self._space, self._lights)
self._lights.tick()
+
+ def exit(self, gamestate):
+ turnip_data = [turnip.serialize() for turnip in self._turnips]
+ gamestate.turnips = turnip_data
--- /dev/null
+# Brassica rapa extraterrestrialus, the common space turnip
+
+from .loader import loader
+import random
+
+class Turnip(object):
+
+ def __init__(self, **kwargs):
+ self._age = kwargs.get('age', 0)
+ self._pos = kwargs.get('pos', (0, 0))
+ self._update_image()
+
+ def _update_image(self):
+ self._image = loader.load_image('32', 'turnip%d.png' % (self._age + 1))
+
+ def render(self, surface):
+ surface.blit(self._image, self._pos, None)
+
+ def serialize(self):
+ return {'age': self._age, 'pos': self._pos}
+
+ def grow(self):
+ self._age += 1
+ if self._age >= 3:
+ # Mature, so harvest it for seeds
+ return random.randint(1, 3)
+ else:
+ self._update_image()
+ return None