void Garage::tick(float dt) { if (!doorObject) { return; } if (!active) { return; } needsToUpdate = false; switch (state) { case State::Opened: { if (shouldClose()) { state = State::Closing; doOnStartClosingEvent(); } break; } case State::Closed: { if (shouldOpen()) { state = State::Opening; doOnStartOpeningEvent(); } break; } case State::Opening: { if (shouldStopOpening()) { state = State::Closing; } else { fraction += dt * step; if (fraction >= 1.0f) { state = State::Opened; fraction = 1.f; doOnOpenEvent(); } needsToUpdate = true; } break; } case State::Closing: { if (shouldStopClosing()) { state = State::Opening; } else { fraction -= dt * step; if (fraction <= 0.f) { state = State::Closed; fraction = 0.f; doOnCloseEvent(); } needsToUpdate = true; } break; } default: { break; } } if (needsToUpdate) { updateDoor(); } }
void ofMainLoop::keyPressed(ofKeyEventArgs & key){ if (key.key == OF_KEY_ESC && escapeQuits == true){ // "escape" shouldClose(0); } }