@@ -25,9 +25,24 @@ void Player::on_move(PointerMove const& pointer_move) { m_controller->on_move(po
2525void Player::on_tap (PointerTap const & pointer_tap) { m_controller->on_tap (pointer_tap); }
2626
2727void Player::tick (State const & state, Seconds const dt) {
28+ if (m_death) {
29+ m_death->tick (dt);
30+ if (m_death->active_particles () == 0 ) { m_death.reset (); }
31+ }
32+
33+ if (health.is_dead ()) { return ; }
34+
2835 auto const y_position = m_controller->tick (dt);
2936 set_y (y_position);
3037
38+ for (auto const & target : state.targets ) {
39+ if (is_intersecting (target->get_bounds (), ship.get_bounds ())) {
40+ on_death ();
41+ target->force_death ();
42+ return ;
43+ }
44+ }
45+
3146 auto const round_state = IWeaponRound::State{.targets = state.targets , .muzzle_position = get_muzzle_position ()};
3247 m_arsenal.tick (round_state, m_controller->is_firing (), dt);
3348
@@ -40,18 +55,24 @@ void Player::tick(State const& state, Seconds const dt) {
4055}
4156
4257void Player::draw (Shader& shader) const {
43- m_exhaust.draw (shader);
44- ship.draw (shader);
58+ if (!health.is_dead ()) {
59+ m_exhaust.draw (shader);
60+ ship.draw (shader);
61+ }
4562 m_arsenal.draw (shader);
63+ if (m_death) { m_death->draw (shader); }
4664}
4765
4866void Player::setup (WorldSpec::Player const & spec) {
4967 auto const & rgbas = m_services->get <Styles>().rgbas ;
5068 auto const & resources = m_services->get <Resources>();
5169 ship.tint = rgbas[spec.tint ];
70+
5271 if (auto const exhaust = resources.get <ParticleEmitter>(spec.exhaust_emitter )) { m_exhaust = *exhaust; }
5372 m_exhaust.set_position (get_exhaust_position ());
5473 m_exhaust.pre_warm ();
74+
75+ if (auto const death = resources.get <ParticleEmitter>(spec.death_emitter )) { m_death_source = *death; }
5576}
5677
5778void Player::set_y (float const y) { ship.transform .position .y = y; }
@@ -74,6 +95,13 @@ void Player::setup_ship() {
7495 ship.set_shape (rounded_quad);
7596}
7697
98+ void Player::on_death () {
99+ health = 0 .0f ;
100+ m_death = m_death_source;
101+ m_death->set_position (ship.transform .position );
102+ m_death->config .respawn = false ;
103+ }
104+
77105void Player::do_inspect () {
78106 if constexpr (bave::imgui_v) {
79107 if (ImGui::TreeNodeEx (" Controller" , ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_DefaultOpen)) {
0 commit comments