This commit is contained in:
ohsqueezy 2023-02-04 23:59:17 -05:00
parent 09564da198
commit c22d9f0b3e
3 changed files with 57 additions and 18 deletions

View File

@ -8,17 +8,18 @@ from games.ibitfit.electric_sieve.ElectricSieve import ElectricSieve
class Playzing(pgfw.Game): class Playzing(pgfw.Game):
def __init__(self): def __init__(self, config_overrides=None):
""" """
Create logo sprite, clear screen, and subscribe to events. Create logo sprite, clear screen, and subscribe to events.
""" """
pgfw.Game.__init__(self) pgfw.Game.__init__(self)
# Assign types to configuration values # Assign types to configuration values
self.get_configuration().type_declarations.add_chart({ self.configuration.type_declarations.add_chart({
"display": "display":
{ {
"int-list": "clear" "int-list": "clear",
"bool": "rotated"
}, },
"logo": "logo":
{ {
@ -28,6 +29,9 @@ class Playzing(pgfw.Game):
} }
}) })
# Merge config overrides from the command line
self.configuration.merge_command_line()
# Clear screen to black # Clear screen to black
self.get_display_surface().fill(self.configuration.get("display", "clear")) self.get_display_surface().fill(self.configuration.get("display", "clear"))
@ -37,33 +41,53 @@ class Playzing(pgfw.Game):
# Load sprites for logo parts # Load sprites for logo parts
self.logo_text = pgfw.Sprite(self) self.logo_text = pgfw.Sprite(self)
self.logo_text.load_from_path(self.get_resource(self.configuration.get("logo", "text")), True) self.logo_text.load_from_path(self.get_resource(self.configuration.get("logo", "text")), True)
if self.rotated:
self.logo_text.rotate()
self.logo_fire = pgfw.Sprite(self) self.logo_fire = pgfw.Sprite(self)
self.logo_fire.load_from_path(self.get_resource(self.configuration.get("logo", "fire")), True) self.logo_fire.load_from_path(self.get_resource(self.configuration.get("logo", "fire")), True)
if self.rotated:
self.logo_fire.rotate()
# Register logo animation functions and begin animation # Register logo animation functions and begin animation
self.register(self.animate_logo) self.register(self.animate_logo)
self.register(self.reveal_text, interval=40) self.register(self.reveal_text, interval=40)
self.play(self.animate_logo, play_once=True) self.play(self.animate_logo, play_once=True)
@property
def rotated(self):
return self.configuration.get("display", "rotated")
def orient(self, obj):
oriented = obj
if self.rotated:
if isinstance(obj, pygame.Rect):
oriented = pygame.Rect(obj.y, self.get_display_surface().get_height() - obj.x + obj.w, obj.h, obj.w)
return oriented
def animate_logo(self): def animate_logo(self):
""" """
Reset the logo animation to its beginning and start animating. Reset the logo animation to its beginning and start animating.
""" """
# Place the logo # Place the logo
screen_rect = self.get_display_surface().get_rect()
margin = self.configuration.get("logo", "margin") margin = self.configuration.get("logo", "margin")
self.logo_text.location.center = screen_rect.center self.logo_text.location.center = self.get_display_surface().get_rect().center
self.logo_text.move(-self.logo_fire.location.w + margin / 2) self.logo_text.move(-self.orient(self.logo_fire.location).w + margin / 2, rotated=self.rotated)
# Clear the screen # Clear the screen
self.get_display_surface().fill(self.configuration.get("display", "clear")) self.get_display_surface().fill(self.configuration.get("display", "clear"))
# Place the fire at the left side of the logo text # Place the fire at the left side of the logo text
self.logo_fire.location.midleft = self.logo_text.location.midleft if not self.rotated:
self.logo_fire.location.midleft = self.logo_text.location.midleft
else:
self.logo_fire.location.midbottom = self.logo_text.location.midbottom
# Close the draw clip for the logo completely # Close the draw clip for the logo completely
self.logo_text_clip = self.logo_text.location.copy() self.logo_text_clip = self.logo_text.location.copy()
self.logo_text_clip.width = 0 if not self.rotated:
self.logo_text_clip.width = 0
else:
self.logo_text_clip.height = 0
# Queue the text reveal to start # Queue the text reveal to start
self.play(self.reveal_text, delay=self.configuration.get("logo", "delay")) self.play(self.reveal_text, delay=self.configuration.get("logo", "delay"))
@ -72,11 +96,22 @@ class Playzing(pgfw.Game):
""" """
Move the fire right, opening the logo text clip rect until it's big enough to show all the text. Queue the animation to restart once finished. Move the fire right, opening the logo text clip rect until it's big enough to show all the text. Queue the animation to restart once finished.
""" """
self.logo_fire.move(10) self.logo_fire.move(10, rotated=self.rotated)
self.logo_text_clip.width = self.logo_fire.location.left - self.logo_text.location.left halt = False
limit = self.logo_text.location.right + self.configuration.get("logo", "margin") / 2 if not self.rotated:
if self.logo_fire.location.left > limit: self.logo_text_clip.width = self.logo_fire.location.left - self.logo_text.location.left
self.logo_fire.location.left = limit limit = self.logo_text.location.right + self.configuration.get("logo", "margin") / 2
if self.logo_fire.location.left > limit:
self.logo_fire.location.left = limit
halt = True
else:
self.logo_text_clip.height = self.logo_text.location.bottom - self.logo_fire.location.bottom
self.logo_text_clip.bottom = self.logo_text.location.bottom
limit = self.logo_text.location.top - self.configuration.get("logo", "margin") / 2
if self.logo_fire.location.bottom < limit:
self.logo_fire.location.bottom = limit
halt = True
if halt:
self.halt(self.reveal_text) self.halt(self.reveal_text)
self.play(self.animate_logo, delay=self.configuration.get("logo", "restart"), play_once=True) self.play(self.animate_logo, delay=self.configuration.get("logo", "restart"), play_once=True)
@ -100,7 +135,11 @@ class Playzing(pgfw.Game):
# Erase the center of the screen if enabled # Erase the center of the screen if enabled
if not self.configuration.get("logo", "trail"): if not self.configuration.get("logo", "trail"):
erase_rect = self.logo_text.location.copy() erase_rect = self.logo_text.location.copy()
erase_rect.width = self.logo_fire.location.right - self.logo_text.location.left if not self.rotated:
erase_rect.width = self.logo_fire.location.right - self.logo_text.location.left
else:
erase_rect.height = self.logo_text.location.bottom - self.logo_fire.location.top
erase_rect.bottom = self.logo_text.location.bottom
self.get_display_surface().fill(self.configuration.get("display", "clear"), erase_rect) self.get_display_surface().fill(self.configuration.get("display", "clear"), erase_rect)
# Draw the logo text clipped to the current state of the animation, then remove the clip # Draw the logo text clipped to the current state of the animation, then remove the clip
@ -136,7 +175,7 @@ if __name__ == "__main__":
Ignore hangup signals. Enabling this may be necessary for running the launcher as a systemd service. See Ignore hangup signals. Enabling this may be necessary for running the launcher as a systemd service. See
https://stackoverflow.com/questions/57205271/how-to-display-pygame-framebuffer-using-systemd-service https://stackoverflow.com/questions/57205271/how-to-display-pygame-framebuffer-using-systemd-service
""") """)
arguments = parser.parse_args() arguments, unknown = parser.parse_known_args()
# If not keeping the working directory, try to move into the same directory as where this program is stored. Use the location of the program # If not keeping the working directory, try to move into the same directory as where this program is stored. Use the location of the program
# that launched this process to determine the path. # that launched this process to determine the path.

4
config
View File

@ -1,8 +1,8 @@
[display] [display]
clear = 0, 0, 0 clear = 0, 0, 0
caption = Playzing caption = Playzing
dimensions = 480, 720 dimensions = 720, 480
#dimensions = 720, 480 rotated = no
[logo] [logo]
fire = fire.png fire = fire.png

@ -1 +1 @@
Subproject commit 34451c3f4cacee9b2df3b0dff68e6539f5754bc4 Subproject commit 71cc53f3994b6e174bb4b8983d7d821a5bfc9e14