void Oubliette::keyPressEvent(QKeyEvent *ke) { QPoint newPos = m_character.position(); switch (ke->key()) { case Qt::Key_Up: case Qt::Key_K: newPos.ry() -= 1; break; case Qt::Key_Down: case Qt::Key_J: newPos.ry() += 1; break; case Qt::Key_Left: case Qt::Key_H: newPos.rx() -= 1; break; case Qt::Key_Right: case Qt::Key_L: newPos.rx() += 1; break; case Qt::Key_I: showInventory(); break; default: QWidget::keyPressEvent(ke); } if (tryMove(newPos)) { QRect r(QPoint((newPos.x() - 8) * TileWidth, (newPos.y() - 8) * TileHeight), QSize(24 * TileWidth, 24 * TileHeight)); update(r); emit characterMoved(visualCursorPos()); } }
// Called when the game starts void UInventoryComponent::BeginPlay() { Super::BeginPlay(); equipment = NewObject<UCharacterEquipment>(this, equipment->GetClass()); for (int i = 0; i < beginPlayEquipment.Num(); i++) { if (beginPlayEquipment[i].item) { UItemBase* x = NewObject<UItemBase>(this, beginPlayEquipment[i].item); if (x) { x->ammount = beginPlayEquipment[i].ammount; x->initialize(GetOwner()->GetWorld()); addItem(x); } } } equipment->attachedInventory = this; if (requiresUI) loadUI(); showInventory(); hideInventory(); // ... }
void Hero::handleStateEquip(bool pressed, int key) { showInventory(); if (pressed) { switch (key) { case '1': case '2': case '3': case '4': case '5': { int i = m_inventoryPage * INVENTORY_PAGE_SIZE + key - '1'; if (i < (int)m_items.size()) { ItemSharedPtr item = m_items[i]; if (isEquipped(item)) { unequip(item); } else { equip(item); } } } break; case 'n': case 'N': { m_inventoryPage++; if (m_inventoryPage * INVENTORY_PAGE_SIZE > (int)m_items.size()) { m_inventoryPage = 0; } } break; case ' ': m_state = State::InGame; break; case 's': case 'S': m_state = State::Status; break; case 'd': case 'D': m_state = State::Drop; break; } } }
void UInventoryComponent::openTradeWindow(UInventoryComponent* otherInventory) { if (!requiresUI) return; state = InventoryState::TRADE; showInventory(); mainInventory->otherBorder->SetVisibility(ESlateVisibility::Visible); mainInventory->inventoryBorder->SetVisibility(ESlateVisibility::Visible); mainInventory->equipmentBorder->SetVisibility(ESlateVisibility::Collapsed); mainInventory->tradeBorder->SetVisibility(ESlateVisibility::Visible); otherInventoryForTransfering = otherInventory; refresh(); GetWorld()->GetTimerManager().SetTimer(transferRangeTimer, this, &UInventoryComponent::checkRangeOnOtherInventory, 0.1f, true); }
/** * Test dialog opening */ void DialogsManager::testDialogOpening() { if (_vm->_globals->_cityMapEnabledFl) _vm->_events->_gameKey = KEY_NONE; if ((_vm->_events->_gameKey == KEY_NONE) || _inventFl) return; DIALOG_KEY key = _vm->_events->_gameKey; _vm->_events->_gameKey = KEY_NONE; _inventFl = true; switch (key) { case KEY_INVENTORY: showInventory(); break; case KEY_OPTIONS: _vm->_graphicsMan->_scrollStatus = 1; showOptionsDialog(); _vm->_graphicsMan->_scrollStatus = 0; break; case KEY_LOAD: _vm->_graphicsMan->_scrollStatus = 1; showLoadGame(); _vm->_graphicsMan->_scrollStatus = 0; break; case KEY_SAVE: _vm->_graphicsMan->_scrollStatus = 1; showSaveGame(); _vm->_graphicsMan->_scrollStatus = 0; break; default: break; } _inventFl = false; _vm->_events->_gameKey = KEY_NONE; }
void Engine::mainLoop() { bool quit = false; //frame loop while(!quit) { //create event que sf::Event event; //clear screen m_Screen->clear(); //handle events while(m_Screen->pollEvent(event)) { if(event.type == sf::Event::Closed) quit = true; else if(event.type == sf::Event::KeyPressed) { if(event.key.code == sf::Keyboard::Escape) quit = true; else if(event.key.code == sf::Keyboard::F1) debugtest(); else if(event.key.code == sf::Keyboard::I) showInventory(); else if(event.key.code == sf::Keyboard::F) fillLiquidContainer(); else if(event.key.code == sf::Keyboard::D) dropItemUI(); else if(event.key.code == sf::Keyboard::G) pickupItemFromTileUI(m_Player->getPosition()); else if(event.key.code == sf::Keyboard::Left || event.key.code == sf::Keyboard::Numpad4) { walkInDir(m_Player, DIR_WEST); } else if(event.key.code == sf::Keyboard::Right || event.key.code == sf::Keyboard::Numpad6) { walkInDir(m_Player, DIR_EAST); } else if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::Numpad8) { walkInDir(m_Player, DIR_NORTH); } else if(event.key.code == sf::Keyboard::Down || event.key.code == sf::Keyboard::Numpad2) { walkInDir(m_Player, DIR_SOUTH); } else if(event.key.code == sf::Keyboard::Numpad1) { walkInDir(m_Player, DIR_SW); } else if(event.key.code == sf::Keyboard::Numpad3) { walkInDir(m_Player, DIR_SE); } else if(event.key.code == sf::Keyboard::Numpad7) { walkInDir(m_Player, DIR_NW); } else if(event.key.code == sf::Keyboard::Numpad9) { walkInDir(m_Player, DIR_NE); } } } //UPDATE //center viewport on player centerViewport(m_Player->getPosition()); //draw drawGame(); //update and display screen m_Screen->display(); if(!m_Player->isAlive()) { return; } } }
void move(Map *map, char direction) { //If there is a collision return. Else move. if (isCollision(map, direction) == 1) return; else { checkItemPickup(map, direction); //Checks movement direction then applies the movement. Will handle collision switch (direction) { case 0: break; //Movement case MOVE_UP: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0] - 1][map->currentPlayerLocation[1]] = PLAYER; map->currentPlayerLocation[0] -= 1; break; case MOVE_LEFT: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1] - 1] = PLAYER; map->currentPlayerLocation[1] -= 1; break; case MOVE_RIGHT: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1] + 1] = PLAYER; map->currentPlayerLocation[1] += 1; break; case MOVE_DOWN: map->map[map->currentPlayerLocation[0]][map->currentPlayerLocation[1]] = '-'; map->map[map->currentPlayerLocation[0] + 1][map->currentPlayerLocation[1]] = PLAYER; map->currentPlayerLocation[0] += 1; break; //Checks if other keys are pressed case QUIT_KEY: printf("Quitting...\n"); freeEverything(map); exit(1); break; case INV_KEY: showInventory(); break; case SPACEBAR: check = checkNPC(map); if (check != 0) { printf("Check was successful\n"); int i; for (i = 0; i < 1; i++) { if (map->npcs[i]->location[0] == *(check + i) && map->npcs[i]->location[1] == *(check + 1 + i)) talkNPC(map, map->npcs[i]); else printf("Error talking to NPC\n"); } } break; default: printMap(map); } } //Checks if inventory is closed. If so, print the map if (inventoryOpen == 0) { printMap(map); } }
void Parser::keyHandler(Common::Event event) { debugC(1, kDebugParser, "keyHandler(%d)", event.kbd.keycode); status_t &gameStatus = _vm->getGameStatus(); uint16 nChar = event.kbd.keycode; if ((event.kbd.hasFlags(Common::KBD_ALT)) || (event.kbd.hasFlags(Common::KBD_SCRL))) return; if (event.kbd.hasFlags(Common::KBD_CTRL)) { switch (nChar) { case Common::KEYCODE_d: _vm->getDebugger()->attach(); _vm->getDebugger()->onFrame(); break; case Common::KEYCODE_l: _vm->_file->restoreGame(-1); break; case Common::KEYCODE_n: if (Utils::yesNoBox("Are you sure you want to start a new game?")) _vm->_file->restoreGame(0); break; case Common::KEYCODE_s: if (gameStatus.viewState == kViewPlay) { if (gameStatus.gameOverFl) _vm->gameOverMsg(); else _vm->_file->saveGame(-1, Common::String()); } break; default: break; } return; } // Process key down event - called from OnKeyDown() switch (nChar) { // Set various toggle states case Common::KEYCODE_ESCAPE: // Escape key, may want to QUIT if (gameStatus.viewState == kViewIntro) gameStatus.skipIntroFl = true; else { if (_vm->_inventory->getInventoryState() == kInventoryActive) // Remove inventory, if displayed _vm->_inventory->setInventoryState(kInventoryUp); _vm->_screen->resetInventoryObjId(); } break; case Common::KEYCODE_END: case Common::KEYCODE_HOME: case Common::KEYCODE_PAGEUP: case Common::KEYCODE_PAGEDOWN: case Common::KEYCODE_KP1: case Common::KEYCODE_KP7: case Common::KEYCODE_KP9: case Common::KEYCODE_KP3: case Common::KEYCODE_LEFT: case Common::KEYCODE_RIGHT: case Common::KEYCODE_UP: case Common::KEYCODE_DOWN: case Common::KEYCODE_KP4: case Common::KEYCODE_KP6: case Common::KEYCODE_KP8: case Common::KEYCODE_KP2: _vm->_route->resetRoute(); // Stop any automatic route _vm->_route->setWalk(nChar); // Direction of hero travel break; case Common::KEYCODE_F1: // User Help (DOS) if (_checkDoubleF1Fl) gameStatus.helpFl = true; else _vm->_screen->userHelp(); _checkDoubleF1Fl = !_checkDoubleF1Fl; break; case Common::KEYCODE_F2: // Toggle sound _vm->_sound->toggleSound(); _vm->_sound->toggleMusic(); break; case Common::KEYCODE_F3: // Repeat last line gameStatus.recallFl = true; break; case Common::KEYCODE_F4: // Save game if (gameStatus.viewState == kViewPlay) { if (gameStatus.gameOverFl) _vm->gameOverMsg(); else _vm->_file->saveGame(-1, Common::String()); } break; case Common::KEYCODE_F5: // Restore game _vm->_file->restoreGame(-1); break; case Common::KEYCODE_F6: // Inventory showInventory(); break; case Common::KEYCODE_F8: // Turbo mode switchTurbo(); break; case Common::KEYCODE_F9: // Boss button warning("STUB: F9 (DOS) - BossKey"); break; default: // Any other key if (!gameStatus.storyModeFl) { // Keyboard disabled // Add printable keys to ring buffer uint16 bnext = _putIndex + 1; if (bnext >= sizeof(_ringBuffer)) bnext = 0; if (bnext != _getIndex) { _ringBuffer[_putIndex] = event.kbd.ascii; _putIndex = bnext; } } break; } if (_checkDoubleF1Fl && (nChar != Common::KEYCODE_F1)) _checkDoubleF1Fl = false; }
void KyraEngine_MR::updateMouse() { int shape = 0, offsetX = 0, offsetY = 0; Common::Point mouse = getMousePos(); bool hasItemCollision = checkItemCollision(mouse.x, mouse.y) != -1; if (mouse.y > 187) { bool setItemCursor = false; if (_mouseState == -6) { if (mouse.x < 311) setItemCursor = true; } else if (_mouseState == -5) { if (mouse.x < _sceneMinX || mouse.x > _sceneMaxX) setItemCursor = true; } else if (_mouseState == -4) { if (mouse.x > 8) setItemCursor = true; } if (setItemCursor) { setItemMouseCursor(); return; } } if (_inventoryState) { if (mouse.y >= 144) return; hideInventory(); } if (hasItemCollision && _mouseState < -1 && _itemInHand < 0) { _mouseState = kItemNone; _itemInHand = kItemNone; _screen->setMouseCursor(0, 0, _gameShapes[0]); } int type = 0; if (mouse.y <= 199) { if (mouse.x <= 8) { if (_sceneExit4 != 0xFFFF) { type = -4; shape = 4; offsetX = 0; offsetY = 0; } } else if (mouse.x >= 311) { if (_sceneExit2 != 0xFFFF) { type = -6; shape = 2; offsetX = 13; offsetY = 8; } } else if (mouse.y >= 171) { if (_sceneExit3 != 0xFFFF) { if (mouse.x >= _sceneMinX && mouse.x <= _sceneMaxX) { type = -5; shape = 3; offsetX = 8; offsetY = 13; } } } else if (mouse.y <= 8) { if (_sceneExit1 != 0xFFFF) { type = -7; shape = 1; offsetX = 8; offsetY = 0; } } } for (int i = 0; i < _specialExitCount; ++i) { if (checkSpecialSceneExit(i, mouse.x, mouse.y)) { switch (_specialExitTable[20+i]) { case 0: type = -7; shape = 1; offsetX = 8; offsetY = 0; break; case 2: type = -6; shape = 2; offsetX = 13; offsetY = 8; break; case 4: type = -5; shape = 3; offsetX = 8; offsetY = 13; break; case 6: type = -4; shape = 4; offsetX = 0; offsetY = 8; break; default: break; } } } if (type != 0 && type != _mouseState && !hasItemCollision) { _mouseState = type; _screen->setMouseCursor(offsetX, offsetY, _gameShapes[shape]); } else if (type == 0 && _mouseState != _itemInHand && mouse.x > 8 && mouse.x < 311 && mouse.y < 171 && mouse.y > 8) { setItemMouseCursor(); } else if (mouse.y > 187 && _mouseState > -4 && type == 0 && !_inventoryState) { showInventory(); } }