bool Mouse::regularMove() { IW_CALLSTACK("Mouse::regularMove"); CIwFVec2 ftemp = this->f2AbsPosition; if(this->bScared == true) { } else { if(this->bMoveLeft == true) { this->f2AbsPosition.x -= this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; if(checkPosition()) this->i2Position.x = (int)this->f2AbsPosition.x; else this->f2AbsPosition = ftemp; } else { this->f2AbsPosition.x += this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; if(checkPosition()) this->i2Position.x = (int)this->f2AbsPosition.x; else this->f2AbsPosition = ftemp; } } return false; }
void ComboBox::MouseEventProc(MOUSE_EVENT_RECORD mer) { if (displayList) { if (checkPosition(mer) && mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) { CloseList(); return; } string prevChose = optionsList->GetValue(); optionsList->MouseEventProc(mer); string chose = optionsList->GetValue(); if (prevChose != chose) { CloseList(); } chosenText->CleanLabel(); if (chose != "no choose") { chose[0] = '+'; chose[1] = ' '; chose[2] = ' '; } else { chose = "+ "; } chosenText->SwitchContent(chose); } else { if (checkPosition(mer) && mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) { OpenList(); } } }
void OEMFGame :: handleInput() { if (m_done == 1) return; float accel = 4.0f; m_player->m_vx = 0.0f; if (m_keyDown[SDLK_LEFT]) m_player->m_vx += -accel; if (m_keyDown[SDLK_RIGHT]) m_player->m_vx += accel; if (m_keyDown[SDLK_UP]) { if (!checkPosition(m_player, m_player->posX(), m_player->posY() + 1, false) && checkPosition(m_player, m_player->posX(), m_player->posY() - 1, false)) // am I standing on something? is there room to jump? { m_player->m_vy = -10.0f; musicPlayer->playSound(sounds[SND_HIP]); } } if (!m_keyDown[SDLK_LEFT] && !m_keyDown[SDLK_RIGHT]) { #ifndef WINCE Mix_HaltChannel(15); #endif } }
/** This function sets the steering. * \param dt Time step size. */ void ArenaAI::handleArenaSteering(const float dt) { const int current_node = getCurrentNode(); if (current_node == BattleGraph::UNKNOWN_POLY || m_target_node == BattleGraph::UNKNOWN_POLY) return; if (m_target_node == current_node) { // Very close to the item, steer directly checkPosition(m_target_point, &m_cur_kart_pos_data); #ifdef AI_DEBUG m_debug_sphere->setPosition(m_target_point.toIrrVector()); #endif if (m_cur_kart_pos_data.behind) { m_adjusting_side = m_cur_kart_pos_data.on_side; m_is_uturn = true; } else { float target_angle = steerToPoint(m_target_point); setSteering(target_angle, dt); } return; } else if (m_target_node != current_node) { findPortals(current_node, m_target_node); stringPull(m_kart->getXYZ(), m_target_point); if (m_path_corners.size() > 0) m_target_point = m_path_corners[0]; checkPosition(m_target_point, &m_cur_kart_pos_data); #ifdef AI_DEBUG m_debug_sphere->setPosition(m_target_point.toIrrVector()); #endif if (m_cur_kart_pos_data.behind) { m_adjusting_side = m_cur_kart_pos_data.on_side; m_is_uturn = true; } else { float target_angle = steerToPoint(m_target_point); setSteering(target_angle, dt); } return; } else { // Do nothing (go straight) if no targets found setSteering(0.0f, dt); return; } } // handleSteering
MOVES Model::movesFigure(int player, const Figure& figure, int movetype, bool needCheck) const { bool accepted; int curLimit; MOVES avMoves; Move move; MOVERULES::iterator itRule; Position curPos; MOVERULES curRules = myRules->getMoveRules(figure.id); for (itRule = curRules.begin(); itRule != curRules.end(); ++itRule) { if ((movetype == CAPTURE && itRule->moveType == MOVE) || (movetype == MOVE && itRule->moveType == CAPTURE)) { // пропускаем правило } else if (itRule->player == ALL || itRule->player == player) { if (itRule->ruleType == JUMP) { accepted = false; move.pos1 = figure.position; move.pos2.myX = move.pos1.myX + itRule->dx; move.pos2.myY = move.pos1.myY + itRule->dy; move.player = player; accepted = checkPosition(*itRule, figure, move, movetype, needCheck); if (accepted == true) { avMoves.push_back(move); } } else if (itRule->ruleType == SLIDE) { curLimit = 0; move.pos1 = figure.position; move.pos2 = move.pos1; bool isFree; do { isFree = checkIsFree(*itRule, move.pos2); if (isFree == true) { move.pos2.myX += itRule->dx; move.pos2.myY += itRule->dy; move.player = player; accepted = checkPosition(*itRule, figure, move, movetype, needCheck); if (accepted == true) { avMoves.push_back(move); } ++curLimit; } } while (isFree == true && myBoard(move.pos2.myX, move.pos2.myY) == 0 && (itRule->limit == 0 || curLimit < itRule->limit)); } } } return avMoves; }
bool World::move(WorldObject* const worldObject, const int direction, const int maxPower, int& usedPower) { Position p(0,0); WorldObject *object; WorldObjectList* list; if ( maxPower < usedPower) return false; p.x = worldObject->p->x; p.y = worldObject->p->y; Direction::computePosition(&p,direction); if (checkPosition(&p) == false ) return false; list = world[p.x][p.y]; list->setToFirst(); while(object = list->getNext()) if(!object->conditionalMovement(worldObject,direction,maxPower,usedPower)) return false; if(!moveObject(worldObject,direction)) return false; return true; }
int RobotMemory::getMemoryCell(Position *p) { if(checkPosition(*p)) return map[p->x][p->y]; else exit(200); }
//----------------------------------------------------------------------------- void ArenaAI::handleArenaBanana() { if (m_is_uturn) return; const std::vector< std::pair<const Item*, int> >& item_list = BattleGraph::get()->getItemList(); const unsigned int items_count = item_list.size(); for (unsigned int i = 0; i < items_count; ++i) { const Item* item = item_list[i].first; if (item->getType() == Item::ITEM_BANANA && !item->wasCollected()) { posData banana_pos = {0}; Vec3 banana_lc(0, 0, 0); checkPosition(item->getXYZ(), &banana_pos, &banana_lc); if (banana_pos.angle < 0.2f && banana_pos.distance < 7.5f && !banana_pos.behind) { // Check whether it's straight ahead towards a banana // If so, adjust target point banana_lc = (banana_pos.on_side ? banana_lc + Vec3 (2, 0, 0) : banana_lc - Vec3 (2, 0, 0)); m_target_point = m_kart->getTrans()(banana_lc); m_target_node = BattleGraph::get() ->pointToNode(getCurrentNode(), m_target_point, false/*ignore_vertical*/); // Handle one banana only break; } } } } // handleArenaBanana
//----------------------------------------------------------------------------- void ArenaAI::handleArenaUTurn(const float dt) { const float turn_side = (m_adjusting_side ? 1.0f : -1.0f); if (fabsf(m_kart->getSpeed()) > (m_kart->getKartProperties()->getEngineMaxSpeed() / 5) && m_kart->getSpeed() < 0) // Try to emulate reverse like human players m_controls->m_accel = -0.06f; else m_controls->m_accel = -5.0f; if (m_time_since_uturn >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f)) setSteering(-(turn_side), dt); // Preventing keep going around circle else setSteering(turn_side, dt); m_time_since_uturn += dt; checkPosition(m_target_point, &m_cur_kart_pos_data); if (!m_cur_kart_pos_data.behind || m_time_since_uturn > (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 3.5f : 3.0f)) { m_is_uturn = false; m_time_since_uturn = 0.0f; } else m_is_uturn = true; } // handleArenaUTurn
WorldObject* World::getObject(Position *p, int className) { if(!checkPosition(p)) return NULL; else return world[p->x][p->y]->getObjectByName(className); }
void KNMusicBackendBassThread::setPosition(const qint64 &position) { //Check the channel is null. if(!m_channel) { return; } //If the state is stopped and the position is not 0, then changed the state //to pause. if(m_state==Stopped && position!=0) { //Change to paused. setPlayingState(Paused); } //Change the position, the unit of the position should be translate into //second. BASS_ChannelSetPosition( m_channel, BASS_ChannelSeconds2Bytes(m_channel, //The position here should be the //'absolute' position. //That means it should be the position //plus the start position. (double)(m_startPosition+position) /1000.0), BASS_POS_BYTE); //Check the position. checkPosition(); }
void StoneHandler::checkAllPositions() { // Traverse all stones and check their positions. // Yuck, I suppose this is expensive... // Called when jumping through the variations. groups->clear(); Q3IntDictIterator<Stone> it(*stones); Stone *s; // Unmark stones as checked while (it.current()) { it.current()->checked = false; ++it; } it.toFirst(); while (it.current()) { s = it.current(); if (!s->checked) checkPosition(s,NULL); //SL added eb 8 ++it; } }
/* Връща 1, ако конфигурацията е печеливша за играча player, 2 — ако е губеща и * 3, ако е неопределена */ char checkPosition(char player, char board[3][3]) { unsigned i, j, result; int t = terminal(board); if (t) { if (player == t) return 1; if (3 == t) return 3; if (player != t) return 2; } else { char otherPlayer, playerSign; if (player == 1) { playerSign = 'X'; otherPlayer = 2; } else { playerSign = 'O'; otherPlayer = 1; } /* char boardi[3][3]; Ј * определя позицията */ for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (board[i][j] == '.') { board[i][j] = playerSign; result = checkPosition(otherPlayer, board); board[i][j] = '.'; if (result == 2) return 1; /* конфигурацията е губеща за противника, */ /* следователно е печеливша за играча player */ if (result == 3) return 3; /* конфигурацията е неопределена */ } } } /* ако сме достигнали дотук, значи всички наследници са печеливши конфигурации и * следователно тази е губеща за играча player */ return 2; } }
void PositionInterpolatorTests::testExtremes( TestReporter& reporter ) { NEW_TEST_FUNCTION( reporter ); PositionInterpolator interpolator; PositionInterpolatorTester tester( interpolator ); interpolator.disableMC2Conversion(); /** * * No data. No correct calculations or assumptions could be made, * so the position 0, 0 is returned. * */ CHECK( !tester.getPosition( 1000 ).isValid(), reporter ); InterpolationHintConsumer& pathConsumer = interpolator; pathConsumer.prepareNewData( 1000 ); MC2Coordinate checkPosition( 1337, 1337 ); static const int MPSToCmPS = 100; pathConsumer.addDataPoint( checkPosition, 10 * MPSToCmPS ); pathConsumer.finalizeNewData(); /** * Only single point, should return point itself. */ CHECK( tester.getPosition( 0 ) == checkPosition, reporter ); CHECK( tester.getPosition( 1000 ) == checkPosition, reporter ); CHECK( tester.getPosition( 2000 ) == checkPosition, reporter ); /** * Two points, test outside scope on both sides of the interval. * Should be clamped to endpoints. */ MC2Coordinate endPosition( 1338, 1338 ); pathConsumer.addDataPoint( endPosition, 10 * MPSToCmPS ); pathConsumer.finalizeNewData(); /** * Seconds to millisecond conversion unit. */ static const int sToMs = 1000; CHECK( tester.getPosition( 0 ) == checkPosition, reporter ); CHECK( tester.getPosition( 500000 * sToMs ) == endPosition, reporter ); }
void MainMenuState::Update(StateEngine* state, double dt) { // rather than move the player a fixed amount per frame, check for input and move the character in that direction // every frame move by velocity, the input will change the velocity of the player. Vector2 newPos = mPlayer->GetPosition(); if (glfwGetKey(state->GetGLFWWindow(), GLFW_KEY_ESCAPE)) { glfwTerminate(); } if (glfwGetKey(state->GetGLFWWindow(), GLFW_KEY_UP)) { newPos.y += 64 * dt; } if ( glfwGetKey(state->GetGLFWWindow(), GLFW_KEY_DOWN)) { newPos.y -= 64 * dt; } if (glfwGetKey(state->GetGLFWWindow(), GLFW_KEY_LEFT)) { newPos.x -= 64 * dt; } if (glfwGetKey(state->GetGLFWWindow(), GLFW_KEY_RIGHT) ) { newPos.x += 64 * dt; } if (checkPosition(newPos)) { mPlayer->SetPosition(newPos); } }
void DiInputManager::setMousePosition(int _x, int _y) { mCursorX = _x; mCursorY = _y; checkPosition(); }
void OISListener::setInputViewSize(int width,int height) { const OIS::MouseState &ms = mMouse->getMouseState(); ms.width = width; ms.height = height; checkPosition(); }
bool OISListener::mouseMoved(const OIS::MouseEvent& arg) { const OIS::MouseState &ms = mMouse->getMouseState(); mCursorX = ms.X.abs; mCursorY = ms.Y.abs; checkPosition(); return true; }
void InputManager::setMousePosition(int _x, int _y) { //const OIS::MouseState &ms = mMouse->getMouseState(); mCursorX = _x; mCursorY = _y; checkPosition(); }
bool RefereeManager::goTo(unsigned int boardSize, unsigned int& x, unsigned int& y, Vector dir) { if (dir != RefereeManager::NONE && checkPosition(x + _directionArray[dir].direction.x, y + _directionArray[dir].direction.y, boardSize)) { x += _directionArray[dir].direction.x; y += _directionArray[dir].direction.y; return true; } return false; }
/* * incrementPosition * Updates the values of the data block stored in dataLocal and dataLocalNext * to the next values in the data block. */ void U3DBitStreamWriter::incrementPosition() { _dataPosition++; checkPosition(); _data[_dataPosition-1] = _dataLocal; _dataLocal = _dataLocalNext; _dataLocalNext = _data[_dataPosition+1]; }
bool WaypointList::recalcStepList() { if (!checkPosition()) { return false; } steplist.clear(); steplist = _movechar->getStepList(positions.front(),max_fields_for_waypoints); return (!steplist.empty()); }
bool InputManager::mouseMoved(const OIS::MouseEvent& _arg) { mCursorX += _arg.state.X.rel; mCursorY += _arg.state.Y.rel; checkPosition(); injectMouseMove(mCursorX, mCursorY, _arg.state.Z.abs); return true; }
int RobotMemory::lookAround(Position *p,int direction) { Position p2(p->x,p->y); Direction::computePosition(&p2,direction); if (checkPosition(p2)) return getMemoryCell(&p2); else return RobotProcessor::END; }
bool World::setCell(Position* p, WorldObject *object) { if (!checkPosition(p)) return false; else { world[p->x][p->y]->add(object); object->world = this; return true; } }
void InputManager::setInputViewSize(int _width, int _height) { if (mMouse) { const OIS::MouseState& ms = mMouse->getMouseState(); ms.width = _width; ms.height = _height; checkPosition(); } }
Position RobotMemory::minCell(Position p) { Position temp(0,0); Position pmin(p.x,p.y); temp.x = p.x + 1; temp.y = p.y; if(checkPosition(temp)) if ((map2[temp.x][temp.y] < map2[pmin.x][pmin.y]) && (map2[temp.x][temp.y] != -1)) { pmin.x = temp.x; pmin.y = temp.y; } temp.x = p.x - 1; temp.y = p.y; if(checkPosition(temp)) if ((map2[temp.x][temp.y] < map2[pmin.x][pmin.y]) && (map2[temp.x][temp.y] != -1)) { pmin.x = temp.x; pmin.y = temp.y; } temp.x = p.x; temp.y = p.y + 1; if(checkPosition(temp)) if ((map2[temp.x][temp.y] < map2[pmin.x][pmin.y]) && (map2[temp.x][temp.y] != -1)) { pmin.x = temp.x; pmin.y = temp.y; } temp.x = p.x; temp.y = p.y - 1; if(checkPosition(temp)) if ((map2[temp.x][temp.y] < map2[pmin.x][pmin.y]) && (map2[temp.x][temp.y] != -1)) { pmin.x = temp.x; pmin.y = temp.y; } return pmin; }
bool StoneHandler::addStone(Stone *stone, bool toAdd, bool doCheck, Matrix *m, bool koStone) { // CHECK_PTR(stone); // CHECK_PTR(m); if (toAdd) stones->insert(Matrix::coordsToKey(stone->posX(), stone->posY()), stone); if (doCheck) return checkPosition(stone, m, koStone); return true; }
bool DiInputManager::mouseMoved(const OIS::MouseEvent& _arg) { mCursorX += _arg.state.X.rel; mCursorY += _arg.state.Y.rel; checkPosition(); injectMouseMove(_arg.state.X.abs, _arg.state.Y.abs, _arg.state.Z.abs); for (auto it = mMouseMoves.begin(); it != mMouseMoves.end(); ++it) if (it->second) it->second(_arg); return true; }
/** * Adjust position of a sprite * This function adjusts the position of a sprite moving it until * certain criteria is matched. According to priority and control line * data, a sprite may not always appear at the location we specified. * This behaviour is also known as the "Budin-Sonneveld effect". * * @param n view table entry number */ void AgiEngine::fixPosition(int n) { VtEntry *v = &_game.viewTable[n]; int count, dir, size; debugC(4, kDebugLevelSprites, "adjusting view table entry #%d (%d,%d)", n, v->xPos, v->yPos); // test horizon if ((~v->flags & IGNORE_HORIZON) && v->yPos <= _game.horizon) v->yPos = _game.horizon + 1; dir = 0; count = size = 1; while (!checkPosition(v) || checkCollision(v) || !checkPriority(v)) { switch (dir) { case 0: // west v->xPos--; if (--count) continue; dir = 1; break; case 1: // south v->yPos++; if (--count) continue; dir = 2; size++; break; case 2: // east v->xPos++; if (--count) continue; dir = 3; break; case 3: // north v->yPos--; if (--count) continue; dir = 0; size++; break; } count = size; } debugC(4, kDebugLevelSprites, "view table entry #%d position adjusted to (%d,%d)", n, v->xPos, v->yPos); }