From 6bf5bc8144dd74df51b410628b1db9cdbc39ad36 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Mon, 17 Nov 2025 17:34:11 +0300 Subject: [PATCH] Fixed some bugs --- game/entities/other/blast.gd | 19 ++++++++++--------- game/entities/ships/abstract_ship.tscn | 2 ++ .../ships/enemies/abstract_enemy_ship.tscn | 1 - .../ships/enemies/heavy/heavy_enemy_ship.tscn | 5 +++-- .../enemies/medium/medium_enemy_ship.tscn | 4 +--- .../ships/enemies/small/small_enemy_ship.tscn | 5 +++-- game/entities/ships/player/player_ship.tscn | 1 - game/passage.gd | 4 ++-- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/game/entities/other/blast.gd b/game/entities/other/blast.gd index 6606bde..a9cd8d6 100644 --- a/game/entities/other/blast.gd +++ b/game/entities/other/blast.gd @@ -29,19 +29,20 @@ func get_damage_to(body: Node2D) -> AbstractDamage: func _get_distance_to(body: Node2D) -> float: if not shape: return INF + var space_state := get_world_2d().direct_space_state + var query := PhysicsShapeQueryParameters2D.new() + var circle_shape := CircleShape2D.new() + query.shape = circle_shape + query.transform = Transform2D(0, global_position) + query.collide_with_areas = false + query.collide_with_bodies = true + query.collision_mask = collision_mask + query.exclude = [self] + #TODO optimize by binary search for radius in range(shape.radius + 1): - var query := PhysicsShapeQueryParameters2D.new() - var circle_shape := CircleShape2D.new() circle_shape.radius = radius - query.shape = circle_shape - query.transform = Transform2D(0, global_position) - query.collide_with_areas = false - query.collide_with_bodies = true - query.collision_mask = collision_mask - query.exclude = [self] - var space_state := get_world_2d().direct_space_state var results := space_state.intersect_shape(query) for result in results: diff --git a/game/entities/ships/abstract_ship.tscn b/game/entities/ships/abstract_ship.tscn index 5d3839b..dd7a69c 100644 --- a/game/entities/ships/abstract_ship.tscn +++ b/game/entities/ships/abstract_ship.tscn @@ -21,3 +21,5 @@ shape = SubResource("CircleShape2D_xxtvk") [node name="HeathBar" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_l62e5")] health = NodePath("../Health") + +[connection signal="depleted" from="Health" to="." method="_on_health_depleted"] diff --git a/game/entities/ships/enemies/abstract_enemy_ship.tscn b/game/entities/ships/enemies/abstract_enemy_ship.tscn index 7076e0b..b0d6800 100644 --- a/game/entities/ships/enemies/abstract_enemy_ship.tscn +++ b/game/entities/ships/enemies/abstract_enemy_ship.tscn @@ -11,7 +11,6 @@ script = ExtResource("2_fwvrd") [node name="EnemyController" parent="." index="4" instance=ExtResource("3_l8c0n")] -[connection signal="depleted" from="Health" to="." method="_on_health_depleted"] [connection signal="accelerate" from="EnemyController" to="." method="accelerate"] [connection signal="reload" from="EnemyController" to="." method="reload"] [connection signal="shoot" from="EnemyController" to="." method="shoot"] diff --git a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn index bf398c1..d72c885 100644 --- a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn +++ b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn @@ -27,5 +27,6 @@ shape = SubResource("CapsuleShape2D_cuapu") [node name="Health" parent="." index="2"] max_hull = 200 -[node name="HeathBar" parent="." index="4"] -position = Vector2(0, 30) +[node name="HeathBar" parent="." index="3"] +offset_top = 30.0 +offset_bottom = 30.0 diff --git a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn index dc7d9b9..212c16a 100644 --- a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn +++ b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn @@ -26,8 +26,6 @@ shape = SubResource("CapsuleShape2D_4jmkv") [node name="Health" parent="." index="2"] max_hull = 100 -[node name="HeathBar" parent="." index="4"] +[node name="HeathBar" parent="." index="3"] offset_top = 30.0 offset_bottom = 30.0 - -[connection signal="depleted" from="Health" to="." method="_on_health_depleted"] diff --git a/game/entities/ships/enemies/small/small_enemy_ship.tscn b/game/entities/ships/enemies/small/small_enemy_ship.tscn index 56a360f..e823d33 100644 --- a/game/entities/ships/enemies/small/small_enemy_ship.tscn +++ b/game/entities/ships/enemies/small/small_enemy_ship.tscn @@ -26,5 +26,6 @@ shape = SubResource("CapsuleShape2D_lopve") [node name="Health" parent="." index="2"] max_hull = 50 -[node name="HeathBar" parent="." index="4"] -position = Vector2(0, 14) +[node name="HeathBar" parent="." index="3"] +offset_top = 14.0 +offset_bottom = 14.0 diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index f834e23..08cb723 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -37,7 +37,6 @@ offset_bottom = 22.0 [node name="PlayerController" parent="." index="4" instance=ExtResource("3_4mjo1")] -[connection signal="depleted" from="Health" to="." method="_on_health_depleted"] [connection signal="accelerate" from="PlayerController" to="." method="accelerate"] [connection signal="reload" from="PlayerController" to="." method="reload"] [connection signal="shoot" from="PlayerController" to="." method="shoot"] diff --git a/game/passage.gd b/game/passage.gd index b4b3ace..e644e54 100644 --- a/game/passage.gd +++ b/game/passage.gd @@ -17,7 +17,7 @@ func _create_player() -> void: var player : PlayerShip = PLAYER.instantiate() add_child(player) player.position = Vector2(100, 100) - player.destroyed.connect(_create_player) + player.destroyed.connect(_create_player, CONNECT_DEFERRED) func _create_random_enemy() -> void: @@ -26,4 +26,4 @@ func _create_random_enemy() -> void: var enemy : AbstractEnemyShip = ENEMIES.pick_random().instantiate() add_child(enemy) enemy.position = Vector2(550, 180) - enemy.destroyed.connect(_create_random_enemy) + enemy.destroyed.connect(_create_random_enemy, CONNECT_DEFERRED)