Make player using the event bus for enemies touching him
This commit is contained in:
parent
6c0b656d79
commit
ba46d6c65b
@ -60,6 +60,7 @@ void alai::player::Player::_ready()
|
|||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("level_loaded", this, "_on_level_loaded");
|
event->connect("level_loaded", this, "_on_level_loaded");
|
||||||
|
event->connect("player_touched", this, "_on_player_touched");
|
||||||
|
|
||||||
animated_sprite = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
if (!animated_sprite)
|
if (!animated_sprite)
|
||||||
@ -156,11 +157,11 @@ void alai::player::Player::_physics_process(float delta)
|
|||||||
}
|
}
|
||||||
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0))
|
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0))
|
||||||
{
|
{
|
||||||
_on_player_touched();
|
_on_player_touched(3);
|
||||||
}
|
}
|
||||||
else if (collider->is_in_group("enemy") && !collider->is_in_group("rideable"))
|
else if (collider->is_in_group("enemy") && !collider->is_in_group("rideable"))
|
||||||
{
|
{
|
||||||
_on_player_touched();
|
_on_player_touched(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +302,7 @@ godot::Vector2 alai::player::Player::get_velocity()
|
|||||||
return this->velocity;
|
return this->velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::player::Player::_on_player_touched()
|
void alai::player::Player::_on_player_touched(uint8_t damage)
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->emit_signal("player_died");
|
event->emit_signal("player_died");
|
||||||
|
@ -283,7 +283,7 @@ namespace alai
|
|||||||
* @brief This function is called when an enemy touches the player.
|
* @brief This function is called when an enemy touches the player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _on_player_touched();
|
void _on_player_touched(uint8_t damage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when the monitor is loaded to connect the player to it for tracking.
|
* @brief Called when the monitor is loaded to connect the player to it for tracking.
|
||||||
|
Loading…
Reference in New Issue
Block a user