bomb.gd 953 B

123456789101112131415161718192021222324252627282930313233343536
  1. extends Area2D
  2. var in_area: Array = []
  3. var from_player: int
  4. # Called from the animation.
  5. func explode() -> void:
  6. if not is_multiplayer_authority():
  7. # Explode only on authority.
  8. return
  9. for p: Object in in_area:
  10. if p.has_method("exploded"):
  11. # Checks if there is wall in between bomb and the object.
  12. var world_state: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state
  13. var query := PhysicsRayQueryParameters2D.create(position, p.position)
  14. query.hit_from_inside = true
  15. var result: Dictionary = world_state.intersect_ray(query)
  16. if result.collider is not TileMap:
  17. # Exploded can only be called by the authority, but will also be called locally.
  18. p.exploded.rpc(from_player)
  19. func done() -> void:
  20. if is_multiplayer_authority():
  21. queue_free()
  22. func _on_bomb_body_enter(body: Node2D) -> void:
  23. if not body in in_area:
  24. in_area.append(body)
  25. func _on_bomb_body_exit(body: Node2D) -> void:
  26. in_area.erase(body)