Skip to content

Commit

Permalink
월드 분리 및 체력 안뒤지는 버그 수정
Browse files Browse the repository at this point in the history
Co-authored-by: AkiaCode <AkiaCode@users.noreply.github.com>
  • Loading branch information
MineEric64 and AkiaCode committed Aug 26, 2023
1 parent b870e3f commit 179f717
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 30 deletions.
3 changes: 3 additions & 0 deletions characters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Character(ABC):
is_air = False
"""플레이어가 공중에 떠 있는가?"""

dialog: TextCollection = None
"""현재 플레이어/NPC의 대화"""

sign = None
"""말풍선"""

Expand Down
3 changes: 2 additions & 1 deletion components/events/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TextEvent(object):
dialog_closed = True
"""대화창 텍스트가 닫혀있는가?"""

dialog: TextCollection
dialog: TextCollection = None
"""대화창 (Text 배열)"""

@classmethod
Expand All @@ -36,6 +36,7 @@ def process_next_event(cls):
cls.dialog_paused = False # 텍스트 출력 미완성

else: # 대화창의 텍스트가 더이상 없을 때
cls.dialog = None
cls.dialog_closed = True # 대화창 닫힘
cls.dialog_paused = True # 텍스트 출력 완성

Expand Down
62 changes: 59 additions & 3 deletions maps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
class Maps:
def __init__():
pass
from characters.player import Player
from characters.enemy import Enemy
from characters.texture import Texture

class Map:
player: Player
"""플레이어"""

NPCs: list[Player]
"""NPC 배열"""

enemies: list[Enemy]
"""적 배열"""

obstacles: list[Player]
"""장애물 배열"""

sign = None
"""말풍선"""

background: Texture
"""배경"""

floor: Texture
"""바닥"""

def __init__(
self,
player: Player = None,
NPCs: list[Player] = [],
enemies: list[Enemy] = [],
obstacles: list[Player] = [],
sign = None,
background: Texture = None,
floor: Texture = None
):
"""
맵 클래스를 생성합니다.
:param player: 현재 플레이어
:param npcs: NPC 배열
:param enemies: 적 배열
:param obstacles: 장애물 배열
:param background: 배경
:param floor: 바닥
"""
self.player = player
self.NPCs = NPCs
self.enemies = enemies
self.obstacles = obstacles
self.sign = sign
self.background = background
self.floor = floor

def render(self):
"""맵을 렌더링합니다."""
pass

def __str__(self):
return f"<Map Player={self.player}>"
4 changes: 0 additions & 4 deletions maps/__test__.py

This file was deleted.

74 changes: 74 additions & 0 deletions maps/map_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 MapMain(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, 195), 0.4) # 에밀리아
self.emilia.dialog = TextCollection(
[
Text("*안녕!*"),
Text("나는 에밀리아야."),
Text("*J키*는 #기본공격#이야!"),
Text("그럼 즐거운 여행되길 바래!")
],
self.sign.width
)

self.NPCs = [self.emilia]

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

for enemy in self.enemies:
enemy.grace_period = GracePeriod(1500)
enemy.hp = 2

# 장애물
self.spike = Player.get_from_sprite(SpriteCollection({
"default": SpriteHandler(
Sprite(
"assets/images/object_spike_default.png", 17, 1, size=(155, 100)
)
)
},
"default",
position=(800, 270),
scale=0.4))

self.spike2 = Player.get_from_sprite(SpriteCollection({
"default": SpriteHandler(
Sprite(
"assets/images/object_spike_default.png", 17, 1, size=(155, 100)
)
)
},
"default",
position=(850, 270),
scale=0.4))

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

# 배경
self.background = Texture("assets/images/background_sky.png", (0, 0), 1, repeat_x=2, fit=True)
self.ground = Texture("assets/images/grass.png", (0, 287), 0.4, repeat_x=2)
21 changes: 21 additions & 0 deletions maps/map_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from characters.player import Player

from maps import Map
from maps.map_main import MapMain

class MapManager:
"""플레이어가 다니는 맵을 관리합니다."""

maps: dict[str, Map] = {}

current: Map = None
"""현재 맵"""

@classmethod
def apply(cls, map: str):
"""
맵을 적용합니다.
:param map: 적용할 맵
"""

cls.current = cls.maps[map]
56 changes: 34 additions & 22 deletions screens/ingame.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from components.sprites.sprite_handler import SpriteHandler
from components.sprites.sprite import Sprite

from maps.map_main import MapMain
from maps.map_manager import MapManager

from screens.pause_menu import update_pause_menu


Expand Down Expand Up @@ -156,21 +159,29 @@ def process_ingame(event: pygame.event.Event):
if CONFIG.is_interactive():
match event.key:
case pygame.K_SPACE | pygame.K_w | pygame.K_UP:
if self.emilia.is_bound(80, 80):
TextEvent.process_next_event()
speeched = False

for npc in MapManager.current.NPCs:
if npc.is_bound(80, 80):
if TextEvent.dialog is None and npc.dialog is not None:
TextEvent.dialog = npc.dialog

if TextEvent.dialog is not None:
TextEvent.process_next_event()

if TextEvent.dialog_delayed:
self.sign.refresh()
if TextEvent.dialog_delayed:
self.sign.refresh()

if not TextEvent.dialog_closed:
pygame.time.set_timer(CONST.PYGAME_EVENT_DIALOG, 1, 1)
if not TextEvent.dialog_closed:
pygame.time.set_timer(CONST.PYGAME_EVENT_DIALOG, 1, 1)

# 주인공 애니메이션 기본으로 설정
self.player.sprites.status = "stay"
# 주인공 애니메이션 기본으로 설정
MapManager.current.player.sprites.status = "stay"

else:
if not self.player.is_air: # 다중 점프 금지
self.player.move_y(13) # 점프
speeched = True

if TextEvent.dialog_closed and not MapManager.current.player.is_air and not speeched: # 다중 점프 금지
MapManager.current.player.move_y(13) # 점프

case pygame.K_j: # 기본 공격
self.player.attack = True
Expand Down Expand Up @@ -205,15 +216,10 @@ def process_ingame(event: pygame.event.Event):
if self.button_menu.check_for_input(self.mouse_pos): # 메뉴화면으로 나가기
self.need_to_exit = True

TextEvent.dialog = TextCollection(
[
Text("*안녕!*"),
Text("나는 에밀리아야."),
Text("*J키*는 #기본공격#이야!"),
Text("그럼 즐거운 여행되길 바래!")
],
self.sign.width
)
MapManager.maps = {
"main": MapMain(self.player, self.sign)
}
MapManager.apply("main")

count = 0

Expand Down Expand Up @@ -278,7 +284,10 @@ def process_ingame(event: pygame.event.Event):
World.process_gravity(self.enemies + [self.player], 305) # 중력 구현
# endregion

self.process_hp_event(hp_attacked_index, hp_healed_index)
# hp 이벤트 처리 후 hp 애니메이션 index 변수 갱신
hp_indicies = self.process_hp_event(hp_attacked_index, hp_healed_index)
hp_attacked_index = hp_indicies[0]
hp_healed_index = hp_indicies[1]

# 무적 시간
for player in self.enemies + [self.player]:
Expand Down Expand Up @@ -446,11 +455,12 @@ def process_ingame(event: pygame.event.Event):
pygame.mixer.unpause()

# region 체력
def process_hp_event(self, hp_attacked_index: int, hp_healed_index: int):
def process_hp_event(self, hp_attacked_index: int, hp_healed_index: int) -> tuple[int, int]:
"""
체력 관련 이벤트를 처리합니다.
:param hp_attacked_index: hp 공격받은 애니메이션 현재 index
:param hp_healed_index: hp 회복하는 애니메이션 현재 index
:return: 갱신해야할 hp 애니메이션 index 변수 2개
"""
self.hp.get_sprite_handler().group.draw(CONFIG.surface)

Expand Down Expand Up @@ -491,6 +501,8 @@ def process_hp_event(self, hp_attacked_index: int, hp_healed_index: int):

self.player.healed = False # 회복 여부 변수 초기화

return (hp_attacked_index, hp_healed_index)

def process_hp_animation(self, hp_attacked_index: int, hp_healed_index: int):
"""
체력 관련 애니메이션을 처리합니다.
Expand Down

0 comments on commit 179f717

Please sign in to comment.