JHRGB/Body2D.gd
2023-12-03 15:49:59 +00:00

33 lines
938 B
GDScript

extends RigidBody2D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _integrate_forces(state: PhysicsDirectBodyState2D):
var contact_count = state.get_contact_count()
#print("aa")
for i in range(contact_count):
#print("bb")
var collider_object = state.get_contact_collider_object(i)
if collider_object and collider_object.get_parent() is Player:
handle_player_collision(collider_object.get_parent())
if collider_object and collider_object.get_parent() is Pool:
handle_pool_collision(collider_object.get_parent())
func handle_player_collision(player: Player):
if $"..".is_carrying() and player.is_carrying():
$"..".doubledrop(player)
$"..".drop()
player.drop()
func handle_pool_collision(pool: Pool):
$"..".exchange_with(pool)