/** * Moves the given number of items (selected) to the base. */ void CraftEquipmentState::moveLeft(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) cQty = c->getVehicleCount(_items[_sel]); else cQty = c->getItems()->getItem(_items[_sel]); if (0 >= change || 0 >= cQty) return; change = std::min(cQty, change); // Convert vehicle to item if (item->isFixed()) { if(item->getClipSize() != -1) { // First we remove all vehicles because we want to redistribute the ammo RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); i = c->getVehicles()->erase(i); } else ++i; } _base->getItems()->addItem(_items[_sel], cQty); // And now reAdd the count we want to keep in the craft (and redistribute the ammo among them) if (cQty > change) moveRight(cQty - change); } else { _base->getItems()->addItem(_items[_sel], change); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { delete (*i); i = c->getVehicles()->erase(i); if (0 >= --change) break; } else ++i; } } } else { c->getItems()->removeItem(_items[_sel], change); _base->getItems()->addItem(_items[_sel], change); } updateQuantity(); }
void fetchUserInput() { Block orgBlock = currentBlock; if (gameState == 0) { switch (getch()) { case KEY_LEFT: moveLeft(); break; case KEY_RIGHT: moveRight(); break; case KEY_UP: rotateBlock(); break; case KEY_DOWN: moveDown(); break; case 'p': gameState = 1; break; } } else { switch (getch()) { case 'p': if (gameState == 1) { gameState = 0; } break; case 'r': resetGame(); break; case 'q': inGame = 0; break; } } if (isCollision()) { currentBlock = orgBlock; } }
void CDopeFish::moveDope(const int speed) { if(xDirection == LEFT) moveLeft(speed); else moveRight(speed); if(yDirection == UP) moveUp(speed); else moveDown(speed); }
void moveRight(PlannerPertchartNode *pertchartnode) { GList *l = NULL; l = getPertNodeSuccessors(pertchartnode); gint row = planner_pertchart_node_get_row(pertchartnode); gint col = planner_pertchart_node_get_col(pertchartnode); for(;l;l=l->next) { moveRight(l->data); } gint newcol = col + 1; if(isOccupied(row,newcol)) { moveRight(getNodeByRowCol(pertnodes,row,newcol)); } g_object_set(pertchartnode,"col",newcol,NULL); if(newcol == nbCols) { nbCols++; } }
void CBerkFlame::processThrown() { if(blockedd) setAction(A_FLAME_LANDED); // Move normally in the direction if( xDirection == RIGHT ) moveRight( xinertia ); else moveLeft( xinertia ); xinertia--; }
void Object::randMove(int random) { if (frame) { switch(frame) { case 1: moveUp(); break; case 2: moveRight(); break; case 3: moveDown(); break; case 4: moveLeft(); break; } } else { switch(random) { default: moveUp(); break; case 2: moveRight(); break; case 3: moveDown(); break; case 4: moveLeft(); break; } } }
void Player::Update() { if (KeyboardManager::getKeys()->Key_Left) { moveLeft(); } else if (KeyboardManager::getKeys()->Key_Right) { moveRight(); } if (KeyboardManager::getKeys()->Key_Up) { jump(); sm->PlayJumpSound(); } else { count =0; } }
void CMimrock::processWalk() { if(m_hDir == LEFT) moveLeft(WALK_SPEED); else moveRight(WALK_SPEED); if(getActionStatus(A_MIMROCK_SIT)) { setAction(A_MIMROCK_SIT); mp_processState = (void (CStunnable::*)()) &CMimrock::processSit; } }
bool GISManipulator::performMovementLeftMouseButton( const double /*eventTimeDelta*/, const double dx, const double dy ) { // TODO: compute the right amount in order for one mouse's pixel movement to correspond to a movement of one object's pixel osg::Vec3d eye, center, up; getTransformation( eye, center, up ); double altitude = eye[2]; moveRight( -dx * altitude / 8.0 ); moveUp( -dy * altitude / 8.0 ); return true; }
void MainMenuState::handleMousePresses(){ if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){ moveLeft(); } if (sf::Mouse::isButtonPressed(sf::Mouse::Right)){ moveRight(); } }
void AppWindow::keyPressEvent(QKeyEvent *event) { if(m_viewer->gameStatus>=0){ if (event->key() == Qt::Key_Escape) { QCoreApplication::instance()->quit(); } else if (event->key() == Qt::Key_Right) { moveRight(); } else if (event->key() == Qt::Key_Left) { moveLeft(); } else if (event->key() == Qt::Key_Down) { rotateCW(); } else if (event->key() == Qt::Key_Up) { rotateCCW(); } else if (event->key() == Qt::Key_Space) { dropPiece(); } else if (event->key() == Qt::Key_Shift) { shiftPressed(); } } if (event->key() == Qt::Key_1) { slowSpeed(); slowSpeedAct->setChecked(true); }else if (event->key() == Qt::Key_2) { normalSpeed(); normalSpeedAct->setChecked(true); }else if (event->key() == Qt::Key_3) { fastSpeed(); fastSpeedAct->setChecked(true); }else if (event->key() == Qt::Key_W) { wire_frame(); wireAct->setChecked(true); }else if (event->key() == Qt::Key_F) { face(); faceAct->setChecked(true); }else if (event->key() == Qt::Key_M) { multi_coloured(); multiAct->setChecked(true); }else if (event->key() == Qt::Key_N) { new_game(); }else if (event->key() == Qt::Key_R) { reset(); }else if (event->key() == Qt::Key_Q) { close(); }else { QWidget::keyPressEvent(event); } }
/* * At the moment, the main() function is primarily used for testing and * debugging. */ int main() { clearArray(moving); clearArray(fixed); srand(0); /* Initialize random seed */ /* Debugging info */ int j; for (j = 0; j < 10; j++) { fixed[10][j] = 1; } printf("Initial board:\n"); printArray(&fixed, 24, 10); printf("Checking array\n"); checkBoard(); printArray(&fixed, 24, 10); printf("Points: %d \n", points); /* More debugging info */ printf("Printing moving board:\n"); printArray(&moving, 24, 10); printf("Adding random tile:\n"); int k; for (k = 0; k < 7; k++) { setRandomTile(); printArray(&moving, 24, 10); printf("\n\n\n"); clearArray(moving); } /* trying to move left */ setRandomTile(); printArray(&moving,24,10); printf("\n\n\n"); moveLeft(); printArray(&moving,24,10); /*move right*/ printf("\n\n\n"); moveRight(); printArray(&moving,24,10); getchar(); return 0; }
void Quad::rotateRight() { if (shape == SHAPE_O) { Coord temp = {master->getX(), master->getY() }; master->setX(slave3->getX() ); master->setY(slave3->getY() ); slave3->setX(slave2->getX() ); slave3->setY(slave2->getY() ); slave2->setX(slave1->getX() ); slave2->setY(slave1->getY() ); slave1->setX(temp.x); slave1->setY(temp.y); return; //no need to check for changed position } Coord center = {master->getX(), master->getY() }; slave1->rotateAround(center, 1); slave2->rotateAround(center, 1); slave3->rotateAround(center, 1); //first check if we've rotated off the left for (int i = 0; i < 4 && (master->blocked((const Block***)grid) == 2 || slave1->blocked((const Block***)grid) == 2 || slave2->blocked((const Block***)grid) == 2 || slave3->blocked((const Block***)grid) == 2); ++i) moveRight(); //then right for (int i = 0; i < 4 && (master->blocked((const Block***)grid) == 3 || slave1->blocked((const Block***)grid) == 3 || slave2->blocked((const Block***)grid) == 3 || slave3->blocked((const Block***)grid) == 3); ++i) moveLeft(); if (slave1->blocked((const Block***)grid) || slave3->blocked((const Block***)grid) || slave2->blocked((const Block***)grid) ) { slave1->rotateAround(center, 0); slave2->rotateAround(center, 0); slave3->rotateAround(center, 0); } else nextris::audio::play_sound(master->getColor(), master->getX(), master->getY(), SND_ROTATERIGHT); }
void CBloog::processWalking() { // Move normally in the direction if( xDirection == RIGHT ) { //moveRight( m_Action.velX ); moveRight( WALK_SPEED ); } else { //moveLeft( m_Action.velX ); moveLeft( WALK_SPEED ); } }
Sequence * MiniBoss::action2_2() { auto flip = CallFunc::create(this, callfunc_selector(MiniBoss::flipBoss2)); auto attack1 = CallFunc::create(this, callfunc_selector(MiniBoss::attack2_2)); auto attack2 = CallFunc::create(this, callfunc_selector(MiniBoss::attack2_1)); Sequence *action = Sequence::create( moveUp(), attack1, moveUp(), attack1, moveUp(), moveRight(), flip, moveDown(), attack2, moveDown(), attack2, moveDown(), NULL ); return action; }
void CLick::processHop() { // Move left or right according to set direction if(m_hDir == RIGHT) moveRight(LICK_HOP_X_SPEED); else if(m_hDir == LEFT) moveLeft(LICK_HOP_X_SPEED); if(blockedd) { mp_processState = (void (CStunnable::*)()) (&CLick::processLand); setAction( A_LICK_LAND ); } }
void Screen::putchar(char c) { if (c == '\n') { m_x = 0; moveDown(); } else { unsigned int offs = offset(m_x, m_y); m_screen[offs] = iso2scr ((uint_least8_t) c); moveRight(); } }
void Enemy::patrol() { std::discrete_distribution<int> dir_distribution({ 60, 10, 10, 10, 10 }); std::uniform_int_distribution<int> distance_distribution(50, 100); std::uniform_real_distribution<float> wait_time_distribution(1.f, 3.f); Direction dir = static_cast<Direction>(dir_distribution(mt)); int distance = distance_distribution(mt); stop_time = sf::seconds(wait_time_distribution(mt)); //Action selection Action patrol; patrol.thread_id = 1; patrol.action = get_action([this, dir, distance](sf::Time dt) { if (dir == Direction::Left) { moveLeft(distance); } else if (dir == Direction::Right) { moveRight(distance); } else if (dir == Direction::Up) { moveUp(distance); } else if (dir == Direction::Down) { moveDown(distance); } //else if (dir == Direction::None) { std::cout << "Stop time" << stop_time.asSeconds() << std::endl; wait(stop_time); } return false; }); //When we have 2 actions we stop action addition unsigned int max_actions = 2; if (action_tree.threadSize(patrol.thread_id) < max_actions) { pushAction(patrol); } //Action updating, each frame Action patrol_update; patrol_update.thread_id = 0; patrol_update.action = get_action([this](sf::Time dt) { if (getCurrentDirection() == Direction::Left) { goLeft(dt); } else if (getCurrentDirection() == Direction::Right) { goRight(dt); } else if (getCurrentDirection() == Direction::Up) { goUp(dt); } else if (getCurrentDirection() == Direction::Down) { goDown(dt); } return false; }); pushAction(patrol_update); }
void moveXY(int x, int y) { int i; if ( x < 0 ) { if (y < 0) { for ( i = y ; i < 0; i++) { moveDown(); } } else { for ( i = 0 ; i < y; i ++) { moveUp(); } } for ( i = x ; i < 0; i ++) { moveLeft(); } } else { if (y < 0) { for ( i = y ; i < 0; i++) { moveDown(); } } else { for ( i = 0 ; i < y; i ++) { moveUp(); } } for ( i = 0 ; i < y; i ++) { moveRight(); } } }
void ItemBoss::move(float dt) { if (_status == NORMAL) { int randNum = CCRANDOM_0_1() * 60; if (randNum==1 && _bCanJump) { _bCanJump = false; CCCallFunc* callFunc = CCCallFunc::create(this, callfunc_selector(ItemBoss::setAccJumpTrue)); CCJumpBy* jump = CCJumpBy::create(.3f, ccp(0, 0), 20, 1); runAction(CCSequence::create(jump, callFunc, NULL)); } randNum = CCRANDOM_0_1() * 60; if (randNum == 1) { //// 发射子弹 //ItemBullet* bullet = ItemBullet::create(); //getMap()->addChild(bullet); // 设置bullet的位置 // 设置bullet的方向 // 让bullet运动 } if (_dir == Common::LEFT) { moveLeft(dt); if (getPositionX() < _left) { _dir = Common::RIGHT; updateStatus(); } } else { moveRight(dt); if (getPositionX() > _right) { _dir = Common::LEFT; updateStatus(); } } } else if (_status == DROPPING) { moveDown(dt); } }
void CWaterMine::processMove() { performCollisions(); if(yDirection) { const Uint16 blockerUp = mp_Map->getPlaneDataAt(2, getXMidPos(), getYUpPos()); const Uint16 blockerDown = mp_Map->getPlaneDataAt(2, getXMidPos(), getYDownPos()); // If there is a blocker, block the Watermine if( blockerUp == 31 ) blockedu = true; if( blockerDown == 31 ) blockedd = true; // If the mine is really blocked, change the direction if(blockedd) yDirection = UP; else if(blockedu) yDirection = DOWN; if(yDirection == DOWN) moveDown(MINE_SPEED); else moveUp(MINE_SPEED); } else { const Uint16 blockerLeft = mp_Map->getPlaneDataAt(2, getXLeftPos(), getYMidPos()); const Uint16 blockerRight = mp_Map->getPlaneDataAt(2, getXRightPos(), getYMidPos()); // If there is a blocker, block the Watermine if( blockerLeft == 31 ) blockedl = true; if( blockerRight == 31 ) blockedr = true; // If the mine is really blocked, change the direction if(blockedl) xDirection = RIGHT; else if(blockedr) xDirection = LEFT; if(xDirection == LEFT) moveLeft(MINE_SPEED); else moveRight(MINE_SPEED); } }
void startMaze(char **maze, int *x, int *y, int mazeSize){ if(*x == 0){ moveRight(maze, x, y); } if(*x == (mazeSize - 1)){ moveLeft(maze, x, y); } if(*y == 0){ moveDown(maze, x, y); } if(*y == (mazeSize - 1)){ moveUp(maze, x, y); } }
void EtherMenu::SetFocusToCard(InfoCard *card) { int start_pos = priority_list_.count() % 2 == 1 ? priority_list_.count() / 2 : priority_list_.count() / 2 - 1; int position = priority_list_.indexOf(objects_.indexOf(card)); int move_count = start_pos - position; if (move_count == 0) return; else if (move_count > 0) for (;move_count > 0; move_count--) moveRight(); else if (move_count < 0) for (;move_count < 0; move_count++) moveLeft(); }
void roboMeet() { bool reachedZero = false; while( !meet() ) { if(reachedZero) { moveLeft(); moveLeft(); } else { moveLeft(); moveLeft(); moveRight(); } if( at-zero() ) { reachedZero = true; } } }
void moveRight(char *game, int from, int level, int pos, int ccc, int len, int stp) { if ((((pos % 6) + len) < 6) && (game[ pos + len ] == '_')) { game[ pos ] = '_'; game[ pos + len ] = ccc; storeGame(game, from, level, ccc, 'r', stp); if (solved) return; moveRight(game, from, level, pos + 1, ccc, len, stp + 1); game[ pos ] = ccc; game[ pos + len ] = '_'; } }
void Monster::move(int frameCount) { if((frameCount % 60) == 0) { Direction = rand() % 4; } if(Direction == UP) { setDirection(UP); if((frameCount % 60) != 0) { moveUp(); } } else if(Direction == LEFT) { setDirection(LEFT); if((frameCount % 60) != 0) { moveLeft(); } } else if(Direction == DOWN) { setDirection(DOWN); if((frameCount % 60) != 0) { moveDown(); } } else if(Direction == RIGHT) { setDirection(RIGHT); if((frameCount % 60) != 0) { moveRight(); } } else { } }
void CRay::moveinAir() { if (m_HorDir == RIGHT) { // don't go through bonklethal tiles, even if they're not solid // (for the arms on mortimer's machine) if (blockedr) { state = RAY_STATE_SETZAPZOT; canbezapped = false; if (onscreen) playSound(SOUND_SHOT_HIT); } moveRight(m_speed); } else if (m_HorDir == LEFT) { /*if (TileProperties.at(mp_Map->at((getXPosition()-1)>>CSF, (getYPosition()+1)>>CSF)).behaviour == 1) hitlethal = true; else if (TileProperties.at(mp_Map->at((getXPosition()-1)>>CSF, ((getYPosition()>>(CSF-4))+(raysprite.getHeight()-1))>>(CSF-4))).behaviour == 1) hitlethal = true; else hitlethal = false;*/ if (blockedl) { state = RAY_STATE_SETZAPZOT; canbezapped = false; if (onscreen) playSound(SOUND_SHOT_HIT); } moveLeft(m_speed); } else if (m_VertDir == DOWN) { if (blockedd || blockedu) { state = RAY_STATE_SETZAPZOT; canbezapped = false; if (onscreen) playSound(SOUND_SHOT_HIT); } moveDown(m_speed); } }
void CMimrock::processWalk() { if(xDirection == LEFT) { moveLeft(WALK_SPEED); } else { moveRight(WALK_SPEED); } if(getActionStatus(A_MIMROCK_SIT)) { setAction(A_MIMROCK_SIT); } }
/* * COMMAND CENTRE */ String Controller::doCommand(String string) { //Log.Debug("Command: %s", string); String s = NULL; int i = (int) stringToTime(string); char command; if (string.length() > 0) { command = string.charAt(0); } else { return s; } switch (command) { case 'A': // status request only break; case 'L': // move left moveLeft(i); break; case 'R': // move right moveRight(i); break; case 'I': // update interval setInterval(i); break; case 'J': // update step size setStepSize(i); break; case 'S': // update start/end/rewind times setTimes(string); break; case 'T': // update date and time setTimestamp(stringToTime(string)); break; default: // returns NULL return s; } s = getStatus(); return s; }
void CRoboRed::processMoving() { // Move normally in the direction if( xDirection == RIGHT ) { moveRight( moveHorizSpeed ); } else { moveLeft( moveHorizSpeed ); } if(getProbability(60) && mKeenNearby) { setAction(A_RED_PAUSE); } }