Exemple #1
0
void Game::updateKeysPressedTable() {
	debug(DBG_GAME, "Game::updateKeysPressedTable()");
	_keysPressed[13] = _stub->_pi.enter ? 1 : 0;
	_keysPressed[16] = _stub->_pi.shift ? 1 : 0;
	_keysPressed[32] = _stub->_pi.space ? 1 : 0;
	_keysPressed[37] = (_stub->_pi.dirMask & PlayerInput::DIR_LEFT)  ? 1 : 0;
	_keysPressed[38] = (_stub->_pi.dirMask & PlayerInput::DIR_UP)    ? 1 : 0;
	_keysPressed[39] = (_stub->_pi.dirMask & PlayerInput::DIR_RIGHT) ? 1 : 0;
	_keysPressed[40] = (_stub->_pi.dirMask & PlayerInput::DIR_DOWN)  ? 1 : 0;
	if (_stub->_pi.tab) {
		_stub->_pi.tab = false;
		handleBagMenu();
	}
	if (_stub->_pi.ctrl) {
		_stub->_pi.ctrl = false;
		_lifeBarDisplayed = !_lifeBarDisplayed;
	}
	if (_stub->_pi.stateSlot != 0) {
		int slot = _stateSlot + _stub->_pi.stateSlot;
		if (slot >= 1 && slot <= 999) {
			_stateSlot = slot;
			debug(DBG_INFO, "Current game state slot is %d", _stateSlot);
		}
		_stub->_pi.stateSlot = 0;
	}
	if (_stub->_pi.load) {
		_stub->_pi.load = false;
		loadState(_stateSlot, true);
		_loadState = _switchScene; // gamestate will get loaded on scene switch
	}
	if (_stub->_pi.save) {
		_stub->_pi.save = false;
		saveState(_stateSlot);
	}
	if (_gameOver) {
		if (_stub->_pi.enter) {
			_stub->_pi.enter = false;
			restart();
		}
	}
}
Exemple #2
0
void Game::mainLoop() {
	if (_nextState != _state) {
		// fini
		switch (_state) {
		case kStateGame:
			break;
		case kStateDialogue:
			finiDialogue();
			break;
		case kStateMenu1:
		case kStateMenu2:
			finiMenu();
			break;
		}
		_state = _nextState;
		// init
		switch (_state) {
		case kStateGame:
			break;
		case kStateDialogue:
			initDialogue();
			break;
		case kStateBitmap:
			displayTitleBitmap();
			break;
		case kStateMenu1:
		case kStateMenu2:
			initMenu(1 + _state - kStateMenu1);
			break;
		}
	}
	switch (_state) {
	case kStateGame:
		while (_switchScene) {
			_switchScene = false;
			if (stringEndsWith(_tempTextBuffer, "SCN")) {
				win16_sndPlaySound(6);
				debug(DBG_GAME, "switch to scene '%s'", _tempTextBuffer);
				if (strcmp(_tempTextBuffer, "PIC4.SCN") == 0) {
					debug(DBG_INFO, "End of game");
					break;
				}
				strcpy(_currentSceneScn, _tempTextBuffer);
				parseSCN(_tempTextBuffer);
			} else {
				debug(DBG_GAME, "load mov '%s'", _tempTextBuffer);
				loadMOV(_tempTextBuffer);
			}
			if (_loadState) {
				_loadState = false;
				if (_currentSceneSav[0]) {
					FileHolder fh(_fs, _currentSceneSav);
					if (!fh._fp) {
						warning("Unable to load game state from file '%s'", _tempTextBuffer);
					} else {
						warning("Loading game state from '%s'", _currentSceneSav);
						loadState(fh._fp, kDemoSavSlot, false);
						loadKBR(_currentSceneSav);
					}
				} else {
					char filePath[MAXPATHLEN];
					snprintf(filePath, sizeof(filePath), kGameStateFileNameFormat, _savePath, _stateSlot);
					File f;
					if (!f.open(filePath, "rb")) {
						warning("Unable to load game state from file '%s'", filePath);
					} else {
						loadState(&f, _stateSlot, false);
					}
				}
				playMusic(_musicName);
				memset(_keysPressed, 0, sizeof(_keysPressed));
			}
			assert(_sceneObjectsCount != 0);
			if (_currentBagObject == -1) {
				_currentBagObject = _bagObjectsCount - 1;
				if (_currentBagObject > 0) {
					_currentBagObject = 0;
				}
			}
			if (_loadDataState != 0) {
				_stub->setPalette(_bitmapBuffer0 + kOffsetBitmapPalette, 256);
				_stub->copyRectWidescreen(kGameScreenWidth, kGameScreenHeight, _bitmapBuffer1.bits, _bitmapBuffer1.pitch);
			}
			_gameOver = false;
			_workaroundRaftFlySceneBug = strncmp(_currentSceneScn, "FLY", 3) == 0;
		}
		updateKeysPressedTable();
		updateMouseButtonsPressed();
		runObjectsScript();
		if (_startDialogue) {
			_startDialogue = false;
			_nextState = kStateDialogue;
		}
		break;
	case kStateBag:
		handleBagMenu();
		break;
	case kStateDialogue:
		handleDialogue();
		if (_dialogueEndedFlag) {
			_nextState = kStateGame;
		}
		break;
	case kStateBitmap:
		if (_stub->_pi.enter) {
			_stub->_pi.enter = false;
			playVideo("DATA/INTRO.AVI");
			_nextState = kStateGame;
		}
		break;
	case kStateMenu1:
		handleMenu();
		switch (_menuOption) {
		case kMenuOptionNewGame:
			restart();
			_nextState = kStateGame;
			break;
		case kMenuOptionLoadGame:
			_stub->_pi.load = true;
			_nextState = kStateGame;
			break;
		case kMenuOptionSaveGame:
			_stub->_pi.save = true;
			_nextState = kStateGame;
			break;
		case kMenuOptionQuitGame:
			_nextState = kStateMenu2;
			break;
		}
		if (_stub->_pi.escape) {
			_stub->_pi.escape = false;
			_nextState = kStateGame;
		}
		break;
	case kStateMenu2:
		handleMenu();
		switch (_menuOption) {
		case kMenuOptionExitGame:
			_stub->_quit = true;
			break;
		case kMenuOptionReturnGame:
			_nextState = kStateGame;
			break;
		}
		if (_stub->_pi.escape) {
			_stub->_pi.escape = false;
			_nextState = kStateGame;
		}
		break;
	}
	_stub->updateScreen();
}