Skip to content

Commit

Permalink
해결 (물론 해상도 변경해서 UI 리마스터함)
Browse files Browse the repository at this point in the history
  • Loading branch information
MineEric64 committed Aug 28, 2023
1 parent e6603e9 commit 92f2311
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 125 deletions.
Binary file modified assets/images/background_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/background_main_edited.png
Binary file not shown.
Binary file added assets/images/background_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/ground_temp_tmp.png
Binary file not shown.
24 changes: 17 additions & 7 deletions components/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import pygame.constants

class CONST:
SCREEN_SIZE = [640, 360]
"""화면 (카메라) 크기 (640x360)"""
SCREEN_SIZE = [960, 540]
"""화면 (카메라) 크기 (960x540)"""

SURFACE_SIZE = [1280, 720]
"""세계 크기 (1280x720)"""
SURFACE_SIZE = [1920, 1080]
"""세계 크기 (1920x1080)"""

COL_WHITE = (255, 255, 255)
COL_BLACK = (0, 0, 0)
Expand Down Expand Up @@ -38,8 +38,18 @@ class Fonts(Enum):
class CONFIG:
FPS = 30

window_size = [1280, 720] # CONST.WINDOW_SIZE * 2
window_scale = 2
window_size = [1440, 810] # CONST.SCREEN_SIZE * 1.5
window_scale = 1.5

resolutions = [
[480, 270],
[960, 540],
[1440, 810],
[1920, 1080],
[2560, 1440],
[3840, 2160]
]
"""적용할 수 있는 해상도 배열"""

surface = pygame.Surface(CONST.SURFACE_SIZE)
"""크기가 [640, 360]으로 고정된 화면
Expand Down Expand Up @@ -118,7 +128,7 @@ def get_mouse_pos() -> tuple[int, int]:
mouse_pos[0] // CONFIG.window_scale,
mouse_pos[1] // CONFIG.window_scale
)

# 월드 좌표 구현에 따른 오프셋 적용
cameraed = (
upscaled[0] + CONFIG.camera_x,
Expand Down
26 changes: 15 additions & 11 deletions components/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class Text:
< : 줄바꿈 (New Line)
"""

FONT = Fonts.TITLE2
PT = 18

SYNTAX: dict[str, tuple[Font, int]] = {
"*": (Fonts.TITLE3, PT),
"#": (Fonts.TITLE2, PT + 4),
"/": (Fonts.DIALOG, PT - 4)
}

def __init__(self, text: str, delay: Optional[int] = 30):
"""
Text 클래스를 생성합니다.
Expand Down Expand Up @@ -93,19 +102,14 @@ def write(
ch_x = char_position[0]
ch_y = char_position[1]

font = Fonts.DIALOG
pt = 15
font = Text.FONT
pt = Text.PT
px = 0

match mutual.prefix: # 접두어별 맞는 폰트 지정
case "*":
font = Fonts.TITLE3
case "#":
font = Fonts.TITLE2
pt += 2
case "/":
font = Fonts.TITLE2
pt -= 3
if mutual.prefix in Text.SYNTAX: # 접두어별 맞는 폰트 지정
syntax = Text.SYNTAX[mutual.prefix]
font = syntax[0]
pt = syntax[1]

px = pt / 3.0 * 4.0 # pt를 픽셀로 변환
chs = mutual.text[index] # 문자
Expand Down
10 changes: 4 additions & 6 deletions components/text/text_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ def __init__(
self.textList = []
self.position = pos

pt = 15 # 폰트 단위
pt = Text.PT # 폰트 단위
text_width = 0.0 # 현재 텍스트 너비
modified_text = "" # 줄바꿈이 들어간 텍스트

for text in texts: # Text
for mutual in text.texts: # Mutual Text
match mutual.prefix: # 접두어
case "#":
pt += 2
case "/":
pt -= 3
if mutual.prefix in Text.SYNTAX: # 접두어별 맞는 폰트 지정
syntax = Text.SYNTAX[mutual.prefix]
pt = syntax[1]

px = pt / 3.0 * 4.0 # pt를 픽셀로 변환

Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def main():
CONFIG.is_fullscreen = True

if args.fullhd: # FHD (1920x1080)
CONFIG.window_size = (1920, 1080)
CONFIG.window_scale = 3
CONFIG.window_size = [1920, 1080]
CONFIG.window_scale = 2

update_screen_resolution() # 화면 해상도 업데이트

elif args.quadhd: # QHD (2560x1440)
CONFIG.window_size = (2560, 1440)
CONFIG.window_scale = 4
CONFIG.window_size = [2560, 1440]
CONFIG.window_scale = 2.6666

update_screen_resolution() # 화면 해상도 업데이트

Expand Down
3 changes: 1 addition & 2 deletions maps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def render(self, frame_count: int):
맵을 렌더링합니다.
:param frame_count: 1초 당 누적되는 프레임 렌더링하는 개수 (범위: 0~10)
"""
self.background.set_pos(CONFIG.camera_x, self.background.y)
#self.background.set_pos(CONFIG.camera_x // 1.1, self.background.y) # 조금씩 움직이게 하고 싶어요
self.background.set_pos(CONFIG.camera_x, self.background.y)

CONFIG.surface.blit(self.background.image.convert(), self.background.get_pos())
CONFIG.surface.blit(self.floor.image, self.floor.get_pos())
Expand Down
12 changes: 6 additions & 6 deletions maps/map_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, player: Player, sign):
# NPC
self.sign = sign

self.emilia = Player("assets/images/chr_emilia.png", (400, 210), 0.4) # 에밀리아
self.emilia = Player("assets/images/chr_emilia.png", (400, 360), 0.4) # 에밀리아
self.emilia.dialog = TextCollection(
[
Text("*안녕!*"),
Expand All @@ -37,7 +37,7 @@ def __init__(self, player: Player, sign):
self.NPCs = [self.emilia]

# 적
self.enemy = Enemy("assets/images/chr_raon.png", (1000, 237), 0.4)
self.enemy = Enemy("assets/images/chr_raon.png", (1000, 387), 0.4)
self.enemies = [self.enemy]

for enemy in self.enemies:
Expand All @@ -53,7 +53,7 @@ def __init__(self, player: Player, sign):
)
},
"default",
position=(800, 285),
position=(800, 435),
scale=0.4))

self.spike2 = Player.get_from_sprite(SpriteCollection({
Expand All @@ -64,11 +64,11 @@ def __init__(self, player: Player, sign):
)
},
"default",
position=(850, 285),
position=(850, 435),
scale=0.4))

self.obstacles = [self.spike, self.spike2]

# 배경
self.background = Texture("assets/images/background_main_edited.png", (0, 0), 1, repeat_x=2, fit=True)
self.floor = Texture("assets/images/grass.png", (0, 320), 0.4, repeat_x=2)
self.background = Texture("assets/images/background_main.png", (0, 0), 1, repeat_x=2, fit=True)
self.floor = Texture("assets/images/grass.png", (0, 470), 0.5, repeat_x=2)
44 changes: 44 additions & 0 deletions maps/map_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from maps import Map

from characters.player import Player
from characters.enemy import Enemy
from characters.texture import Texture

from components.events.grace_period import GracePeriod
from components.events.text import TextEvent

from components.text import Text
from components.text.text_collection import TextCollection

from components.sprites.sprite import Sprite
from components.sprites.sprite_handler import SpriteHandler
from components.sprites.sprite_collection import SpriteCollection

class MapTest(Map):
def __init__(self, player: Player, sign):
super(Map, self).__init__()

self.player = player

# # NPC
# self.sign = sign

# self.emilia = Player("assets/images/chr_emilia.png", (400, 193), 0.4) # 에밀리아
# self.emilia.dialog = TextCollection(
# [
# Text("#이 쪽으로 잘 왔구나!#"),
# Text("여기는 훈련장이야."),
# Text("쭉 가면 적이 출몰할거야!"),
# Text("적은 *J키*로 공격할 수 있으니 참고하라구!")
# ],
# self.sign.width
# )

self.NPCs = []

self.obstacles = []
self.enemies = []

# 배경
self.background = Texture("assets/images/background_main.png", (0, 0), 1, repeat_x=2, fit=True)
self.floor = Texture("assets/images/ground.png", (0, 320), 0.4, repeat_x=2)
4 changes: 2 additions & 2 deletions maps/map_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, player: Player, sign):
# NPC
self.sign = sign

self.emilia = Player("assets/images/chr_emilia.png", (400, 193), 0.4) # 에밀리아
self.emilia = Player("assets/images/chr_emilia.png", (400, 375), 0.4) # 에밀리아
self.emilia.dialog = TextCollection(
[
Text("#이 쪽으로 잘 왔구나!#"),
Expand All @@ -41,4 +41,4 @@ def __init__(self, player: Player, sign):

# 배경
self.background = Texture("assets/images/background_training.png", (0, 0), 1, repeat_x=2, fit=True)
self.floor = Texture("assets/images/ground_temp.png", (0, 320), 0.4, repeat_x=2)
self.floor = Texture("assets/images/ground_temp.png", (0, 482), 0.6, repeat_x=2)
26 changes: 14 additions & 12 deletions screens/ingame.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from maps.map_main import MapMain
from maps.map_training import MapTraining
from maps.map_test import MapTest
from maps.map_manager import MapManager

from screens.pause_menu import update_pause_menu
Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(self):
))
},
"stay",
position=(200, 197),
position=(200, 347),
scale=0.4,
),
True,
Expand All @@ -75,7 +76,7 @@ def __init__(self):
scale=0.6)

# 기타 아이템
self.sign = Texture("assets/images/sign_big.png", (300, 100), 0.3)
self.sign = Texture("assets/images/sign_big.png", (300, 100), 0.4)
self.hp = SpriteCollection({
"attacked": SpriteHandler(
Sprite(
Expand All @@ -88,7 +89,7 @@ def __init__(self):
},
"attacked",
position=(0, 0),
scale=0.4
scale=0.6
)

def update_ingame(self):
Expand Down Expand Up @@ -184,7 +185,8 @@ def process_ingame(event: pygame.event.Event):

MapManager.maps = {
"main": MapMain(self.player, self.sign),
"training": MapTraining(self.player, self.sign)
"training": MapTraining(self.player, self.sign),
"test": MapTest(self.player, self.sign)
}
MapManager.apply("main")

Expand Down Expand Up @@ -274,7 +276,7 @@ def process_ingame(event: pygame.event.Event):
self.dead_background = pygame.transform.scale(
self.dead_background,
(
self.dead_background.get_width() + 20,
self.dead_background.get_width() + 60,
self.dead_background.get_height() - 20,
),
)
Expand All @@ -294,7 +296,7 @@ def process_ingame(event: pygame.event.Event):

self.button_retry = Button(
image=button_retry_image,
pos=(320, 220),
pos=(480, 225),
text_input="재도전",
font=Font(Fonts.TITLE2, 30).to_pygame(),
base_color="#ffffff",
Expand All @@ -311,16 +313,16 @@ def process_ingame(event: pygame.event.Event):

self.button_menu = Button(
image=button_menu_image,
pos=(320, 280),
pos=(480, 280),
text_input="메뉴 화면으로",
font=Font(Fonts.TITLE2, 30).to_pygame(),
base_color="#ffffff",
hovering_color="White",
)

CONFIG.surface.blit(self.dead_background, (180 + CONFIG.camera_x, 120 + CONFIG.camera_y))
CONFIG.surface.blit(self.dead_background, (320 + CONFIG.camera_x, 120 + CONFIG.camera_y))
CONFIG.surface.blit(
self.dead_text, self.dead_text.get_rect(center=(320 + CONFIG.camera_x, 160 + CONFIG.camera_y))
self.dead_text, self.dead_text.get_rect(center=(483 + CONFIG.camera_x, 160 + CONFIG.camera_y))
)

for button in [self.button_retry, self.button_menu]:
Expand All @@ -336,9 +338,9 @@ def process_ingame(event: pygame.event.Event):
# region FPS 표시
if CONFIG.game_fps:
fps = round(CONFIG.clock.get_fps(), 1)
fps_text = Font(Fonts.TITLE3, 20).render(str(fps), (255, 255, 255))
fps_text = Font(Fonts.TITLE3, 32).render(str(fps), CONST.COL_WHITE)

CONFIG.surface.blit(fps_text, (585 + CONFIG.camera_x, 10 + CONFIG.camera_y))
CONFIG.surface.blit(fps_text, (870 + CONFIG.camera_x, 15 + CONFIG.camera_y))
# endregion

CONFIG.update_screen()
Expand All @@ -350,7 +352,7 @@ def process_ingame(event: pygame.event.Event):
TextEvent.NPC = None
TextEvent.dialog = None

self.player.set_pos(200, 225)
self.player.set_pos(200, 375)

CONFIG.game_dead = False
CONFIG.camera_x = 0
Expand Down
8 changes: 4 additions & 4 deletions screens/intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def update():
))
},
"walk",
position=(-250, 320),
position=(-250, 480),
scale=0.4,
)
)
Expand Down Expand Up @@ -74,11 +74,11 @@ def update():
count = 0
player_icon.sprites.get_sprite_handler().sprite.update() # 스프라이트 애니메이션 업데이트

player_icon.move_x(0.8) # 0.8의 속도만큼 X 좌표로 움직임
player_icon.move_x(1.2) # 1.2의 속도만큼 X 좌표로 이동
player_icon.render() # 렌더링

title = Font(Fonts.TITLE3, 40).render(text, CONST.COL_WHITE) # 로고 폰트 렌더링
title_rect = title.get_rect(center=(320, 180)) # 로고의 좌표 & 크기 (Rect) 가져오기
title = Font(Fonts.TITLE3, 60).render(text, CONST.COL_WHITE) # 로고 폰트 렌더링
title_rect = title.get_rect(center=(480, 270)) # 로고의 좌표 & 크기 (Rect) 가져오기

CONFIG.surface.blit(title, title_rect) # 로고를 화면에 렌더링
CONFIG.update_screen() # 업스케일링
Expand Down
Loading

0 comments on commit 92f2311

Please sign in to comment.