From 5469cf7b6da512e48f3d614704e51cfdd6966f08 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 27 Apr 2025 13:44:22 +0200 Subject: initial commit --- ball.gd | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ball.gd (limited to 'ball.gd') diff --git a/ball.gd b/ball.gd new file mode 100644 index 0000000..d9037a8 --- /dev/null +++ b/ball.gd @@ -0,0 +1,35 @@ +extends RigidBody2D + + +var reset_state := false +var target_vector := Vector2.ZERO + +var collision_buffer: Array + + +func _integrate_forces(state: PhysicsDirectBodyState2D) -> void: + if reset_state: + reset_state = false + state.transform = Transform2D(0.0, target_vector) + + for idx in state.get_contact_count(): + var body := state.get_contact_collider_object(idx) + + if body.is_in_group("bumper"): + body.animate_bump() + apply_central_impulse( + state.get_contact_local_normal(idx) * + body.get_impulse() + ) + + if not collision_buffer.has(body): + collision_buffer.append(body) + get_tree().current_scene.get_node("HUD").score += 50 + + if state.get_contact_count() == 0: + collision_buffer.clear() + + +func move_body(target_position: Vector2) -> void: + target_vector = target_position + reset_state = true -- cgit v1.2.3