diff options
Diffstat (limited to 'src/game.py')
-rw-r--r-- | src/game.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/game.py b/src/game.py index d91e378..82330b7 100644 --- a/src/game.py +++ b/src/game.py @@ -10,8 +10,13 @@ import save import time import helper +clock = pygame.time.Clock() + def run(screen, save_data): + global clock + first = True + focused = True canvas = pygame.Surface((1280, 720)) running = True zoom = (1280.0, 720.0) @@ -40,13 +45,18 @@ def run(screen, save_data): if not paused: audio.play_music() + 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.MOUSEMOTION, pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN, 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.MOUSEMOTION: pygame.mouse.set_visible(paused or picker) - mouse = pygame.mouse.get_pos() + mouse = helper.get_real_mouse(screen) if event.type == pygame.MOUSEBUTTONDOWN: left, middle, right = pygame.mouse.get_pressed() - print(pygame.mouse.get_pos()) + print(helper.get_real_mouse(screen)) if paused: if left: @@ -92,7 +102,7 @@ def run(screen, save_data): if len(chunk) - 1 < screen_blocks[i][3] + 1 < 65: chunk.append([["air" for _ in range(16)] for _ in range(16)]) - if len(chunk) - 1 >= screen_blocks[i][3] + 1 and chunk[screen_blocks[i][3] + 1][screen_blocks[i][7]][screen_blocks[i][6]] == "air": + if len(chunk) - 1 >= screen_blocks[i][3] + 1 and chunk[screen_blocks[i][3] + 1][screen_blocks[i][7]][screen_blocks[i][6]] == "air" and chunk[screen_blocks[i][3] + 1][screen_blocks[i][6]][screen_blocks[i][7]] != selected_block: audio.play_sfx(block_list[selected_block]['sounds'][0]) chunk[screen_blocks[i][3] + 1][screen_blocks[i][6]][screen_blocks[i][7]] = selected_block need_update_world = True @@ -143,14 +153,17 @@ def run(screen, save_data): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: if picker: + clock.tick(60) audio.play_sfx("back") picker = False else: paused = not paused if paused: + clock.tick(25) audio.play_sfx("menu") audio.pause_music() else: + clock.tick(60) audio.play_sfx("back") audio.unpause_music() pygame.mouse.set_visible(paused) @@ -183,7 +196,9 @@ def run(screen, save_data): zoom, offset = zoom_util.zoom_reset() need_update_world = True if event.type == pygame.QUIT: - pause.save_and_quit(screen, save_data, loaded_chunks) + pause.save_and_quit(screen, save_data, loaded_chunks, False) running = False - canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, blocks, save_data = display.draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, save_data) + canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, blocks, save_data, focused, clock = display.draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, save_data, focused, clock) + + clock.tick(60) |