diff --git a/README.md b/README.md index 91b938d..bcc57b9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # godot_snake_game +## Resources +- https://opengameart.org/ +- https://kenney.nl/ diff --git a/Scripts/Body.gd b/Scripts/Body.gd index 516a5bb..aee99e5 100644 --- a/Scripts/Body.gd +++ b/Scripts/Body.gd @@ -9,7 +9,7 @@ var scale_tween: Tween = null # 씬 트리 진입 func _enter_tree() -> void: - self.set_multiplayer_authority(peer_id) + self.set_multiplayer_authority(self.peer_id) # 몸체 초기화 func initialize(player_peer_id: int, fill_color: Color, outline_color: Color, location: Vector2, is_first_body: bool) -> void: @@ -18,13 +18,14 @@ func initialize(player_peer_id: int, fill_color: Color, outline_color: Color, lo $Outline.modulate = outline_color self.global_position = location + # 처음 추가되는 몸체가 아닐경우에만 충돌체를 추가한다. if is_first_body == false: var collision = BODY_COLLISION_TEMPLATE.instantiate() self.add_child.call_deferred(collision, true) # 몸체 크기 조정 애니메이션 처리 func change_body_scale(target_scale: Vector2) -> void: - if scale_tween: - scale_tween.kill() - scale_tween = get_tree().create_tween() - scale_tween.tween_property(self, "scale", target_scale, 0.1) + if self.scale_tween: + self.scale_tween.kill() + self.scale_tween = get_tree().create_tween() + self.scale_tween.tween_property(self, "scale", target_scale, 0.1) diff --git a/Scripts/BodySpawner.gd b/Scripts/BodySpawner.gd index 49335f1..38763de 100644 --- a/Scripts/BodySpawner.gd +++ b/Scripts/BodySpawner.gd @@ -4,37 +4,40 @@ extends MultiplayerSpawner const BODY_TEMPLATE = preload("res://Scenes/Templates/body.tscn") var player: Player = null +# 시작 func _ready() -> void: self.spawn_function = self._spawn_body +# 몸체 스폰 함수 func _spawn_body(spawn_data: Dictionary) -> Node: var peer_id: int = spawn_data["peer_id"] var is_paused: bool = spawn_data["is_paused"] # 생성 위치 계산 - var last_body: Node2D = player.body_list.back() + var last_body: Node2D = self.player.body_list.back() var last_body_front: Vector2 = last_body.global_transform.x var body_location: Vector2 = last_body.global_position + (-last_body_front * 32 / last_body.scale) - var is_first_body: bool = player.get_node("Head") == last_body + # 처음 추가되는 몸체인지 판별 여부 + var is_first_body: bool = self.player.get_node("Head") == last_body var body: Body = BODY_TEMPLATE.instantiate() - body.name = player.name + "_Body_" + str(player.body_list.size()) - body.initialize(peer_id, player.get_node("Head/Face").modulate, player.get_node("Head/FaceOutline").modulate, body_location, is_first_body) + body.name = self.player.name + "_Body_" + str(self.player.body_list.size()) + body.initialize(peer_id, self.player.get_node("Head/Face").modulate, self.player.get_node("Head/FaceOutline").modulate, body_location, is_first_body) body.look_at(last_body.global_position) - player.body_list.append(body) + self.player.body_list.append(body) # FollowComponent 목표 객체 설정 var follow_Component: FollowComponent = body.get_node("FollowComponent") follow_Component.follow_target = last_body - follow_Component.player = player + follow_Component.player = self.player if is_paused: follow_Component.process_mode = Node.PROCESS_MODE_DISABLED else: follow_Component.process_mode = Node.PROCESS_MODE_INHERIT - player.marking_component.on_marking.connect(follow_Component.update_target_position) - player.marking_component.on_marking.emit() + self.player.marking_component.on_marking.connect(follow_Component.update_target_position) + self.player.marking_component.on_marking.emit() return body diff --git a/Scripts/BrowserItem.gd b/Scripts/BrowserItem.gd index 622bae4..de52870 100644 --- a/Scripts/BrowserItem.gd +++ b/Scripts/BrowserItem.gd @@ -8,12 +8,12 @@ var server_data: Dictionary = {} # 초기화 func initialize(server_ip: String, server_name: String, gameplay_port: int) -> void: - server_data["ip"] = server_ip - server_data["server_name"] = server_name - server_data["gameplay_port"] = gameplay_port + self.server_data["ip"] = server_ip + self.server_data["server_name"] = server_name + self.server_data["gameplay_port"] = gameplay_port $ServerName.text = server_name # Join버튼 클릭 func _on_btn_join_pressed() -> void: - on_btn_join_pressed.emit(server_data) + self.on_btn_join_pressed.emit(self.server_data) diff --git a/Scripts/FlipComponent.gd b/Scripts/FlipComponent.gd index 9dfe635..dd0edc2 100644 --- a/Scripts/FlipComponent.gd +++ b/Scripts/FlipComponent.gd @@ -5,8 +5,10 @@ class_name FlipComponent @export var target: Node2D @export var target_sprites: Array[Sprite2D] +# 업데이트 func _process(_delta: float) -> void: if target != null: + # 방향에 따라 스프라이트 Flip 설정 var direction = target.global_transform.x var is_flip_v = Vector2.RIGHT.dot(direction) < 0.0 for sprite in target_sprites: diff --git a/Scripts/SFXManager.gd b/Scripts/SFXManager.gd index 2f8b0e4..4c60d37 100644 --- a/Scripts/SFXManager.gd +++ b/Scripts/SFXManager.gd @@ -1,3 +1,4 @@ +# SFXManager.gd extends Node const CLICK_SFX = preload("res://Scenes/SFX/click.tscn")