The mushroom can be destroyed by
The mushroom can be destroyed by
Jumping onto it from above.
Jumping onto it from above.
To enable this we will create a stomp area
To enable this we will create a stomp area
using an Area2D node and a CollisionShape2D
using an Area2D node and a CollisionShape2D
This area will represent the death zone for the mushroom
This area will represent the death zone for the mushroom
Use a RectangleShape2D for the CollisionShape2D
Use a RectangleShape2D for the CollisionShape2D
Place it at the top of the mushroom as shown.
Place it at the top of the mushroom as shown.
When the player (body) enters the mushroom at this zone.
When the player (body) enters the mushroom at this zone.
We will hurt or kill or destroy the mushroom.
We will hurt or kill or destroy the mushroom.
Select the DeathZone node
Select the DeathZone node
connect the on_body_entered signal.
connect the on_body_entered signal.
In the Mushroom script write code for what happens when the player enters the mushroom death zone.
In the Mushroom script write code for what happens when the player enters the mushroom death zone.
We subtract 1 from mushroom health.
We subtract 1 from mushroom health.
Create a function to run once the mushrooms health is below 1.
Create a function to run once the mushrooms health is below 1.
It will raise the mushroom into the air
It will raise the mushroom into the air
and play the death animation.
and play the death animation.
Call it mushroom death.
Call it mushroom death.
Remember to call this function in process!
Remember to call this function in process!
We should also disable the collisions on the mushroom
We should also disable the collisions on the mushroom
We should also disable the physics process
We should also disable the physics process
This is so that the mushroom can be destroyed.
This is so that the mushroom can be destroyed.
We should only destroy the mushroom once the death animation is finished playing.
We should only destroy the mushroom once the death animation is finished playing.
Connect the animation finished signal of the AnimatedSprite2D node
Connect the animation finished signal of the AnimatedSprite2D node
If the animation is called death - destroy the mushroom.
If the animation is called death - destroy the mushroom.