framebuffer flag for launcher script, permanent quit for when running as systemd service, wip reduce resolution to 800x450

This commit is contained in:
ohsqueezy 2022-11-01 17:56:59 -04:00
parent 93cec90dcc
commit 7555d3fca4
4 changed files with 54 additions and 15 deletions

30
NS.py
View File

@ -8,7 +8,7 @@
# README, or for the game in general, visit https://scrape.nugget.fun/ # README, or for the game in general, visit https://scrape.nugget.fun/
# #
import argparse, pathlib, operator import argparse, pathlib, operator, subprocess, sys
from random import randint, choice, random from random import randint, choice, random
from math import pi from math import pi
from copy import copy from copy import copy
@ -463,6 +463,22 @@ class NS(Game, Animation):
if self.idle_elapsed >= self.IDLE_TIMEOUT: if self.idle_elapsed >= self.IDLE_TIMEOUT:
self.reset() self.reset()
def end(self, event):
"""
Extend the parent end method to try adding a permanent quit feature in case there is a Raspbian Lite systemd autostart service running
"""
if event.type == QUIT or self.delegate.compare(event, "quit"):
if self.confirming_quit or not self.get_configuration("input", "confirm-quit"):
# If SHIFT is pressed, try permanently stopping the systemd service to get a console back in case this is running on
# Raspbian Lite
if pygame.key.get_mods() & pygame.KMOD_SHIFT:
try:
subprocess.run(["sudo", "systemctl", "stop", "scrapeboard"])
print("Killing with permanent stop sent to systemd scrapeboard service")
except:
print("No scrapeboard system service detected, so permanent quit either failed or was unnecessary")
super().end(event)
class LevelSelect(Animation): class LevelSelect(Animation):
""" """
@ -506,9 +522,15 @@ class LevelSelect(Animation):
text = pygame.transform.rotate(text, 90) text = pygame.transform.rotate(text, 90)
text_rect = text.get_rect() text_rect = text.get_rect()
text_rect.midleft = preview_rect.midleft text_rect.midleft = preview_rect.midleft
environment = pygame.transform.smoothscale( frame = self.get_game().boss.backgrounds[level_index].frames[0]
self.get_game().boss.backgrounds[level_index].frames[0], frame_rect = (preview_rect.w - text_rect.w - padding, preview_rect.h - padding * 2)
(preview_rect.w - text_rect.w - padding, preview_rect.h - padding * 2))
# Smooth scaling is not available on some platforms, so fallback to regular scale
try:
environment = pygame.transform.smoothscale(frame, frame_rect)
except ValueError:
environment = pygame.transform.scale(frame, frame_rect)
environment_rect = environment.get_rect() environment_rect = environment.get_rect()
environment_rect.midright = preview_rect.right - padding, preview_rect.centery environment_rect.midright = preview_rect.right - padding, preview_rect.centery
boss = pygame.transform.smoothscale(self.get_game().boss.level_sprite(level_index).frames[0], boss = pygame.transform.smoothscale(self.get_game().boss.level_sprite(level_index).frames[0],

View File

@ -1,22 +1,38 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#
# Scrapeboard is an arcade game in development by Frank DeMarco (@diskmem) and Blake Andrews (@snakesandrews). # Scrapeboard is an arcade game in development by Frank DeMarco (@diskmem) and Blake Andrews (@snakesandrews).
# It requires custom hardware to play, but it can be tested in keyboard mode with just the code in this # It requires custom hardware to play, but it can be tested in keyboard mode with just the code in this
# repository. For more information on setting up and running the game, see the README. For more information # repository. For more information on setting up and running the game, see README.md. For more information
# on the game in general, visit https://scrape.nugget.fun # on the game in general, visit <https://scrape.nugget.fun>.
# #
# This is the launcher script that creates a main game object and runs it. If you're running Python 3 with # This is the launcher script that creates a main game object and runs it. If you're running Python 3 with
# the pygame module installed, you should be able to run this script with the --no-serial flag to get it # the pygame module installed, you should be able to run this script with the --no-serial flag to get it
# running even without the custom hardware: # running even without the custom hardware:
# #
# ./OPEN-GAME --no-serial # ./OPEN-GAME --no-serial
#
from sys import argv import sys, os
if "--go-to-dir" in argv: def ignore_sighup():
move_to_executable() """
Ignore hangup signal (that is thrown when launching from systemd?).
Taken from https://stackoverflow.com/questions/57205271/how-to-display-pygame-framebuffer-using-systemd-service
"""
import signal
def handler(signum, frame):
pass
signal.signal(signal.SIGHUP, handler)
# Change directory to the directory of the program launching the script (usually this script "OPEN-GAME").
if "--go-to-dir" in sys.argv:
os.chdir(os.path.dirname(sys.argv[0]))
# Use the framebuffer display (for Raspberry Pi). This only works with Pygame 1.9.6 (and SDL 1.2).
if "--fb" in sys.argv:
import os
os.putenv("SDL_VIDEODRIVER", "fbcon")
os.putenv("SDL_FBDEV", "/dev/fb0")
ignore_sighup()
from NS import NS from NS import NS

5
config
View File

@ -23,7 +23,7 @@ data-exclude = local/, *.pyc, .git*, README, build/, dist/, *.egg-info, *.py, MA
[display] [display]
caption = Scrapeboard caption = Scrapeboard
show-framerate = no show-framerate = no
dimensions = 854, 480 dimensions = 800, 450
fullscreen = no fullscreen = no
attract-gif-alpha = 0.95 attract-gif-alpha = 0.95
effects = yes effects = yes
@ -48,7 +48,7 @@ first-combo-delay = 1300
visible = no visible = no
[keys] [keys]
quit = K_ESCAPE quit = K_q
up = K_u up = K_u
[audio] [audio]
@ -60,6 +60,7 @@ volume = 1.0
buffer = 0 buffer = 0
arduino-port = /dev/ttyACM0 arduino-port = /dev/ttyACM0
serial = True serial = True
confirm-quit = False
[time] [time]
timer-max-time = 10000 timer-max-time = 10000

@ -1 +1 @@
Subproject commit eb83f0d7c24a2325c24cb32e69e3af9baa34a889 Subproject commit 0954cd768f6fed46bf77436317271865a888c3a1