Skip to content

Commit

Permalink
Added some cheesey transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Jan 25, 2024
1 parent 2367a5c commit 2b251d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
33 changes: 26 additions & 7 deletions wideboy/sprites/slideshow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum
from pygame import Rect, Surface
from pygame.sprite import Sprite
from pygame.transform import scale as pygame_transform_scale
from typing import Any, Dict, Optional

logger = logging.getLogger(__name__)
Expand All @@ -11,8 +12,8 @@ class Transition(Enum):
NONE = 0
FADE = 1
WIPE = 2
BLEED = 3
COLUMNS = 4
FOLD = 3
BLEED = 4


class SlideshowSprite(Sprite):
Expand Down Expand Up @@ -49,10 +50,10 @@ def update(self) -> None:
self._transition_fade()
elif self.transition == Transition.WIPE:
self._transition_wipe()
elif self.transition == Transition.FOLD:
self._transition_fold()
elif self.transition == Transition.BLEED:
self._transition_bleed()
elif self.transition == Transition.COLUMNS:
self._transition_columns()

def reset_transition(self) -> None:
self.transition = None
Expand Down Expand Up @@ -99,7 +100,7 @@ def _transition_wipe(self, speed: int = 4) -> None:
self.image_buffer = None
self.reset_transition()

def _transition_bleed(self, speed: int = 1) -> None:
def _transition_fold(self, speed: int = 1) -> None:
if self.image_buffer is None:
return
self.transition_state["y"] = self.transition_state.get("y", 0)
Expand Down Expand Up @@ -127,18 +128,36 @@ def _transition_bleed(self, speed: int = 1) -> None:
self.image_buffer = None
self.reset_transition()

def _transition_columns(self, speed: int = 4) -> None:
def _transition_bleed(self, speed: int = 4) -> None:
if self.image_buffer is None:
return
self.transition_state["x"] = self.transition_state.get("x", 1)
self.transition_state["x"] = self.transition_state.get("x", 0)
# Wipe out old image
if self.transition_state["x"] < self.rect.width:
self.transition_state["x"] += speed
fill = Surface((1, self.rect.height))
fill.blit(
self.image_buffer,
(0, 0),
(self.transition_state["x"], 0, 1, self.rect.height),
)
fill = pygame_transform_scale(
fill, (self.rect.width - self.transition_state["x"], self.rect.height)
)
self.image.blit(
self.image_buffer,
(0, 0),
(0, 0, self.transition_state["x"], self.rect.height),
)
self.image.blit(
fill,
(
self.transition_state["x"],
0,
self.rect.width - self.transition_state["x"],
self.rect.height,
),
)
# When wipe is complete, swap images and reset state
else:
self.image = self.image_buffer
Expand Down
6 changes: 1 addition & 5 deletions wideboy/systems/scene/stages/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ def advance(self) -> None:
self.app_state.slideshow_index = 0
next_image = load_image(self.slideshow_images[self.app_state.slideshow_index])
widget_slideshow.sprite.set_next_image(next_image)
widget_slideshow.sprite.swap(
random.choice(
[Transition.FADE, Transition.WIPE, Transition.BLEED, Transition.COLUMNS]
)
)
widget_slideshow.sprite.swap(random.choice([Transition.BLEED]))

def _glob_backgrounds(self, randomize: bool = False) -> None:
app_state = next(self.entities.get_by_class(AppState))
Expand Down

0 comments on commit 2b251d6

Please sign in to comment.