framebuffer flag for launcher script, permanent quit for when running as systemd service, wip reduce resolution to 800x450
This commit is contained in:
parent
93cec90dcc
commit
7555d3fca4
30
NS.py
30
NS.py
|
@ -8,7 +8,7 @@
|
|||
# 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 math import pi
|
||||
from copy import copy
|
||||
|
@ -463,6 +463,22 @@ class NS(Game, Animation):
|
|||
if self.idle_elapsed >= self.IDLE_TIMEOUT:
|
||||
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):
|
||||
"""
|
||||
|
@ -506,9 +522,15 @@ class LevelSelect(Animation):
|
|||
text = pygame.transform.rotate(text, 90)
|
||||
text_rect = text.get_rect()
|
||||
text_rect.midleft = preview_rect.midleft
|
||||
environment = pygame.transform.smoothscale(
|
||||
self.get_game().boss.backgrounds[level_index].frames[0],
|
||||
(preview_rect.w - text_rect.w - padding, preview_rect.h - padding * 2))
|
||||
frame = self.get_game().boss.backgrounds[level_index].frames[0]
|
||||
frame_rect = (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.midright = preview_rect.right - padding, preview_rect.centery
|
||||
boss = pygame.transform.smoothscale(self.get_game().boss.level_sprite(level_index).frames[0],
|
||||
|
|
32
OPEN-GAME
32
OPEN-GAME
|
@ -1,22 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# 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
|
||||
# repository. For more information on setting up and running the game, see the README. For more information
|
||||
# on the game in general, visit https://scrape.nugget.fun
|
||||
# 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>.
|
||||
#
|
||||
# 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
|
||||
# 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:
|
||||
move_to_executable()
|
||||
def ignore_sighup():
|
||||
"""
|
||||
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
|
||||
|
||||
|
|
5
config
5
config
|
@ -23,7 +23,7 @@ data-exclude = local/, *.pyc, .git*, README, build/, dist/, *.egg-info, *.py, MA
|
|||
[display]
|
||||
caption = Scrapeboard
|
||||
show-framerate = no
|
||||
dimensions = 854, 480
|
||||
dimensions = 800, 450
|
||||
fullscreen = no
|
||||
attract-gif-alpha = 0.95
|
||||
effects = yes
|
||||
|
@ -48,7 +48,7 @@ first-combo-delay = 1300
|
|||
visible = no
|
||||
|
||||
[keys]
|
||||
quit = K_ESCAPE
|
||||
quit = K_q
|
||||
up = K_u
|
||||
|
||||
[audio]
|
||||
|
@ -60,6 +60,7 @@ volume = 1.0
|
|||
buffer = 0
|
||||
arduino-port = /dev/ttyACM0
|
||||
serial = True
|
||||
confirm-quit = False
|
||||
|
||||
[time]
|
||||
timer-max-time = 10000
|
||||
|
|
2
lib/pgfw
2
lib/pgfw
|
@ -1 +1 @@
|
|||
Subproject commit eb83f0d7c24a2325c24cb32e69e3af9baa34a889
|
||||
Subproject commit 0954cd768f6fed46bf77436317271865a888c3a1
|
Loading…
Reference in New Issue