1
0

walls.gd 959 B

123456789101112131415161718192021222324252627282930
  1. class_name Walls
  2. extends StaticBody2D
  3. ## Screen edges. The bottom edge is its own body in the "bottom" group, so the game can tell
  4. ## when a ball or power-up falls out.
  5. func _ready() -> void:
  6. collision_layer = Params.LAYER_WALLS
  7. collision_mask = 0
  8. var size := get_viewport_rect().size
  9. _add_boundary(self, Vector2.RIGHT, 0.0)
  10. _add_boundary(self, Vector2.LEFT, -size.x)
  11. _add_boundary(self, Vector2.DOWN, 0.0)
  12. var bottom := StaticBody2D.new()
  13. bottom.collision_layer = Params.LAYER_WALLS
  14. bottom.collision_mask = 0
  15. bottom.add_to_group("bottom")
  16. add_child(bottom)
  17. _add_boundary(bottom, Vector2.UP, -size.y)
  18. ## Adds a half-plane; [param normal] points into the open (playable) side.
  19. func _add_boundary(body: StaticBody2D, normal: Vector2, distance: float) -> void:
  20. var shape := WorldBoundaryShape2D.new()
  21. shape.normal = normal
  22. shape.distance = distance
  23. var collision := CollisionShape2D.new()
  24. collision.shape = shape
  25. body.add_child(collision)