void Scene2Controller::UpdateRackets() { model_.racket1 = Lerp(model_.racket1, model_.racket1_target, player_move_smooth_factor); if (keys[OF_KEY_LEFT] && model_.racket1_target.x > -half_court_length) { model_.racket1_target.x -= racket_speed; } if (keys[OF_KEY_RIGHT] && model_.racket1_target.x < -racket_speed - racket_radius) { model_.racket1_target.x += racket_speed; } RacketCollide(model_.racket1, racket1_low_hit_direction, low_hit_mean, OF_KEY_LEFT, OF_KEY_RIGHT); }
void Scene3Controller::UpdateRackets() { model_.racket1 = Lerp(model_.racket1, model_.racket1_target, player_move_smooth_factor); if (model_.opponent_index == 7) { model_.opponent = Lerp(model_.opponent, model_.opponent_target, player_move_smooth_factor * model_.nerd_energy); } else { model_.opponent = Lerp(model_.opponent, model_.opponent_target, player_move_smooth_factor); } if (keys[OF_KEY_LEFT] && model_.racket1_target.x > -half_court_length) { model_.racket1_target.x -= racket_speed; } if (keys[OF_KEY_RIGHT] && model_.racket1_target.x < -racket_speed - racket_radius) { model_.racket1_target.x += racket_speed; } if (model_.score != 5 && model_.opponent_index != 8 && model_.opponent_index != 3 && model_.opponent_index != 9 && model_.opponent_index != 7 && model_.opponent_index != 4) { if (model_.opponent_index == 0) { const float dy = ofNoise(-ofGetElapsedTimef()) * racket_speed / 10.0; model_.opponent_target.y += dy; } // opponent if (model_.ball_body && model_.ball_body->GetPosition().x > 0) { const float dx = model_.ball_body->GetPosition().x - model_.opponent_target.x; if (dx > racket_radius + ball_radius) { model_.opponent_target.x += racket_speed - ofNoise(ofGetElapsedTimef()) * racket_speed; } else if (dx < -racket_radius - ball_radius) { model_.opponent_target.x -= racket_speed - ofNoise(ofGetElapsedTimef()) * racket_speed; } } else { const float dx = ofSignedNoise(ofGetElapsedTimef()) * racket_speed; if (dx > 0 && model_.opponent_target.x < half_court_length) { model_.opponent_target.x += dx; } if (dx < 0 && model_.opponent_target.x > dx + racket_radius) { model_.opponent_target.x += dx; } } } if (model_.opponent_index == 3) { model_.opponent_target.x = .377 * half_court_length; } if (model_.opponent_index == 5 && model_.score != 5) { model_.opponent_target.x = 7; } if (model_.opponent_index == 7 || (model_.opponent_index == 4 && model_.glass_hits < 3)) { if (model_.ball_body && model_.ball_body->GetPosition().x > 0) { const float dx = model_.ball_body->GetLinearVelocity().x; model_.opponent_target.x = model_.ball_body->GetPosition().x + 3.0 * dx * delta_time; model_.opponent_target.x = max(model_.opponent_target.x, racket_radius.GetValue()); } else { model_.opponent_target.x = racket_radius + (half_court_length - 2.0 * racket_radius) * ofNoise(ofGetElapsedTimef()); } } if (model_.opponent_index == 9) { model_.opponent_target.x = -model_.racket1_target.x; } RacketCollide(model_.racket1, racket1_low_hit_direction, low_hit_mean, OF_KEY_LEFT, OF_KEY_RIGHT); if (model_.score != 5 && model_.opponent_index != 3 && model_.opponent_index != 4) { RacketCollide(model_.opponent, model_.opponent_index == 6 ? -racket2_low_hit_direction.GetValue() : racket2_low_hit_direction, low_hit_mean, OF_KEY_LEFT, OF_KEY_RIGHT, true); } if (model_.opponent_index == 4 && model_.glass_hits < 3) { RacketCollide(model_.opponent, model_.opponent_index == 6 ? -racket2_low_hit_direction.GetValue() : racket2_low_hit_direction, low_hit_mean, OF_KEY_LEFT, OF_KEY_RIGHT, true); } }