@@ -11,41 +11,38 @@ using bave::RoundedQuad;
11
11
using bave::Seconds;
12
12
using bave::Shader;
13
13
14
- Enemy::Enemy (Services const & services, bave::NotNull<IEnemyDeathListener*> listener, std::string_view const type)
15
- : health_bar(services), m_layout(&services.get<ILayout>()), m_listener(listener), m_type(type) {
14
+ Enemy::Enemy (Services const & services, std::string_view const type) : m_layout(&services.get<ILayout>()), m_health_bar(services), m_type(type) {
16
15
static constexpr auto init_size_v = glm::vec2{100 .0f };
17
16
auto const play_area = m_layout->get_play_area ();
18
17
auto const y_min = play_area.rb .y + 0 .5f * init_size_v.y ;
19
18
auto const y_max = play_area.lt .y - 0 .5f * init_size_v.y - 50 .0f ;
20
19
setup (init_size_v, random_in_range (y_min, y_max));
21
20
22
- health_bar .set_style (services.get <Styles>().progress_bars [" enemy" ]);
21
+ m_health_bar .set_style (services.get <Styles>().progress_bars [" enemy" ]);
23
22
}
24
23
25
24
auto Enemy::take_damage (float const damage) -> bool {
26
25
if (is_destroyed ()) { return false ; }
27
26
health.inflict_damage (damage);
28
- if (health.is_dead ()) { m_listener->on_death (EnemyDeath{.position = shape.transform .position , .points = points}); }
29
27
return true ;
30
28
}
31
29
32
30
void Enemy::force_death () {
33
31
health = 0 .0f ;
34
- health_bar.set_progress (0 .0f );
35
- m_listener->on_death (EnemyDeath{.position = shape.transform .position });
32
+ m_health_bar.set_progress (0 .0f );
36
33
}
37
34
38
35
void Enemy::tick (Seconds const dt, bool const /* in_play*/ ) {
39
- health_bar .position = shape.transform .position ;
40
- health_bar .position .y += 0 .5f * shape.get_shape ().size .y + 20 .0f ;
41
- health_bar .size = {shape.get_shape ().size .x , 10 .0f };
42
- health_bar .set_progress (health.get_hit_points () / health.get_total_hit_points ());
43
- health_bar .tick (dt);
36
+ m_health_bar .position = shape.transform .position ;
37
+ m_health_bar .position .y += 0 .5f * shape.get_shape ().size .y + 20 .0f ;
38
+ m_health_bar .size = {shape.get_shape ().size .x , 10 .0f };
39
+ m_health_bar .set_progress (health.get_hit_points () / health.get_total_hit_points ());
40
+ m_health_bar .tick (dt);
44
41
}
45
42
46
43
void Enemy::draw (Shader& shader) const {
47
44
shape.draw (shader);
48
- health_bar .draw (shader);
45
+ m_health_bar .draw (shader);
49
46
}
50
47
51
48
void Enemy::setup (glm::vec2 max_size, float y_position) {
0 commit comments