From f8baebb304faf9272fe430276f81d25957abc6de Mon Sep 17 00:00:00 2001 From: kimhwijin Date: Mon, 13 Jun 2022 22:50:22 +0900 Subject: [PATCH 1/3] add base path --- src/Settings.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Settings.py b/src/Settings.py index 7c4afbb..3db7723 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -1,4 +1,3 @@ - border_size = 20 topbar_height = 100 @@ -13,9 +12,16 @@ Ddisplay_width=border_size*2+Dboard_size[0]*cell_size[0] Ddisplay_height=border_size*2+Dboard_size[1]*cell_size[1] + title = "Snake Game" -icon_path = "images/icon.png" -font_style = "fonts/arial.ttf" -save_dir = "data" -save_state_path = "data/gamescene.dat" -save_rankings_path = "data/score.dat" + + +import os +from pathlib import Path + +base = Path(__file__).absolute().parent.parent +icon_path = base / "images/icon.png" +font_style = base / "fonts/arial.ttf" +save_dir = base / "data" +save_state_path = base / "data/gamescene.dat" +save_rankings_path = base / "data/score.dat" From 70493fff9440f38b6d93b8d547fea87d662aa432 Mon Sep 17 00:00:00 2001 From: kimhwijin Date: Mon, 13 Jun 2022 22:57:30 +0900 Subject: [PATCH 2/3] add png path in settings of basic text button image --- src/BasicTextButton.py | 6 ++++-- src/Settings.py | 11 +++++++++++ src/TitleScene.py | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/BasicTextButton.py b/src/BasicTextButton.py index aa15b2a..e25c371 100644 --- a/src/BasicTextButton.py +++ b/src/BasicTextButton.py @@ -1,15 +1,17 @@ +from typing import Set from Button import Button from pygame import Vector2 from Text import Text, ALIGN_CENTER +import Settings class BasicTextButton(Button): def __init__(self, text = "", pos = Vector2(0,0), flag = None): self.text = text if flag: - super().__init__("images/buttonframe2.png","images/buttonframe2_hover.png","images/buttonframe2_down.png") + super().__init__(Settings.f2_path,Settings.f2_hover_path,Settings.f2_down_path) self.text_object = Text(text, 25, align = ALIGN_CENTER, bold = True, italic=True) else: - super().__init__("images/buttonframe.png","images/buttonframe_hover.png","images/buttonframe_down.png") + super().__init__(Settings.f_path, Settings.f_hover_path, Settings.f_down_path) self.text_object = Text(text, 36, align = ALIGN_CENTER, bold = True, italic=True) def update(self, delta_time = 0): diff --git a/src/Settings.py b/src/Settings.py index 3db7723..4d36ea6 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -25,3 +25,14 @@ save_dir = base / "data" save_state_path = base / "data/gamescene.dat" save_rankings_path = base / "data/score.dat" + +bg_path = base / "images/titlescene/bg.png" + +f_path = base / "images/buttonframe.png" +f_hover_path = base / "images/buttonframe_hover.png" +f_down_path = base / "images/buttonframe_down.png" + +f2_path = base / "images/buttonframe2.png" +f2_hover_path = base / "images/buttonframe2_hover.png" +f2_down_path = base / "images/buttonframe2_down.png" + diff --git a/src/TitleScene.py b/src/TitleScene.py index c8ff389..3e3318e 100644 --- a/src/TitleScene.py +++ b/src/TitleScene.py @@ -16,7 +16,7 @@ class TitleScene: def __init__(self, saved = False): - self.bg = GameObject("images/titlescene/bg.png") + self.bg = GameObject(Settings.bg_path) self.bg.set_size(Settings.display_width, Settings.display_height) self.saved = saved From 839995eedd7714a801d47761d6c5dc748cf75d23 Mon Sep 17 00:00:00 2001 From: kimhwijin Date: Mon, 13 Jun 2022 23:01:11 +0900 Subject: [PATCH 3/3] path object to str --- src/Settings.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Settings.py b/src/Settings.py index 4d36ea6..28ec2d0 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -19,20 +19,20 @@ import os from pathlib import Path -base = Path(__file__).absolute().parent.parent -icon_path = base / "images/icon.png" -font_style = base / "fonts/arial.ttf" -save_dir = base / "data" -save_state_path = base / "data/gamescene.dat" -save_rankings_path = base / "data/score.dat" - -bg_path = base / "images/titlescene/bg.png" - -f_path = base / "images/buttonframe.png" -f_hover_path = base / "images/buttonframe_hover.png" -f_down_path = base / "images/buttonframe_down.png" - -f2_path = base / "images/buttonframe2.png" -f2_hover_path = base / "images/buttonframe2_hover.png" -f2_down_path = base / "images/buttonframe2_down.png" +base = str(Path(__file__).absolute().parent.parent) +icon_path = os.path.join(base, "images/icon.png") +font_style = os.path.join(base, "fonts/arial.ttf") +save_dir = os.path.join(base, "data") +save_state_path = os.path.join(base, "data/gamescene.dat") +save_rankings_path = os.path.join(base, "data/score.dat") + +bg_path = os.path.join(base, "images/titlescene/bg.png") + +f_path = os.path.join(base, "images/buttonframe.png") +f_hover_path = os.path.join(base, "images/buttonframe_hover.png") +f_down_path = os.path.join(base, "images/buttonframe_down.png") + +f2_path = os.path.join(base, "images/buttonframe2.png") +f2_hover_path = os.path.join(base, "images/buttonframe2_hover.png") +f2_down_path = os.path.join(base, "images/buttonframe2_down.png")