rotate
This commit is contained in:
parent
09564da198
commit
c22d9f0b3e
69
Playzing.py
69
Playzing.py
|
@ -8,17 +8,18 @@ from games.ibitfit.electric_sieve.ElectricSieve import ElectricSieve
|
|||
|
||||
class Playzing(pgfw.Game):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, config_overrides=None):
|
||||
"""
|
||||
Create logo sprite, clear screen, and subscribe to events.
|
||||
"""
|
||||
pgfw.Game.__init__(self)
|
||||
|
||||
# Assign types to configuration values
|
||||
self.get_configuration().type_declarations.add_chart({
|
||||
self.configuration.type_declarations.add_chart({
|
||||
"display":
|
||||
{
|
||||
"int-list": "clear"
|
||||
"int-list": "clear",
|
||||
"bool": "rotated"
|
||||
},
|
||||
"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
|
||||
self.get_display_surface().fill(self.configuration.get("display", "clear"))
|
||||
|
||||
|
@ -37,33 +41,53 @@ class Playzing(pgfw.Game):
|
|||
# Load sprites for logo parts
|
||||
self.logo_text = pgfw.Sprite(self)
|
||||
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.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
|
||||
self.register(self.animate_logo)
|
||||
self.register(self.reveal_text, interval=40)
|
||||
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):
|
||||
"""
|
||||
Reset the logo animation to its beginning and start animating.
|
||||
"""
|
||||
# Place the logo
|
||||
screen_rect = self.get_display_surface().get_rect()
|
||||
margin = self.configuration.get("logo", "margin")
|
||||
self.logo_text.location.center = screen_rect.center
|
||||
self.logo_text.move(-self.logo_fire.location.w + margin / 2)
|
||||
self.logo_text.location.center = self.get_display_surface().get_rect().center
|
||||
self.logo_text.move(-self.orient(self.logo_fire.location).w + margin / 2, rotated=self.rotated)
|
||||
|
||||
# Clear the screen
|
||||
self.get_display_surface().fill(self.configuration.get("display", "clear"))
|
||||
|
||||
# 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
|
||||
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
|
||||
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.
|
||||
"""
|
||||
self.logo_fire.move(10)
|
||||
self.logo_text_clip.width = self.logo_fire.location.left - self.logo_text.location.left
|
||||
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
|
||||
self.logo_fire.move(10, rotated=self.rotated)
|
||||
halt = False
|
||||
if not self.rotated:
|
||||
self.logo_text_clip.width = self.logo_fire.location.left - self.logo_text.location.left
|
||||
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.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
|
||||
if not self.configuration.get("logo", "trail"):
|
||||
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)
|
||||
|
||||
# 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
|
||||
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
|
||||
# that launched this process to determine the path.
|
||||
|
|
4
config
4
config
|
@ -1,8 +1,8 @@
|
|||
[display]
|
||||
clear = 0, 0, 0
|
||||
caption = Playzing
|
||||
dimensions = 480, 720
|
||||
#dimensions = 720, 480
|
||||
dimensions = 720, 480
|
||||
rotated = no
|
||||
|
||||
[logo]
|
||||
fire = fire.png
|
||||
|
|
2
lib/pgfw
2
lib/pgfw
|
@ -1 +1 @@
|
|||
Subproject commit 34451c3f4cacee9b2df3b0dff68e6539f5754bc4
|
||||
Subproject commit 71cc53f3994b6e174bb4b8983d7d821a5bfc9e14
|
Loading…
Reference in New Issue