| 123456789101112131415161718192021222324252627282930 |
- class_name Walls
- extends StaticBody2D
- ## Screen edges. The bottom edge is its own body in the "bottom" group, so the game can tell
- ## when a ball or power-up falls out.
- func _ready() -> void:
- collision_layer = Params.LAYER_WALLS
- collision_mask = 0
- var size := get_viewport_rect().size
- _add_boundary(self, Vector2.RIGHT, 0.0)
- _add_boundary(self, Vector2.LEFT, -size.x)
- _add_boundary(self, Vector2.DOWN, 0.0)
- var bottom := StaticBody2D.new()
- bottom.collision_layer = Params.LAYER_WALLS
- bottom.collision_mask = 0
- bottom.add_to_group("bottom")
- add_child(bottom)
- _add_boundary(bottom, Vector2.UP, -size.y)
- ## Adds a half-plane; [param normal] points into the open (playable) side.
- func _add_boundary(body: StaticBody2D, normal: Vector2, distance: float) -> void:
- var shape := WorldBoundaryShape2D.new()
- shape.normal = normal
- shape.distance = distance
- var collision := CollisionShape2D.new()
- collision.shape = shape
- body.add_child(collision)
|