summaryrefslogtreecommitdiff
path: root/ball.gd
diff options
context:
space:
mode:
Diffstat (limited to 'ball.gd')
-rw-r--r--ball.gd35
1 files changed, 35 insertions, 0 deletions
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