From 4db6751987e27976328db096f934cec83d4dd4c0 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Fri, 9 Sep 2016 21:12:08 +0200 Subject: [PATCH] Don't repeatedly reload soil. --- tabakrolletjie/scenes/day.py | 18 ++++++++++-------- tabakrolletjie/scenes/night.py | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index c280702..9e55fba 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -1,7 +1,6 @@ """ Be prepared. """ import pygame.locals as pgl -import pygame.surface import pymunk import pymunk.pygame_util @@ -12,6 +11,7 @@ from ..obstacles import ObstacleManager from ..events import SceneChangeEvent from ..utils import debug_timer from ..loader import loader +from ..transforms import Overlay from ..constants import SCREEN_SIZE, FONTS from ..widgets import ImageButton @@ -19,6 +19,9 @@ from ..turnip import Turnip, TurnipInvalidPosition class DayScene(BaseScene): + + BRIGHTNESS = Overlay(colour=(255, 255, 255, 50)) + def enter(self, gamestate): self._space = pymunk.Space() self._toolbar_font = loader.load_font(FONTS['sans'], size=20) @@ -46,6 +49,9 @@ class DayScene(BaseScene): pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40)), ] self._update_toolbar(gamestate) + # Background + self._soil = loader.load_image( + "textures", "soil.png", transform=self.BRIGHTNESS) def exit(self, gamestate): self._unset_cursor() @@ -56,12 +62,8 @@ class DayScene(BaseScene): @debug_timer("day.render") def render(self, surface, gamestate): - surface.blit(loader.load_image("textures", "soil.png"), (0, 0)) - brightness = pygame.surface.Surface(surface.get_size()) - brightness = brightness.convert_alpha() - brightness.fill((255, 255, 255, 50)) - surface.blit(brightness, (0, 0)) - + surface.blit(self._soil, (0, 0)) + for turnip in self._turnips: turnip.render(surface) self._lights.render_light(surface) @@ -122,7 +124,7 @@ class DayScene(BaseScene): def _update_toolbar(self, gamestate): text = ("Turnip Stocks: Seeds: %d. Planted: %d. " - "Harvested: %d. Destroyed: %d" % + "Harvested: %d. Destroyed: %d" % (self._seeds, len(self._turnips), self._harvested, gamestate.eaten)) self._toolbar = self._toolbar_font.render(text, True, (255, 255, 255)) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index fe1fae3..d8f0e1a 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -1,7 +1,6 @@ """ In the night, the mould attacks. """ import pygame.locals as pgl -import pygame.surface import pymunk @@ -12,10 +11,14 @@ from ..enemies import Boyd from ..events import SceneChangeEvent from ..utils import debug_timer from ..loader import loader +from ..transforms import Overlay from ..turnip import Turnip class NightScene(BaseScene): + + DARKNESS = Overlay(colour=(0, 0, 0, 150)) + def enter(self, gamestate): self._space = pymunk.Space() self._obstacles = ObstacleManager(self._space, gamestate) @@ -25,15 +28,13 @@ class NightScene(BaseScene): for turnip_data in gamestate.turnips: turnip = Turnip(space=self._space, **turnip_data) self._turnips.append(turnip) + self._soil = loader.load_image( + "textures", "soil.png", transform=self.DARKNESS) @debug_timer("night.render") def render(self, surface, gamestate): - surface.blit(loader.load_image("textures", "soil.png"), (0, 0)) - darkness = pygame.surface.Surface(surface.get_size()) - darkness = darkness.convert_alpha() - darkness.fill((0, 0, 0, 150)) - surface.blit(darkness, (0, 0)) - + surface.blit(self._soil, (0, 0)) + self._mould.render(surface) for turnip in self._turnips[:]: @@ -43,6 +44,7 @@ class NightScene(BaseScene): gamestate.eaten += 1 else: turnip.render(surface) + self._lights.render_light(surface) self._obstacles.render(surface) self._lights.render_fittings(surface) -- 2.34.1