bomb.gd 895 B

12345678910111213141516171819202122232425262728293031323334
  1. extends Area2D
  2. var in_area: Array = []
  3. var from_player: int
  4. # Called from the animation.
  5. func explode():
  6. if not is_multiplayer_authority():
  7. # Explode only on authority.
  8. return
  9. for p 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 not result.collider is 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():
  20. if is_multiplayer_authority():
  21. queue_free()
  22. func _on_bomb_body_enter(body):
  23. if not body in in_area:
  24. in_area.append(body)
  25. func _on_bomb_body_exit(body):
  26. in_area.erase(body)