added title screen loading at launch

This commit is contained in:
Nicholas Dyer 2023-05-11 12:20:07 -04:00
parent 6f6eaa3c6d
commit 2ffd9bd929
2 changed files with 22 additions and 10 deletions

View File

@ -2,6 +2,7 @@ import pygame
import os
from pathlib import Path
import pocket_friends
from pocket_friends.game_files.surfaces import title
# FPS for the entire game to run at.
game_fps = 16
@ -9,6 +10,10 @@ game_fps = 16
game_res = 80
script_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = os.path.join(Path.home(), '.pocket_friends')
resources_dir = script_dir + '/surfaces/resources'
starting_surface = 'title'
# Gets the directory of the script for importing and the save directory
@ -24,21 +29,16 @@ def game():
pygame.mouse.set_visible(False)
pygame.display.set_caption('Pocket Friends {0}'.format(pocket_friends.__version__))
window = pygame.display.set_mode((screen_size, screen_size))
surface = pygame.Surface((game_res, game_res))
surface = globals()[starting_surface].Surface((game_res, game_res), resources_dir)
# Add an icon to the pygame window.
icon = pygame.image.load(script_dir + '/resources/images/icon/icon.png').convert_alpha()
icon = pygame.image.load(script_dir + '/icon/icon.png').convert_alpha()
pygame.display.set_icon(icon)
clock = pygame.time.Clock()
# Font used for small text in the game. Bigger text is usually image files.
small_font = pygame.font.Font(script_dir + '/resources/fonts/5Pts5.ttf', 10)
# Default game state when the game first starts.
game_state = 'title'
running = True
# A group of all the sprites on screen. Used to update all sprites at onc
@ -47,6 +47,14 @@ def game():
# Time since last input. Used to help regulate double presses of buttons.
last_input_tick = 0
while running:
clock.tick(game_fps)
surface.update()
frame = pygame.transform.scale(surface, (screen_size, screen_size))
window.blit(frame, frame.get_rect())
pygame.display.flip()
def main():
"""

View File

@ -2,11 +2,15 @@ import pygame
class Surface(pygame.Surface):
def __init__(self, window_size):
def __init__(self, window_size, resources_dir):
super().__init__(window_size, pygame.SRCALPHA)
self.running = True
self.next_surface = None
def update(self):
self.fill((0, 0, 0))
self.bg = pygame.image.load(resources_dir + '/images/bg.png').convert_alpha()
self.title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha()
def update(self):
self.blit(self.bg, (0, 0))
self.blit(self.title, (0, 0))