summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-09-03 14:39:50 +0200
committerRaindropsSys <contact@minteck.org>2023-09-03 14:39:50 +0200
commit153d21ace9801ac665e2d7f99c967147d1214f29 (patch)
treef363dccf520fbc2c1670d2308b73294fa9ab5676
parent6a20ab31ef4d9f6bb0e008b9f1b8d3fbeb6bd956 (diff)
downloadblocks-153d21ace9801ac665e2d7f99c967147d1214f29.tar.gz
blocks-153d21ace9801ac665e2d7f99c967147d1214f29.tar.bz2
blocks-153d21ace9801ac665e2d7f99c967147d1214f29.zip
Updated 16 files and added 5 files (automated)
-rw-r--r--.gitignore3
-rw-r--r--.idea/blocks.iml2
-rw-r--r--.idea/discord.xml2
-rw-r--r--.idea/misc.xml2
-rw-r--r--assets/source/texture_atlas.psdbin106829 -> 272735 bytes
-rw-r--r--assets/textures/icon-mac.icnsbin0 -> 169997 bytes
-rw-r--r--assets/textures/icon-mac.pngbin0 -> 188996 bytes
-rw-r--r--assets/textures/icon.icobin0 -> 182342 bytes
-rw-r--r--assets/textures/icon.pngbin0 -> 5388 bytes
-rw-r--r--assets/textures/texture_atlas.pngbin9128 -> 37400 bytes
-rwxr-xr-xbuild.sh24
-rw-r--r--main.py38
-rw-r--r--src/audio.py10
-rw-r--r--src/debug.py66
-rw-r--r--src/display.py16
-rw-r--r--src/game.py25
-rw-r--r--src/helper.py18
-rw-r--r--src/loader.py2
-rw-r--r--src/menu.py43
-rw-r--r--src/pause.py8
-rw-r--r--src/window.py11
21 files changed, 217 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore
index 027c5c8..2c99b10 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
__pycache__
venv
win32
-dist \ No newline at end of file
+dist
+venv_x86 \ No newline at end of file
diff --git a/.idea/blocks.iml b/.idea/blocks.iml
index 66e1bc6..331b438 100644
--- a/.idea/blocks.iml
+++ b/.idea/blocks.iml
@@ -7,7 +7,7 @@
<excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/win32" />
</content>
- <orderEntry type="jdk" jdkName="Python 3.10 (blocks)" jdkType="Python SDK" />
+ <orderEntry type="jdk" jdkName="Python 3.10 ARM64 (blocks)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module> \ No newline at end of file
diff --git a/.idea/discord.xml b/.idea/discord.xml
index 30bab2a..cf77f1e 100644
--- a/.idea/discord.xml
+++ b/.idea/discord.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
- <option name="show" value="ASK" />
+ <option name="show" value="DISABLE" />
<option name="description" value="" />
</component>
</project> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9dee8a7..623cdbf 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
- <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (blocks)" project-jdk-type="Python SDK" />
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 ARM64 (blocks)" project-jdk-type="Python SDK" />
</project> \ No newline at end of file
diff --git a/assets/source/texture_atlas.psd b/assets/source/texture_atlas.psd
index 790f1f9..faae857 100644
--- a/assets/source/texture_atlas.psd
+++ b/assets/source/texture_atlas.psd
Binary files differ
diff --git a/assets/textures/icon-mac.icns b/assets/textures/icon-mac.icns
new file mode 100644
index 0000000..48498a7
--- /dev/null
+++ b/assets/textures/icon-mac.icns
Binary files differ
diff --git a/assets/textures/icon-mac.png b/assets/textures/icon-mac.png
new file mode 100644
index 0000000..50b2ba5
--- /dev/null
+++ b/assets/textures/icon-mac.png
Binary files differ
diff --git a/assets/textures/icon.ico b/assets/textures/icon.ico
new file mode 100644
index 0000000..ef59d06
--- /dev/null
+++ b/assets/textures/icon.ico
Binary files differ
diff --git a/assets/textures/icon.png b/assets/textures/icon.png
new file mode 100644
index 0000000..750b821
--- /dev/null
+++ b/assets/textures/icon.png
Binary files differ
diff --git a/assets/textures/texture_atlas.png b/assets/textures/texture_atlas.png
index 47b2383..05a9733 100644
--- a/assets/textures/texture_atlas.png
+++ b/assets/textures/texture_atlas.png
Binary files differ
diff --git a/build.sh b/build.sh
index ad10b5a..0ef2218 100755
--- a/build.sh
+++ b/build.sh
@@ -3,34 +3,40 @@ source ./venv/bin/activate
rm -rf ./dist ./_temp
mkdir -p ./dist/darwin-arm64 ./dist/darwin-x64 ./dist/win32 ./dist/linux-arm64 ./dist/linux-x64 ./_temp
-podman machine start
-ssh -i ~/.ssh/podman-machine-default -R 10000:$(hostname):22 -p $(podman machine --log-level=debug ssh -- exit 2>&1 | grep Executing | awk {'print $8'}) core@localhost sshfs -p 10000 $USER@127.0.0.1:/Volumes/Projects /mnt/Projects&
+#podman machine start
+#ssh -i ~/.ssh/podman-machine-default -R 10000:$(hostname):22 -p $(podman machine --log-level=debug ssh -- exit 2>&1 | grep Executing | awk {'print $8'}) core@localhost sshfs -p 10000 $USER@127.0.0.1:/Volumes/Projects /mnt/Projects&
# macOS
cp -rv ./assets ./_temp/assets
-pyinstaller --distpath ./dist/darwin-arm64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --osx-bundle-identifier dev.equestria.blocks --target-architecture arm64 main.py
+pyinstaller --distpath ./dist/darwin-arm64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --osx-bundle-identifier dev.equestria.blocks -i ./assets/textures/icon-mac.icns --target-architecture arm64 main.py
rm -rf ./_temp
+
+source ./venv_x86/bin/activate
mkdir -p ./_temp
cp -rv ./assets ./_temp/assets
-pyinstaller --distpath ./dist/darwin-x64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --osx-bundle-identifier dev.equestria.blocks --target-architecture x86_64 main.py
+arch -x86_64 pyinstaller --distpath ./dist/darwin-x64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --osx-bundle-identifier dev.equestria.blocks -i ./assets/textures/icon-mac.icns --target-architecture x86_64 main.py
rm -rf ./_temp
+source ./venv_x86/bin/activate
+exit
+
# Linux
mkdir -p ./_temp
cp -rv ./assets ./_temp/assets
podman start blocks-build
-podman exec blocks-build bash -c "cd /blocks && pyinstaller --distpath ./dist/linux-arm64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --onefile main.py"
+podman exec blocks-build bash -c "cd /blocks && pyinstaller --distpath ./dist/linux-arm64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --hidden-import=pygame -i ./assets/textures/icon.png --onefile main.py"
rm -rf ./_temp
podman stop blocks-build
podman machine stop
mkdir -p ./_temp
cp -rv ./assets ./_temp/assets
-ssh zephyrheights sshfs $USER@192.168.1.23:/Volumes/Projects/blocks /blocks && ssh zephyrheights sshfs $USER@192.168.1.23:/Volumes/Projects/blocks /blocks
-ssh zephyrheights 'bash -c "cd /blocks && pyinstaller --distpath ./dist/linux-x64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --onefile main.py && cd / && umount /blocks"'
+ssh zephyrheights umount -lf /blocks
+ssh zephyrheights sshfs $USER@192.168.1.23:/Volumes/Projects/blocks /blocks
+ssh zephyrheights 'bash -c "cd /blocks && pyinstaller --distpath ./dist/linux-x64 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data assets:assets -p src -s --noconsole --hidden-import=pygame -i ./assets/textures/icon.png --onefile main.py && cd / && umount /blocks"'
rm -rf ./_temp
# Windows
mkdir -p ./_temp
cp -rv ./assets ./_temp/assets
-wine64 $PWD/win32/Scripts/pyinstaller.exe --distpath ./dist/win32 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data "assets;assets" -p src --noconsole --onefile main.py
-rm -rf ./_temp \ No newline at end of file
+wine64 $PWD/win32/Scripts/pyinstaller.exe --distpath ./dist/win32 --workpath ./_temp --noconfirm --specpath ./_temp -n Blocks --add-data "assets;assets" -p src --noconsole -i ./assets/textures/icon.ico --onefile main.py
+rm -rf ./_temp
diff --git a/main.py b/main.py
index cb9b8c2..2c0d989 100644
--- a/main.py
+++ b/main.py
@@ -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()
diff --git a/src/audio.py b/src/audio.py
index 1d8f725..169c886 100644
--- a/src/audio.py
+++ b/src/audio.py
@@ -1,10 +1,14 @@
import pygame
import random
-enable_audio = False
+enable_audio = True
+
+try:
+ pygame.mixer.init()
+except pygame.error:
+ print("WARNING: Failed to initialize DSP mixer.")
+ enable_audio = False
-pygame.mixer.pre_init(48000, -16, 2, 2048)
-pygame.mixer.init()
pygame.mixer.set_num_channels(3)
pygame.mixer.stop()
diff --git a/src/debug.py b/src/debug.py
new file mode 100644
index 0000000..b60e808
--- /dev/null
+++ b/src/debug.py
@@ -0,0 +1,66 @@
+import pygame
+import constants
+
+def show_debug(clock, extended=False):
+ screen = pygame.display.get_surface()
+
+ if extended:
+ accelerates = []
+ info = pygame.display.Info()
+
+ if info.hw == 1:
+ accelerates.append("HARDWARE")
+ if info.blit_hw == 1:
+ accelerates.append("HW_BLIT")
+ if info.blit_hw_CC == 1:
+ accelerates.append("HW_BLIT_CK")
+ if info.blit_hw_A == 1:
+ accelerates.append("HW_BLIT_RGBA")
+ if info.blit_sw == 1:
+ accelerates.append("BLIT")
+ if info.blit_sw_CC == 1:
+ accelerates.append("BLIT_CK")
+ if info.blit_sw_A == 1:
+ accelerates.append("BLIT_RGBA")
+
+ width = screen.get_size()[0]
+ height = width / (16/9)
+
+ if width > screen.get_size()[0] or height > screen.get_size()[1]:
+ height = screen.get_size()[1]
+ width = height * (16/9)
+
+ offset_x = screen.get_size()[0] / 2 - width / 2
+ offset_y = screen.get_size()[1] / 2 - height / 2
+ scaling = ((width / 1280) + (height / 720)) / 2
+
+ text = [
+ f"Blocks {constants.VERSION}, Pygame {pygame.version.ver}, SDL {pygame.version.SDL}",
+ f"{str(round(clock.get_fps()))} FPS",
+ f"",
+ f"Graphics:",
+ f" Driver: {pygame.display.get_driver()}, VRAM: {info.video_mem} MB, {info.bitsize}bit color",
+ f" Acceleration: {','.join(accelerates)}",
+ f" Window: {pygame.display.get_window_size()[0]}x{pygame.display.get_window_size()[1]}, Scaling factor: {round(scaling, 3)}x",
+ f"",
+ f"Audio:",
+ f" Mixer: {pygame.mixer.get_sdl_mixer_version()}",
+ f" Channels:"
+ ]
+
+ for i in range(pygame.mixer.get_num_channels()):
+ channel = pygame.mixer.Channel(i)
+ txt = " " + str(i) + ": [" + str(round(channel.get_volume(), 3)) + "] "
+
+ if channel.get_busy():
+ sound = channel.get_sound()
+ txt += hex(id(sound)) + " (" + str(round(sound.get_length(), 3)) + ")"
+ else:
+ txt += " <idle>"
+
+ text.append(txt)
+ else:
+ text = [f"{str(round(clock.get_fps()))} FPS"]
+
+ for i in range(len(text)):
+ screen.blit(pygame.font.SysFont("Arial", 14).render(text[i], True, (255, 255, 255), (0, 0, 0)), (5, screen.get_size()[1] - 20 - ((len(text) - 1 - i) * 15)))
diff --git a/src/display.py b/src/display.py
index 536b2f3..ad4c48b 100644
--- a/src/display.py
+++ b/src/display.py
@@ -5,16 +5,12 @@ import pause
import picker as picker_ui
import time
import save
+import debug
opacity = 0
-def draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, save_data):
- global v1
- global v2
- global last_v1
- global last_v2
-
- blocks = [] # TODO: Figure out what chunks to get and how to get them
+def draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, save_data, focused, clock):
+ blocks = []
start = time.time()
timings = {}
@@ -204,7 +200,9 @@ def draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, o
timings['screen_display_final'] = (time.time() - tstart) * 1000
tstart = time.time()
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
timings['screen_display_flip'] = (time.time() - tstart) * 1000
if opacity < 1:
@@ -218,4 +216,4 @@ def draw(canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, o
print(timings)
print("-----------------------")
- return canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, blocks, save_data
+ return canvas, screen, need_update_world, world, mouse, loaded_chunks, zoom, offset, block_coordinates, paused, screen_blocks, selected_block, picker, blocks, save_data, focused, clock
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)
diff --git a/src/helper.py b/src/helper.py
index 46f831a..2f4e53e 100644
--- a/src/helper.py
+++ b/src/helper.py
@@ -70,4 +70,20 @@ def get_chunk_regions(chunks):
"range": (16 * x, 16 * y, 15 + 16 * x, 15 + 16 * y)
})
- return data \ No newline at end of file
+ return data
+
+def get_real_mouse(screen):
+ width = screen.get_size()[0]
+ height = width / (16/9)
+
+ if width > screen.get_size()[0] or height > screen.get_size()[1]:
+ height = screen.get_size()[1]
+ width = height * (16/9)
+
+ offset_x = screen.get_size()[0] / 2 - width / 2
+ offset_y = screen.get_size()[1] / 2 - height / 2
+ scaling = ((width / 1280) + (height / 720)) / 2
+
+ pos = pygame.mouse.get_pos()
+
+ return (int((pos[0] - offset_x) / scaling), int((pos[1] - offset_y) / scaling))
diff --git a/src/loader.py b/src/loader.py
index 02da9e0..75d7701 100644
--- a/src/loader.py
+++ b/src/loader.py
@@ -1,7 +1,7 @@
import pygame
from math import floor
-texture_map = pygame.image.load('./assets/textures/intro_atlas.png')
+texture_map = pygame.image.load('./assets/textures/intro_atlas.png').convert_alpha()
preloaded = []
for i in range(8):
diff --git a/src/menu.py b/src/menu.py
index 1b877ac..49e263f 100644
--- a/src/menu.py
+++ b/src/menu.py
@@ -5,19 +5,28 @@ import helper
import audio
import save
import constants
+import debug
+
+clock = pygame.time.Clock()
def show(screen):
running = True
+ focused = True
opacity = 0
audio.play_menu(True)
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.MOUSEBUTTONDOWN, pygame.MOUSEMOTION, 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(True)
if event.type == pygame.MOUSEBUTTONDOWN:
left, middle, right = pygame.mouse.get_pressed()
- mouse = pygame.mouse.get_pos()
+ mouse = helper.get_real_mouse(screen)
print(mouse)
if left:
@@ -43,7 +52,12 @@ def show(screen):
while run and not done:
canvas.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, pygame.KEYDOWN])
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:
run = False
quit = True
@@ -77,7 +91,11 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
+
+ clock.tick(25)
if quit:
pygame.quit()
@@ -90,6 +108,7 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
+ debug.show_debug(clock)
pygame.display.flip()
audio.wait_for_sfx()
@@ -124,12 +143,17 @@ def show(screen):
while run and not done:
canvas.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, pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN])
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:
run = False
quit = True
elif event.type == pygame.MOUSEBUTTONDOWN:
- cursor = pygame.mouse.get_pos()
+ cursor = helper.get_real_mouse(screen)
for i in range(len(saves)):
save_name = saves[i]
@@ -161,7 +185,11 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
+
+ clock.tick(25)
if quit:
pygame.quit()
elif done:
@@ -173,6 +201,7 @@ def show(screen):
scaled_win = pygame.transform.scale(canvas, (width, height))
screen.blit(scaled_win, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
+ debug.show_debug(clock)
pygame.display.flip()
loaded = save.load_world(helper.get_data_path() + "/saves/" + world_name)
@@ -227,10 +256,14 @@ def show(screen):
screen.blit(result, (screen.get_size()[0] / 2 - width / 2, screen.get_size()[1] / 2 - height / 2))
audio.play_menu()
- pygame.display.flip()
+ if focused:
+ debug.show_debug(clock)
+ pygame.display.flip()
if opacity < 1:
opacity += 1/30
if opacity >= 1:
opacity = 1
+
+ clock.tick(25)
diff --git a/src/pause.py b/src/pause.py
index a68ea1f..84a7242 100644
--- a/src/pause.py
+++ b/src/pause.py
@@ -31,8 +31,9 @@ def click(mouse, screen, paused, keep, save_data, regions):
return mouse, screen, paused, keep
-def save_and_quit(screen, path, regions):
- audio.play_sfx("save")
+def save_and_quit(screen, path, regions, sfx=True):
+ if sfx:
+ audio.play_sfx("save")
canvas = pygame.Surface((1280, 720))
canvas.fill("black")
@@ -52,6 +53,7 @@ def save_and_quit(screen, path, regions):
pygame.display.flip()
audio.stop(1)
- audio.wait_for_sfx()
+ if sfx:
+ audio.wait_for_sfx()
save.save_world(path, regions) \ No newline at end of file
diff --git a/src/window.py b/src/window.py
index fd35f39..4df6065 100644
--- a/src/window.py
+++ b/src/window.py
@@ -1,6 +1,13 @@
+import sys
+
import pygame
def init():
pygame.display.set_caption("Blocks")
- pygame.mouse.set_visible(False)
- pygame.mouse.set_pos((0, 0)) \ No newline at end of file
+
+ if sys.platform == "darwin":
+ pygame.display.set_icon(pygame.image.load('./assets/textures/icon-mac.png').convert_alpha())
+ else:
+ pygame.display.set_icon(pygame.image.load('./assets/textures/icon.png').convert_alpha())
+
+ pygame.mouse.set_visible(True)