|
@@ -1,18 +1,12 @@
|
|
|
class_name Ball
|
|
|
extends RigidBody2D
|
|
|
|
|
|
-export (Color) var interrupt_color = Color.white
|
|
|
-
|
|
|
|
|
|
-signal kace_contact
|
|
|
+export (Color) var interrupt_color = Color.white
|
|
|
|
|
|
|
|
|
-const brick_layer = 2
|
|
|
-const interrupt_speed = 700
|
|
|
-const cell_size = Vector2(20, 10)
|
|
|
-const max_penetration = 1.0
|
|
|
-const contact_corrector = cell_size - Vector2(max_penetration, max_penetration)
|
|
|
-const redundant_ceil = 0.9 # 0.5 < x < 1.0
|
|
|
+const BRICK_LAYER = 2
|
|
|
+const INTERRUPT_SPEED = 700
|
|
|
|
|
|
|
|
|
var last_normal:Vector2 = Vector2(0.0, 0.0)
|
|
@@ -24,24 +18,9 @@ func interrupt_ball():
|
|
|
|
|
|
|
|
|
func go_down_unstopped():
|
|
|
- linear_velocity.y = interrupt_speed
|
|
|
- linear_velocity = linear_velocity.normalized() * interrupt_speed
|
|
|
- set_collision_mask_bit(brick_layer, false)
|
|
|
-
|
|
|
-
|
|
|
-func filter_new_contact(new_normal):
|
|
|
- var is_new_contact = last_normal.dot(new_normal) < redundant_ceil
|
|
|
- last_normal = new_normal
|
|
|
- return is_new_contact
|
|
|
-
|
|
|
-
|
|
|
-func _integrate_forces(state : Physics2DDirectBodyState):
|
|
|
- for i in range(state.get_contact_count()):
|
|
|
- var contact_normal = state.get_contact_local_normal(i)
|
|
|
- if filter_new_contact(contact_normal):
|
|
|
- var contact_pos = state.get_contact_local_position(i)
|
|
|
- var correct_pos = contact_pos - contact_normal * contact_corrector
|
|
|
- emit_signal("kace_contact", correct_pos)
|
|
|
+ linear_velocity.y = INTERRUPT_SPEED
|
|
|
+ linear_velocity = linear_velocity.normalized() * INTERRUPT_SPEED
|
|
|
+ set_collision_mask_bit(BRICK_LAYER, false)
|
|
|
|
|
|
|
|
|
func _on_Launcher_interrupt_wave():
|