+ // guess number of frames to descend to same height as player
+ float estFrames = height / relSpeed;
+
+ // guess where the player would be at this time
+ float estPx = (player_pos.x + (estFrames * player_mov.x));
+
+ // guess where we would be at this time
+ float estBx = (self_pos.x + (estFrames * self_mov.x));
+
+ // near misses are OK, too
+ if (fabsf(estPx - estBx) < 8) return true;
+ }
+
+ // update last player tracked, as well as our positions
+ last_player = player;
+ if (player) {
+ last_player_pos = player->get_pos();
+ last_self_pos = this->get_pos();
+ }
+
+ return false;
+}
+
+void
+Zeekling::active_update(float elapsed_time) {
+ if (state == FLYING) {
+ if (should_we_dive()) {
+ state = DIVING;
+ physic.set_velocity_y(2*fabsf(physic.get_velocity_x()));
+ sprite->set_action(dir == LEFT ? "diving-left" : "diving-right");
+ }
+ BadGuy::active_update(elapsed_time);
+ return;
+ } else if (state == DIVING) {
+ BadGuy::active_update(elapsed_time);
+ return;
+ } else if (state == CLIMBING) {
+ // stop climbing when we're back at initial height
+ if (get_pos().y <= start_position.y) {
+ state = FLYING;
+ physic.set_velocity_y(0);
+ }
+ BadGuy::active_update(elapsed_time);
+ return;
+ } else {
+ assert(false);
+ }