I finished the Godot 2D game tutorial Dodge the Creeps, and i'm adding a few additional features to reinforce the things learned and make more interesting the base game.
Basically i added a Scene with a area2d as root node with a collisionShape2d,a 2 timers for the Bomb scene.
The bomb appears randomlly in the main scene, for a few seconds is supposed to be ticking and then explodes.
My problem is that neither the player or the creeps( the npc enemies) are being removed from the scene. They don't interact at all,
This is the code for the Bomb.tscn scene:
extends Node func _ready(): # Area collison disabled until animation finishes $CollisionShape2D.disabled = true # Bomb ticking animation $AnimatedSprite.animation = "bomb" # Until BombTimer times out we change animation and activate collisionArea $BombTimer.start() func _on_BombTimer_timeout(): # Change animation sprite $AnimatedSprite.animation = "explosion" # Enable Collision area $CollisionShape2D.disabled = false # Start timer to remove bomb object $RemoveTimer.start() func _on_RemoveTimer_timeout(): queue_free()
The code for the creep/mob when hit by the bomb:
func _on_Mob_body_shape_entered(body_id, body, body_shape, local_shape): $CollisionShape2D.set_deferred("disabled", true) queue_free()
The code for collision detection for the player when is hit:
func _on_Player_body_entered(body): hide() # Player disappears after being hit emit_signal("hit") $CollisionShape2D.set_deferred("disabled", true)
If the creep/mob touches the player the game is over, but if the bombs explodes nothing happens. What i'm missing in the code?