TODO
====
-* Lose condition (no turnips and no seeds)
* Win condition
* Battery and light power consts
* Mould resistances
* Save game
* More sounds
* Five levels
-* Sunrise transition screen
* 'End the Day' button
* Seralize light on / off and colour selection state across day / night transition
-* 'Dawn breaks' transition screen
Done
====
* All lights multicolour
* Light direction configuration
* Fitting rotation
+* Sunrise transition screen
+* Lose condition (no turnips and no seeds)
MOULD=eyeballA eyeballB eyeballC
LIGHT=spotlight lamp laser
LIGHT_MASK=light_mask_2_1 light_mask_2_2 light_mask_3_1 light_mask_3_2 light_mask_3_3
+CONTROLS=night default_cursor exit pause play
IMG16=$(MOULD_BODY)
-IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) $(SEED) $(LIGHT_MASK)
+IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) $(SEED) $(LIGHT_MASK) $(CONTROLS)
IMG48=$(LIGHT) $(TURNIP) $(LIGHT_MASK)
IMG64=$(MOULD_BODY)
Shrub texture:
https://commons.wikimedia.org/wiki/File:Gew%C3%B6hnlicher_Buchsbaum,_Buxus_sempervirens_.JPG
-
-Pointer image: data/images/32/default_cursor.png
-Based on mouse_pointer_wolfram_es_01.png
-(image cropped and shrunk to 32x32)
-From OpenClipArt: http://www.openclipart.org
-LICENSE: Public Domain
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="100mm"
+ height="100mm"
+ viewBox="0 0 354.33071 354.33071"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="default_cursor.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1.4"
+ inkscape:cx="103.58267"
+ inkscape:cy="168.74492"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:window-width="1264"
+ inkscape:window-height="720"
+ inkscape:window-x="102"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:object-nodes="true"
+ inkscape:snap-smooth-nodes="true">
+ <inkscape:grid
+ type="xygrid"
+ id="grid4423"
+ units="mm"
+ spacingx="3.543307"
+ spacingy="3.543307" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-698.0315)">
+ <path
+ style="opacity:1;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 44.833481,742.86495 263.077129,112.74735 -87.69238,37.58245 75.16492,75.16491 -25.05497,25.05496 -75.16491,-75.16491 -37.58245,87.69239 z"
+ id="path4233"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cccccccc" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="100mm"
+ height="100mm"
+ viewBox="0 0 354.33071 354.33071"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="exit.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1.4"
+ inkscape:cx="115.01124"
+ inkscape:cy="168.74492"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:window-width="1264"
+ inkscape:window-height="720"
+ inkscape:window-x="102"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:object-nodes="true"
+ inkscape:snap-smooth-nodes="true">
+ <inkscape:grid
+ type="xygrid"
+ id="grid4423"
+ units="mm"
+ spacingx="3.543307"
+ spacingy="3.543307" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-698.0315)">
+ <rect
+ style="opacity:1;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect4149"
+ width="194.8819"
+ height="283.46457"
+ x="124.01575"
+ y="733.4646" />
+ <path
+ style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 124.01575,733.46457 159.44882,35.43307 0,212.59843 -159.44882,35.43303 z"
+ id="rect4151"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="ccccc" />
+ <path
+ style="fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
+ d="m 35.433071,839.76378 53.149606,0 0,-35.43307 106.299213,70.86614 -106.299213,70.86615 0,-35.43307 -53.149606,0 z"
+ id="path4154"
+ inkscape:connector-curvature="0" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="100mm"
+ height="100mm"
+ viewBox="0 0 354.33071 354.33071"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="night.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1.4"
+ inkscape:cx="115.01124"
+ inkscape:cy="168.74492"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:window-width="1264"
+ inkscape:window-height="720"
+ inkscape:window-x="102"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:object-nodes="true"
+ inkscape:snap-smooth-nodes="true">
+ <inkscape:grid
+ type="xygrid"
+ id="grid4423"
+ units="mm"
+ spacingx="3.543307"
+ spacingy="3.543307" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-698.0315)">
+ <path
+ style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 177.16602 17.716797 A 159.44882 159.44882 0 0 0 42.353516 92.375 A 106.29922 106.29922 0 0 1 106.29883 70.865234 A 106.29922 106.29922 0 0 1 212.59766 177.16602 A 106.29922 106.29922 0 0 1 106.29883 283.46484 A 106.29922 106.29922 0 0 1 42.0625 261.69336 A 159.44882 159.44882 0 0 0 177.16602 336.61328 A 159.44882 159.44882 0 0 0 336.61328 177.16602 A 159.44882 159.44882 0 0 0 177.16602 17.716797 z "
+ transform="translate(0,698.0315)"
+ id="path4177" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:end;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="102.29472"
+ y="861.47351"
+ id="text4184"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan4186"
+ x="102.29472"
+ y="861.47351"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:80px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold'">Z</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:end;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="129.29697"
+ y="954.19006"
+ id="text4184-3"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan4186-6"
+ x="129.29697"
+ y="954.19006"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:80px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold'">Z</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:end;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ x="190.72552"
+ y="882.76147"
+ id="text4184-7"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan4186-5"
+ x="190.72552"
+ y="882.76147"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:80px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold'">Z</tspan></text>
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="100mm"
+ height="100mm"
+ viewBox="0 0 354.33071 354.33071"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="pause.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1.4"
+ inkscape:cx="115.01124"
+ inkscape:cy="168.74492"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:window-width="1264"
+ inkscape:window-height="720"
+ inkscape:window-x="102"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:object-nodes="true"
+ inkscape:snap-smooth-nodes="true">
+ <inkscape:grid
+ type="xygrid"
+ id="grid4423"
+ units="mm"
+ spacingx="3.543307"
+ spacingy="3.543307" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-698.0315)">
+ <circle
+ style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path4188"
+ cx="177.16536"
+ cy="875.19684"
+ r="141.73228" />
+ <rect
+ style="opacity:1;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect4190"
+ width="35.433071"
+ height="106.29922"
+ x="124.01575"
+ y="822.04724" />
+ <rect
+ style="opacity:1;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect4190-3"
+ width="35.433079"
+ height="106.29922"
+ x="194.88188"
+ y="822.04724" />
+ </g>
+</svg>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="100mm"
+ height="100mm"
+ viewBox="0 0 354.33071 354.33071"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="play.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1.4"
+ inkscape:cx="115.01124"
+ inkscape:cy="168.74492"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:window-width="1264"
+ inkscape:window-height="720"
+ inkscape:window-x="102"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:object-nodes="true"
+ inkscape:snap-smooth-nodes="true">
+ <inkscape:grid
+ type="xygrid"
+ id="grid4423"
+ units="mm"
+ spacingx="3.543307"
+ spacingy="3.543307" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-698.0315)">
+ <circle
+ style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path4188"
+ cx="177.16536"
+ cy="875.19684"
+ r="141.73228" />
+ <path
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 124.0159,822.04725 0,106.29921 106.29922,-53.14961 z"
+ id="path4228"
+ inkscape:connector-curvature="0" />
+ </g>
+</svg>
import math
import pygame.display
+import pygame.surface
import pygame.locals as pgl
import pymunk
from ..lights import LightManager, light_fitting_by_type
from ..obstacles import ObstacleManager
from ..events import SceneChangeEvent
-from ..utils import debug_timer
+from ..utils import debug_timer, shadowed_text
from ..loader import loader
from ..transforms import Overlay, Alpha, ColourWedges
# Background
self._soil = loader.load_image(
"textures", "soil.png", transform=self.BRIGHTNESS)
+ # Check if we've lost
+ self._game_over_text = []
+ if self._seeds == 0 and len(self._turnips) == 0:
+ self._draw_game_over_text()
+
+ def _draw_game_over_text(self):
+ overlay = pygame.surface.Surface(
+ (SCREEN_SIZE[0], 240), pgl.SWSURFACE).convert_alpha()
+ overlay.fill((0, 0, 0, 128))
+ self._game_over_text.append((overlay, (0, 250)))
+ self._game_over_text.append(
+ (shadowed_text("You Lost", FONTS["bold"], 48), (400, 280)))
+ self._game_over_text.append(
+ (shadowed_text("You have no seeds and no turnips growing",
+ FONTS["sans"], 24), (250, 350)))
+ self._game_over_text.append(
+ (shadowed_text("Press a key to return to the menu",
+ FONTS["sans"], 24), (250, 400)))
def grow_turnips(self, gamestate):
for turnip_data in gamestate.turnips:
def create_tools(self, gamestate):
tools = []
- x, y, step = 50, SCREEN_SIZE[1] - 40, 50
+ x, y, step = 0, SCREEN_SIZE[1] - 40, 50
+
+ tools.append(ImageButton(
+ '32', 'default_cursor.png', name='reset tool', pos=(x, y)))
+ x += step
tools.append(ImageButton('32', 'seed.png', name='seed', pos=(x, y)))
x += step
x += step
tools.append(ImageButton(
- '32', 'default_cursor.png', name='reset tool', pos=(x, y)))
+ '32', 'night.png', name='start night', pos=(SCREEN_SIZE[0] - 100, y)))
+ tools.append(ImageButton(
+ '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y)))
return tools
def exit(self, gamestate):
for light_tool in self._light_toolbar:
light_tool.render(surface)
self._draw_cursor(surface)
+ if self._game_over_text:
+ for surf, pos in self._game_over_text:
+ surface.blit(surf, pos)
def _draw_light_toolbar(self, light_config, x):
height = SCREEN_SIZE[1] - 80
self._lights.add_light(cfg)
def event(self, ev, gamestate):
+ if self._game_over_text:
+ if ev.type in (pgl.KEYDOWN, pgl.MOUSEBUTTONDOWN):
+ from .menu import MenuScene
+ SceneChangeEvent.post(scene=MenuScene())
if ev.type == pgl.KEYDOWN:
if ev.key in (pgl.K_q, pgl.K_ESCAPE):
from .menu import MenuScene
self._unset_cursor()
self._tool = None
self._clear_light_toolbar()
+ elif tool.name == 'start night':
+ from .night import NightScene
+ SceneChangeEvent.post(scene=NightScene())
+ elif tool.name == 'exit':
+ from .menu import MenuScene
+ SceneChangeEvent.post(scene=MenuScene())
else:
self._tool = tool
if self._tool.name == 'seed':
""" In the night, the mould attacks. """
+import pygame.surface
import pygame.locals as pgl
import pymunk
from ..obstacles import ObstacleManager
from ..enemies import Boyd
from ..events import SceneChangeEvent
-from ..utils import debug_timer
+from ..utils import debug_timer, shadowed_text
from ..loader import loader
from ..transforms import Overlay
from ..turnip import Turnip
-from ..constants import NIGHT_LENGTH, DEBUG
+from ..constants import NIGHT_LENGTH, DEBUG, FONTS, SCREEN_SIZE
class NightScene(BaseScene):
self._soil = loader.load_image(
"textures", "soil.png", transform=self.DARKNESS)
self._total_ticks = 0
+ self._do_ticks = True
+ self._eaten_tonight = 0
+ self._night_over_text = []
@debug_timer("night.render")
def render(self, surface, gamestate):
self._turnips.remove(turnip)
turnip.remove()
gamestate.eaten += 1
+ self._eaten_tonight += 1
else:
turnip.render(surface)
self._obstacles.render(surface)
self._lights.render_fittings(surface)
+ for text, text_pos in self._night_over_text:
+ surface.blit(text, text_pos, None)
+
def event(self, ev, gamestate):
if ev.type == pgl.KEYDOWN:
+ if not self._do_ticks:
+ # Any keypress exits
+ self._to_day()
if ev.key in (pgl.K_q, pgl.K_ESCAPE):
from .menu import MenuScene
SceneChangeEvent.post(scene=MenuScene())
if ev.key == pgl.K_e and DEBUG:
- self._to_day()
+ self._end_night()
elif ev.type == pgl.MOUSEBUTTONDOWN:
+ if not self._do_ticks:
+ # Any mouse press exits
+ self._to_day()
if ev.button == 1:
self._lights.toggle_nearest(ev.pos, surfpos=True)
print self._lights.lit_by(ev.pos, surfpos=True)
from .day import DayScene
SceneChangeEvent.post(scene=DayScene())
+ def _end_night(self):
+ self._do_ticks = False
+ self._night_over_text = []
+ overlay = pygame.surface.Surface(
+ (SCREEN_SIZE[0], 240), pgl.SWSURFACE).convert_alpha()
+ overlay.fill((0, 0, 0, 172))
+ self._night_over_text.append((overlay, (0, 40)))
+ self._night_over_text.append(
+ (shadowed_text("The Night is Over", FONTS["bold"], 48), (300, 50)))
+ self._night_over_text.append(
+ (shadowed_text("Turnips eaten tonight: %d" % self._eaten_tonight,
+ FONTS["sans"], 32), (300, 130)))
+ self._night_over_text.append(
+ (shadowed_text("Surviving turnips: %d" % len(self._turnips),
+ FONTS["sans"], 32), (300, 170)))
+ self._night_over_text.append(
+ (shadowed_text("Press any key to continue", FONTS["sans"], 24),
+ (350, 240)))
+
@debug_timer("night.tick")
def tick(self, gamestate):
- if self._total_ticks < NIGHT_LENGTH:
- self._mould.tick(gamestate, self._space, self._lights)
- self._lights.tick()
- print "Power usage: ", self._lights.total_power_usage()
- else:
- self._to_day()
- if not self._mould.alive():
- self._to_day()
+ if self._do_ticks:
+ if self._total_ticks < NIGHT_LENGTH:
+ self._mould.tick(gamestate, self._space, self._lights)
+ self._lights.tick()
+ print "Power usage: ", self._lights.total_power_usage()
+ else:
+ self._end_night()
+ if not self._mould.alive():
+ self._end_night()
def exit(self, gamestate):
turnip_data = [turnip.serialize() for turnip in self._turnips]
import functools
import time
+import pygame.surface
+import pygame.locals as pgl
from .constants import DEBUG
+from .loader import loader
def debug_timer(label, debug=False):
def end(self):
print " %s: %s" % ("total", time.time() - self.times[0])
print "---- ----"
+
+
+def shadowed_text(text, font_name, size, offset=4):
+ font_black = loader.load_font(font_name, size=size)
+ font_white = loader.load_font(font_name, size=size)
+ background = font_black.render(text, True, (0, 0, 0))
+ foreground = font_white.render(text, True, (255, 255, 255))
+ new_size = (background.get_width() + offset,
+ background.get_height() + offset)
+ base = pygame.surface.Surface(new_size, pgl.SWSURFACE).convert_alpha()
+ base.fill((0, 0, 0, 0))
+ base.blit(background, (offset, offset), None)
+ base.blit(foreground, (0, 0), None)
+ return base
super(ImageButton, self).__init__(self._img.get_size(), name,
pos, padding)
+ def update_image(self, *imgparts, **kwargs):
+ transform=kwargs.pop("transform", NullTransform())
+ self._img = loader.load_image(*imgparts, transform=transform)
+
def render(self, surface):
surface.blit(self._img, self._pos, None)