From a81c6b9afd8500c49398c4cc4f11a30cc583261a Mon Sep 17 00:00:00 2001 From: Just Dzhi Date: Sun, 1 Oct 2023 02:10:12 +0400 Subject: [PATCH] TODO pick nearest target --- project.godot | 12 +----------- src/models/player/player.gd | 10 ++++++++++ src/scenes/game/Game.tscn | 6 +++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/project.godot b/project.godot index 1807714..174b355 100644 --- a/project.godot +++ b/project.godot @@ -8,16 +8,6 @@ config_version=4 -_global_script_classes=[ { -"base": "EditorVCSInterface", -"class": "GitAPI", -"language": "NativeScript", -"path": "res://addons/godot-git-plugin/git_api.gdns" -} ] -_global_script_class_icons={ -"GitAPI": "" -} - [application] config/name="LD54" @@ -49,7 +39,7 @@ version_control_plugin_name="GitAPI" [gdnative] -singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ] +singletons=[ ] [global] diff --git a/src/models/player/player.gd b/src/models/player/player.gd index b11928c..2464bdc 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -24,3 +24,13 @@ func area_exited(area): func _physics_process(_delta): get_input() velocity = move_and_slide(velocity * speed_multiplier) + _choose_target() + +func _choose_target(): + var enemies = get_tree().get_nodes_in_group("enemy") + enemies.sort_custom(self, "_sort") + for enemy in enemies: + enemies.front().scale.x = 1 #TODO + +func _sort(a, b): + return a.position < b.position diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 9dcac09..4784134 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -72,11 +72,15 @@ shape = SubResource( 3 ) [node name="Enemies" type="Node2D" parent="View"] -[node name="TrashCan" parent="View/Enemies" instance=ExtResource( 13 )] +[node name="TrashCan" parent="View/Enemies" groups=["enemy"] instance=ExtResource( 13 )] [node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )] z_index = 1 +[node name="Bat2" parent="View/Enemies" instance=ExtResource( 14 )] +position = Vector2( 142, 54 ) +z_index = 1 + [node name="Player" parent="View" instance=ExtResource( 5 )] position = Vector2( 46, 42 ) z_index = 1