void Scene::loadBackground(int xAmount, int yAmount) { // Adjust the scene bounds by the passed scroll amounts _sceneBounds.translate(xAmount, yAmount); _sceneBounds.contain(_backgroundBounds); _sceneBounds.left &= ~3; _sceneBounds.right &= ~3; _globals->_sceneOffset.x &= ~3; if ((_sceneBounds.top != _oldSceneBounds.top) || (_sceneBounds.left != _oldSceneBounds.left)) { if (_globals->_sceneManager._loadMode == 0) { _globals->_paneRefreshFlag[0] = 2; _globals->_paneRefreshFlag[1] = 2; _globals->_sceneManager._loadMode = 2; } _oldSceneBounds = _sceneBounds; } _globals->_sceneOffset.x = (_sceneBounds.left / 160) * 160; _globals->_sceneOffset.y = (_sceneBounds.top / 100) * 100; if ((_backgroundBounds.width() / 160) == 3) _globals->_sceneOffset.x = 0; if ((_backgroundBounds.height() / 100) == 3) _globals->_sceneOffset.y = 0; if ((_globals->_sceneOffset.x != _globals->_prevSceneOffset.x) || (_globals->_sceneOffset.y != _globals->_prevSceneOffset.y)) { // Change has happend, so refresh background _globals->_prevSceneOffset = _globals->_sceneOffset; refreshBackground(xAmount, yAmount); } }
void GameSwitcher::loadBackgroundImage() { if (background_list.empty()) return; if (background_filename != "") return; // load the background image size_t index = static_cast<size_t>(rand()) % background_list.size(); background_filename = background_list[index]; background_image = render_device->loadImage(background_filename); refreshBackground(); }
void GameSwitcher::logic() { // reset the mouse cursor curs->logic(); // Check if a the game state is to be changed and change it if necessary, deleting the old state GameState* newState = currentState->getRequestedGameState(); if (newState != NULL) { if (currentState->reload_backgrounds || render_device->reloadGraphics()) loadBackgroundList(); delete currentState; currentState = newState; currentState->load_counter++; // reload the fps meter position loadFPS(); // if this game state does not provide music, use the title theme if (!currentState->hasMusic) if (!snd->isPlayingMusic()) loadMusic(); // if this game state shows a background image, load it here if (currentState->has_background) loadBackgroundImage(); else freeBackground(); } // resize background image when window is resized if (inpt->window_resized && currentState->has_background) { refreshBackground(); } currentState->logic(); // Check if the GameState wants to quit the application done = currentState->isExitRequested(); if (currentState->reload_music) { loadMusic(); currentState->reload_music = false; } }