diff options
author | RaindropsSys <contact@minteck.org> | 2023-09-03 14:39:50 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-09-03 14:39:50 +0200 |
commit | 153d21ace9801ac665e2d7f99c967147d1214f29 (patch) | |
tree | f363dccf520fbc2c1670d2308b73294fa9ab5676 /main.py | |
parent | 6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956 (diff) | |
download | blocks-153d21ace9801ac665e2d7f99c967147d1214f29.tar.gz blocks-153d21ace9801ac665e2d7f99c967147d1214f29.tar.bz2 blocks-153d21ace9801ac665e2d7f99c967147d1214f29.zip |
Updated 16 files and added 5 files (automated)
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -11,28 +11,37 @@ import pygame import sys sys.path.append("./src") -from src import audio, window, loader, menu, helper -helper.get_data_path() +clock = pygame.time.Clock() +screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE | pygame.HWSURFACE | pygame.HWACCEL | pygame.DOUBLEBUF, vsync=True) -pygame.font.init() +from src import window +pygame.mixer.pre_init(44100, 16, 2, 4096) +window.init() pygame.init() -window.init() -clock = pygame.time.Clock() -screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE, vsync=True) +screen.fill("black") +pygame.display.flip() + +focused = True running = True index = 0 +from src import audio, loader, menu played_audio = False showing_load = True +pygame.font.init() while running: try: - pygame.display.flip() screen.fill("black") + pygame.event.set_allowed([pygame.APPMOUSEFOCUS, pygame.APPINPUTFOCUS, pygame.WINDOWRESIZED, pygame.WINDOWEXPOSED, pygame.WINDOWENTER, pygame.WINDOWLEAVE, pygame.WINDOWFOCUSLOST, pygame.WINDOWFOCUSGAINED, pygame.WINDOWICCPROFCHANGED, pygame.WINDOWTAKEFOCUS, pygame.WINDOWMINIMIZED, pygame.QUIT]) for event in pygame.event.get(): + if event.type == pygame.WINDOWFOCUSLOST: + focused = False + if event.type == pygame.WINDOWFOCUSGAINED: + focused = True if event.type == pygame.QUIT: running = False @@ -49,11 +58,14 @@ while running: if index > 70: showing_load = False - pygame.display.flip() + if focused: + pygame.display.flip() clock.tick(25) else: loader.unload_intro() + import helper + helper.get_data_path() menu.show(screen) break except Exception as e: @@ -68,7 +80,7 @@ while running: screen.fill((0, 0, 0)) - img = pygame.image.load("./assets/textures/crash.png") + img = pygame.image.load("./assets/textures/crash.png").convert_alpha() img.convert() screen.blit(pygame.transform.scale(img, (84, 84)), (100, 100)) @@ -78,7 +90,8 @@ while running: screen.blit(pygame.font.Font("./assets/font/main.ttf", 20).render("An error has occurred and the game has stopped.", False, (255, 255, 255)), (200, 124)) screen.blit(pygame.font.Font("./assets/font/main.ttf", 20).render("Error code: 0x" + code[0:8], False, (255, 255, 255)), (199, 144)) - pygame.display.update() + if focused: + pygame.display.flip() print(traceback.format_exc()) @@ -89,8 +102,11 @@ while running: print(traceback.format_exc()) while running: + pygame.event.set_allowed([pygame.APPMOUSEFOCUS, pygame.APPINPUTFOCUS, pygame.WINDOWRESIZED, pygame.WINDOWEXPOSED, pygame.WINDOWENTER, pygame.WINDOWLEAVE, pygame.WINDOWFOCUSLOST, pygame.WINDOWFOCUSGAINED, pygame.WINDOWICCPROFCHANGED, pygame.WINDOWTAKEFOCUS, pygame.WINDOWMINIMIZED, pygame.QUIT]) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False -pygame.quit()
\ No newline at end of file + clock.tick(1) + +pygame.quit() |