Created
May 7, 2025 07:19
-
-
Save EncodeTheCode/3c7cc84fa31963e2f9d6a99bef1bb91c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import sys | |
import time | |
# Initialize Pygame | |
pygame.init() | |
# === CONFIGURABLE SETTINGS === | |
WINDOW_WIDTH = 320 | |
WINDOW_HEIGHT = 240 | |
UPSCALED_WIDTH = 1920 | |
UPSCALED_HEIGHT = 1080 | |
FONT_SIZE = 12 | |
TEXT_SCALE = 2 | |
TEXT_OFFSET_X = 0 | |
TEXT_OFFSET_Y = 30 | |
BG_COLOR = (0, 50, 200) | |
BG_PADDING_X = 8 | |
BG_PADDING_Y = 4 | |
BG_OPACITY = 0.8 | |
DISPLAY_DURATION = 4.0 # Total display time in seconds | |
FADE_IN_DURATION = 1.0 | |
FADE_OUT_DURATION = 1.0 | |
VISIBLE_DURATION = 2.0 # Full alpha hold time | |
# Load custom font | |
font_path = "visitor1.ttf" | |
font = pygame.font.Font(font_path, FONT_SIZE) | |
# Set up window | |
screen = pygame.display.set_mode((UPSCALED_WIDTH, UPSCALED_HEIGHT), pygame.RESIZABLE) | |
pygame.display.set_caption("Syphon Filter Pickup Message") | |
clock = pygame.time.Clock() | |
# Start timer | |
start_time = time.time() | |
# Message | |
MESSAGE = "M16 AMMO PICKED UP" | |
def scale_surface(surface, scale): | |
width = surface.get_width() * scale | |
height = surface.get_height() * scale | |
return pygame.transform.scale(surface, (width, height)) | |
try: | |
running = True | |
while running: | |
dt = clock.tick(60) / 1000.0 | |
elapsed = time.time() - start_time | |
screen.fill((0, 0, 0)) | |
# Compute alpha based on elapsed time | |
if elapsed < FADE_IN_DURATION: | |
alpha = int((elapsed / FADE_IN_DURATION) * 255) | |
elif elapsed < FADE_IN_DURATION + VISIBLE_DURATION: | |
alpha = 255 | |
elif elapsed < DISPLAY_DURATION: | |
fade_out_elapsed = elapsed - (FADE_IN_DURATION + VISIBLE_DURATION) | |
alpha = int((1 - (fade_out_elapsed / FADE_OUT_DURATION)) * 255) | |
else: | |
running = False | |
continue | |
# Render text and shadow | |
text_surf = font.render(MESSAGE, True, (255, 255, 255)) | |
shadow_surf = font.render(MESSAGE, True, (0, 0, 0)) | |
text_scaled = scale_surface(text_surf, TEXT_SCALE) | |
shadow_scaled = scale_surface(shadow_surf, TEXT_SCALE) | |
text_scaled.set_alpha(alpha) | |
shadow_scaled.set_alpha(alpha) | |
# Positioning | |
center_x = WINDOW_WIDTH // 2 + TEXT_OFFSET_X | |
center_y = WINDOW_HEIGHT - TEXT_OFFSET_Y | |
text_rect = text_scaled.get_rect(center=(center_x, center_y)) | |
# Background box | |
bg_rect = pygame.Rect( | |
text_rect.left - BG_PADDING_X, | |
text_rect.top - BG_PADDING_Y, | |
text_rect.width + BG_PADDING_X * 2, | |
text_rect.height + BG_PADDING_Y * 2 | |
) | |
bg_surface = pygame.Surface(bg_rect.size, pygame.SRCALPHA) | |
bg_surface.fill(BG_COLOR) | |
bg_surface.set_alpha(int(alpha * BG_OPACITY)) | |
# Internal rendering at native resolution | |
internal_surface = pygame.Surface((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.SRCALPHA) | |
internal_surface.blit(bg_surface, bg_rect.topleft) | |
internal_surface.blit(shadow_scaled, (text_rect.x + 2, text_rect.y + 2)) | |
internal_surface.blit(text_scaled, text_rect.topleft) | |
# Upscale to screen with nearest neighbor | |
final_surface = pygame.transform.scale(internal_surface, (UPSCALED_WIDTH, UPSCALED_HEIGHT)) | |
screen.blit(final_surface, (0, 0)) | |
pygame.display.flip() | |
except Exception as e: | |
print("An error occurred:", e) | |
finally: | |
pygame.quit() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment