diff --git a/game/entities/other/blast.gd b/game/entities/other/blast.gd index f356f40..6606bde 100644 --- a/game/entities/other/blast.gd +++ b/game/entities/other/blast.gd @@ -22,13 +22,33 @@ func get_damage_to(body: Node2D) -> AbstractDamage: var damage_dub := damage.duplicate() var factor := _get_damage_factor(distance) - damage_dub.value = damage_dub.value * factor - + damage_dub.value = round(damage_dub.value * factor) return damage_dub func _get_distance_to(body: Node2D) -> float: - return global_position.distance_to(body.global_position) + if not shape: return INF + + #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: + if result["collider"] == body: + return radius + + return INF func _get_damage_factor(distance: float) -> float: