From 3a4b647df597fc10400e421cbd08c3c4eb2a3b18 Mon Sep 17 00:00:00 2001 From: Just Dzhi Date: Sat, 30 Sep 2023 23:57:58 +0400 Subject: [PATCH] Bat --- project.godot | 12 +----------- src/models/enemies/bat/bat.gd | 11 ++++++++++- src/scenes/game/Game.tscn | 6 +++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/project.godot b/project.godot index 61c5cb7..e759724 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" @@ -48,7 +38,7 @@ version_control_plugin_name="GitAPI" [gdnative] -singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ] +singletons=[ ] [global] diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index fc91a9f..acb41bf 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -12,6 +12,15 @@ func _physics_process(_delta): velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8))) else: velocity = Vector2.ZERO - + + if abs($"../Player".velocity.x) > 0 and position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 48: + velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + + if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 32: + velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180) + + move_and_slide(velocity) diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 496c123..c3c9252 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] @@ -12,6 +12,7 @@ [ext_resource path="res://icon.png" type="Texture" id=10] [ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11] [ext_resource path="res://src/scenes/game/sprites/ui_background.png" type="Texture" id=12] +[ext_resource path="res://src/models/enemies/bat/Bat.tscn" type="PackedScene" id=13] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) @@ -69,6 +70,9 @@ shape = SubResource( 3 ) [node name="Player" parent="View" instance=ExtResource( 5 )] position = Vector2( 46, 42 ) +[node name="Bat" parent="View" instance=ExtResource( 13 )] +position = Vector2( 87, 40 ) + [node name="UI" type="Control" parent="."] margin_right = 40.0 margin_bottom = 40.0