void Rover::MoveRover(int startX, int startY, DIRECTION currentDirection, string moveCommand) { currentPosition.x = startX; currentPosition.y = startY; directionFacing = currentDirection; for(char command = 0; command < moveCommand.length(); command++) { switch(moveCommand[command]) { case 'f': moveFront(); break; case 'b': moveBack(); break; case 'l':turnLeft(); break; case 'r':turnRight(); break; default: break; } } }
void SphereCamera::mouseMoved(QMouseEvent *event) { const double x = event->x(); const double y = event->y(); // Rotation handler if (event->buttons() & Qt::RightButton) { if (y - _yOld < 0) { moveDown(_mouseSensitivity*std::abs(y - _yOld)); } else if (y - _yOld > 0) { moveUp(_mouseSensitivity*std::abs(y - _yOld)); } if (x - _xOld < 0) { moveRight(_mouseSensitivity*std::abs(x - _xOld)); } else if (x - _xOld > 0) { moveLeft(_mouseSensitivity*std::abs(x - _xOld)); } } // Zoom handler if (event->buttons() & Qt::MiddleButton) { if (y - _yOld < 0) { moveFront(_mouseSensitivity*std::abs(y - _yOld)); // Zoom + } else if (y - _yOld > 0) { moveBack(_mouseSensitivity*std::abs(y - _yOld)); // Zoom - } } _xOld = x; _yOld = y; }
// move: void move(int order){ if(order == BALL1); if(order == BALL2){ findLine(); turnLeftLine(); moveLine(); } if(order == BALL3){ moveBack1(); turnLeft(); } if(order == BALL4){ moveBack2(); turnBack(); } if(order == STORAGE1){ turnBack(); moveBack(); turnLeft(); } if(order == STORAGE2){ findLine(); turnRight(); } }
void checkForMove(ubyte data){ switch(data){ case turnRight: nxtDisplayTextLine(7, "RIGHT"); moveRight(); break; case turnLeft: nxtDisplayTextLine(7, "LEFT"); moveLeft(); break; case moveForward: nxtDisplayTextLine(7, "FORWARD"); moveF(); break; case moveBackward: nxtDisplayTextLine(7, "BACKWARD"); moveBack(); break; case goBack: comeBack(); break; case stopMoving: nxtDisplayTextLine(7, "!!!!!!STOP!!!!!!!!"); stopAll(); break; default: stopAll(); break; } }
TutorialDialog::TutorialDialog(QWidget *parent) : QDialog(parent), ui(new Ui::TutorialDialog){ ui->setupUi(this); lblText = findChild<QLabel*>("lblText"); tutorials = new QString[5]; tutorials[0] = tr("Hello! Is it your first time here? \nWelcome to Series! Track your favourite TV series, you'll never forget which\nwas the last episode you watched!\n" \ "Thank you for downloading the app, I hope you like it!"); tutorials[1] = tr("In order to add a new series, just click Add new TV series button, it allows\nyou to choose name, espisode and season for a new series!\nA dialog will be showed to do this operation, " \ "just insert name, season and\nepisode (optional) and press Ok. The new series will be displayed immediately."); tutorials[2] = tr("You can update season and episode of every series: just wrtite it into the\ncorrect field and press the Save button."); tutorials[3] = tr("In order to make some changes, press the Modify button.\nYou will be able to change name and positions (the display order)\nof every series. You can also delete them."); tutorials[4] = tr("I hope you like this app! Thank you for downloading it."); index = 0; lblText->setText(tutorials[0]); btnNext = findChild<QPushButton*>("btnNext"); btnBack = findChild<QPushButton*>("btnBack"); btnClose = findChild<QPushButton*>("btnClose"); connect(btnNext, SIGNAL(released()), this, SLOT(moveNext())); connect(btnBack, SIGNAL(released()), this, SLOT(moveBack())); connect(btnClose, SIGNAL(released()), this, SLOT(closeDialog())); btnBack->setEnabled(false); }
void AKeyboardControllerSFML::subStep(double dt) { if(!mEnabled) return; double MouseClickRelaxTime = SECOND / 4.0; double KeyRelaxTime = SECOND / 4.0; static double t = 0; static double t1 = 0; t += dt; t1 += dt; static int x = Game::Window->getSize().x / 2/* + Game::Window->getPosition().x*/; int dx = sf::Mouse::getPosition(*Game::Window).x; if(dx < 0) dx = 0; if(dx > Game::Window->getSize().x) dx = Game::Window->getSize().x; dx = x - dx; sf::Mouse::setPosition(sf::Vector2i(x, 500), *Game::Window); if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { moveForward(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { moveBack(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { moveRight(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { MoveLeft(); } if(dx != 0) { turn((int)(dx /** Abs(dx) / 400*/)); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { turn(RIGHT); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { turn(LEFT); } if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && t > MouseClickRelaxTime) { t = 0; character->mCombatModel->GenerateAction(Strike); } if(t1 > KeyRelaxTime) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) ) { t1 = 0; character->mCombatModel->GenerateAction(HighHit); } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::F)) { t1 = 0; character->mCombatModel->GenerateAction(MediumHit); } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::V)) { t1 = 0; character->mCombatModel->GenerateAction(LowHit); } } }
int main() { prepare(); moveBack(); stop(); return 0; }
void moveBackDistance(int dist) { //Assuming that "dist" is going to be figured out later //"dist" would be the encoder counts until it stops moving; we can make "onefoot" variables etc. later. while(RightEncoderCounts <= dist) { moveBack(fullspeed); } stopWheels(); }
int main(int argc, char* argv[]){ List A = newList(); List B = newList(); List C = NULL; int i; for(i=1; i<=20; i++){ append(A,i); prepend(B,i); } printList(stdout,A); printf("\n"); printList(stdout,B); printf("\n"); for(moveFront(A); index(A)>=0; moveNext(A)){ printf("%d ", get(A)); } printf("\n"); for(moveBack(B); index(B)>=0; movePrev(B)){ printf("%d ", get(B)); } printf("\n"); C = copyList(A); printf("%s\n", equals(A,B)?"true":"false"); printf("%s\n", equals(B,C)?"true":"false"); printf("%s\n", equals(C,A)?"true":"false"); moveFront(A); for(i=0; i<5; i++) moveNext(A); // at index 5 insertBefore(A, -1); // at index 6 for(i=0; i<9; i++) moveNext(A); // at index 15 insertAfter(A, -2); for(i=0; i<5; i++) movePrev(A); // at index 10 delete(A); printList(stdout,A); printf("\n"); printf("%d\n", length(A)); clear(A); printf("%d\n", length(A)); freeList(&A); freeList(&B); freeList(&C); return(0); }
void Tank::moveForward(bool check) { float x1,y1; // новые координаты x1 = x() + cos(degree * (PI / 180))*speed; y1 = y() + sin(degree * (PI / 180))*speed; setPos(x1,y1); head->setPos(x1,y1); if (check == false) { while (isCollide() == true) moveBack(check = true); } }
//-------------------------------------------------------------- void particleSystem::update(){ mouseLocation = ofxVec3f (ofGetAppPtr()->mouseX,ofGetAppPtr()->mouseY,0); mouseX = mouseLocation.x; mouseY = mouseLocation.y; if (mustMoveBack) { moveBack(); mustMoveBack = !mustMoveBack; } if (mustMoveToCenter) { moveToCenter(); //mustMoveToCenter = !mustMoveToCenter; } if (mustMoveRandom) { moveRandom(); //mustMoveRandom = !mustMoveRandom; } /* if (mustMoveRandomH) { moveRandomH(); //mustMoveRandomH = !mustMoveRandomH; } if (mustMoveRandomV) { moveRandomV(); //mustMoveRandomV = !mustMoveRandomV; } */ if (mustMovePaused) { movePaused(); mustMovePaused = !mustMovePaused; } particleIter = particles.begin(); while (particleIter!= particles.end()){ (*particleIter)->update(); ++particleIter; } }
void Match::moveTowardBall(Player *p) { int x = ball->getPosX(), y = ball->getPosY(), px = p->getPosX(), py = p->getPosY(); int team = p->getTeam(); if((py < y && team == 1) || (py > y && team == 2)) { moveLeft(p); } else if((py < y && team == 2) || (py > y && team == 1)) { moveRight(p); } else if((px < x && team == 1) || (px > x && team == 2)) { moveUp(p); } else if((px < x && team == 2) || (px > x && team == 1)) { moveBack(p); } }
void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: case 'q': case 'Q': /* quit the program */ exit(0); break; case ' ': /* toggle between opengl and sofware rendering */ opengl_test = !opengl_test; redisplay(); break; case 'w': moveForward(); redisplay(); break; case 'a': moveLeft(); redisplay(); break; case 'd': moveRight(); redisplay(); break; case 's': moveBack(); redisplay(); break; case 'b': /* toggle bilinear interpolation of the textures */ bilerp_flag = !bilerp_flag; switchTextureFiltering(); redisplay(); default: break; } return; }
void Match::moveToOwnGoal(Player *p) { int x, y; int team = p->getTeam(); int px = p->getPosX(), py = p->getPosY(); if(team == 1) { x = 0; y = 3; } else if(team == 2) { x = Player::FIELD_WIDTH; y = 3; } if((px < x && team == 1) || (px > x && team == 2)) { moveUp(p); } else if((px < x && team == 2) || (px > x && team == 1)) { moveBack(p); } else if((py < y && team == 1) || (py > y && team == 2)) { moveLeft(p); } else if((py < y && team == 2) || (py > y && team == 1)) { moveRight(p); } else if(py == y && px == x) { moveUp(p); } }
void Match::sim(MatchScreen* screen) { this->screen = screen; resetRound(); int timer; for(timer = 0; timer < 180 && roundOver == false; timer+=3) { screen->tick(timer); cout << teamOne->getPlayer(0)->getRole()<< endl; screen->resetKillFeed(); cout<< "TIME: " << timer << endl; setMoveOrder(); for(int i = 0; i < playersToMove.size() && roundOver == false; i++) { Player* p = playersToMove[i]; checkBall(p); setPlayerStatus(p); int act = p->getAction(); //cout << p->getName(); if(act == p->MOVE_UP) { moveUp(p); } else if(act == p->MOVE_DOWN) { moveBack(p); } else if(act == p->MOVE_LEFT) { moveLeft(p); } else if(act == p->MOVE_RIGHT) { moveRight(p); } else if(act == p->PASS) { pass(p); } else if(act == p->MOVE_TO_BALL) { moveTowardBall(p); } else if(act == p->ATTACK) { attack(p); } else if(act == p->MOVE_TO_GOAL) { moveTowardGoal(p); } else if(act == p->MOVE_TO_OWN_GOAL) { moveToOwnGoal(p); } } cout << "BALL TEAM: " << ball->getTeam() << " PLAYER: " << ball->getPlayer() << endl; screen->updateStatScreen(teamOne, teamTwo); screen->displayPlayers(teamOne, teamTwo, ball); QTime dieTime= QTime::currentTime().addSecs(1); while( QTime::currentTime() < dieTime ) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } cout << "GAME OVER TIME: " << timer << endl; if(winningTeam == 1 || winningTeam == 2) { cout << "WINNER: Team " << winningTeam << endl; } else { cout << "DRAW" << endl; } cout << teamOne->getScore() << "-" << teamTwo->getScore() << endl; }
void AutoCloseMessageBox::prepMoveBack() { m_counter = Steps; m_movingState = MovingBack; connect(&m_animationTimer, SIGNAL(timeout()), this, SLOT(moveBack())); m_animationTimer.start(); }
void Player::keyActions() // player действия при нажатии клавиши { game->centerOn(this); lastX = x(); lastY = y(); lastDeg = degree; lastHDeg = hdegree; lastHealth = health; // эффект получения урона (должен стоять перед движением) if (wou) { /* int x1 = centralX(); int y1 = centralY(); wound->setPos(x1-game->width()/2,y1-game->height()/2); */ } // движение вперед, назад if (mf) { moveForward(); if (game->createBots) *bot << "mf "; } if (mb) { moveBack(); if (game->createBots) *bot << "mb "; } // если player вышел за границы if (this->x() < game->dop - pixsize/2 || this->x() > game->scene->width()-game->dop*2 + 20 || this->y() < game->dop - pixsize/2 || this->y() > game->scene->height()-game->dop*2 + 20) { // координата Х в центре экрана int x1 = centralX(); // координата Y в центре экрана int y1 = centralY(); if (out == false) { out = true; outTime = QTime::currentTime(); outTimer = outMaxTime; QString image = ":/images/images/out.png"; caution = new Caution(image, "CAUTION", 5); caution->setPos(x1-200,y1-88); game->scene->addItem(caution); } caution->setPos(x1-200, y1-88); if (outTime.msecsTo(QTime::currentTime()) > 1000) { if (outTimer > 0) { outTimer--; outTime = outTime.addSecs(1); caution->decTimer(); } else { // DIE M**********R! //qDebug() << "you died"; out = false; outTimer = outMaxTime; delete caution; // убить killPlayer(); // BUHAHA } } } else { if (out == true) { out = false; outTimer = outMaxTime; delete caution; } } // универсальный поворот if (rl || rr) { playerRotate(); spin++; } // ты ничего не видел if (rl == false && rr == false) spin = 0; // совершенно ничего if (spin == 540) { QMediaPlayer *sound = new QMediaPlayer(); sound->setMedia(QUrl("qrc:/sounds/sounds/spin.mp3")); sound->play(); } // поворот башни if (hl) { headLeft(); if (game->createBots) *bot << "hl "; } if (hr) { headRight(); if (game->createBots) *bot << "hr "; } // звук поворота башни if ((hr || hl) && tankhrotate->state() == QMediaPlayer::StoppedState) // если звук поворота еще не проигрывался tankhrotate->play(); if (hr == false && hl == false && tankhrotate->state() == QMediaPlayer::PlayingState) tankhrotate->stop(); // стрельба + звуки стрельбы if (fr && fireReady) { playerFire(); reloading = false; // звук перезарядки еще на начат isFiring = 1; // анимация перезарядки reloadAnim = new QLabel(); reloadAnim->setStyleSheet("background-color: transparent;"); QMovie *movie = new QMovie(":/images/images/anim/Reload.gif"); reloadAnim->setMovie(movie); reloadAnim->move(x()+20,y()+20); movie->setScaledSize(QSize(180,180)); //movie->setSpeed(100); movie->start(); QGraphicsProxyWidget *proxy = game->scene->addWidget(reloadAnim); if (game->createBots) *bot << "fr "; } if (fireReady == false) // счетчик для ожидания между выстрелами { fireCount += keyDelay; reloadAnim->move(x()+20,y()+20); } if ((fireCount > fireTime - bulletready->duration()) && reloading == false) // звук перезарядки { reloading = true; // перезарядка уже начата (защита от нескольких) bulletready->play(); } if (fireCount > fireTime) // готовность выстрела { fireReady = true; fireCount = 0; delete reloadAnim; } if (game->createBots) *bot << endl; if (lastX != x() || lastY != y() || lastDeg != degree || lastHDeg != hdegree || lastHealth != health) emit KeyPressed(); if (alive == false || (mf == false && mb == false && rl == false && rr == false && hl == false && hr == false && fr == false && fireReady == true && tankhrotate->state() == QMediaPlayer::StoppedState && out == false)) { action = false; timer->stop(); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); setMinimumSize(450, 480); newGameMenu = menuBar()->addMenu("New game"); optionsMenu = menuBar()->addMenu("Options"); helpMenu = menuBar()->addMenu("Help"); easyGame = new QAction("Easy", this); newGameMenu->addAction(easyGame); connect(easyGame, SIGNAL(triggered()), this, SLOT(generateEasy())); easyGame->setShortcut(Qt::CTRL + Qt::Key_1); mediumGame = new QAction("Medium", this); newGameMenu->addAction(mediumGame); connect(mediumGame, SIGNAL(triggered()), this, SLOT(generateMedium())); mediumGame->setShortcut(Qt::CTRL + Qt::Key_2); hardGame = new QAction("Hard", this); newGameMenu->addAction(hardGame); connect(hardGame, SIGNAL(triggered()), this, SLOT(generateHard())); hardGame->setShortcut(Qt::CTRL + Qt::Key_3); /*randomGame = new QAction("Random", this); newGameMenu->addAction(randomGame); connect(randomGame, SIGNAL(triggered()), this, SLOT(generateRandom())); randomGame->setShortcut(Qt::CTRL + Qt::Key_4);*/ solve = new QAction("Solve", this); optionsMenu->addAction(solve); connect(solve, SIGNAL(triggered()), this, SLOT(showSolution())); solve->setShortcut(Qt::CTRL + Qt::Key_F); stopSolving = new QAction("Stop solving", this); optionsMenu->addAction(stopSolving); connect(stopSolving, SIGNAL(triggered()), this, SLOT(solvingStopped())); stopSolving->setShortcut(Qt::CTRL + Qt::Key_R); previousMove = new QAction("Move back", this); optionsMenu->addAction(previousMove); connect(previousMove, SIGNAL(triggered()), this, SLOT(moveBack())); previousMove->setShortcut(Qt::CTRL + Qt::Key_Z); nextMove = new QAction("Move forward", this); optionsMenu->addAction(nextMove); connect(nextMove, SIGNAL(triggered()), this, SLOT(moveForward())); nextMove->setShortcut(Qt::CTRL + Qt::Key_Y); getInfo = new QAction("Instructions", this); helpMenu->addAction(getInfo); connect(getInfo, SIGNAL(triggered()), this, SLOT(showInstructions())); getInfo->setShortcut(Qt::Key_F1); gview = new Graphics(); setCentralWidget(gview); scene = new QGraphicsScene(); scene->setBackgroundBrush(QColor("#e0e0e0")); gview->setScene(scene); gview->setEnabled(true); counter = new QLabel(); for (int i = 1; i <= 15; i++) tiles[i] = NULL; srand(time(NULL)); gameBoard = NULL; generateEasy(); statusBar()->addWidget(counter); timer = new QTimer(this); timer->setInterval(400); connect(timer, SIGNAL(timeout()), this, SLOT(moveForward())); }
ConstIteratorImpl &operator--() { moveBack(); return *this; }
void moveBackTimed(int t, int speed) { moveBack(speed); wait1Msec(t); stopWheels(); }
ConstIteratorImpl operator--(int) { ConstIteratorImpl temp(pCurrentNode); moveBack(); return temp; }
void Bot::actions() { QString line; QStringList list; line = bot->readLine(); list = line.split(" "); for (int i = 0; i < list.count(); i++) { // если player вышел за границы if (this->x() < game->dop - pixsize/2 || this->x() > game->scene->width()-game->dop*2 + 20 || this->y() < game->dop - pixsize/2 || this->y() > game->scene->height()-game->dop*2 + 20) { if (out == false) { out = true; outTime = QTime::currentTime(); outTimer = outMaxTime; } if (outTime.msecsTo(QTime::currentTime()) > 1000) { if (outTimer > 0) { outTimer--; outTime = outTime.addSecs(1); } else { // DIE M**********R! out = false; outTimer = outMaxTime; killBot(); // BUHAHA } } } else { if (out == true) { out = false; outTimer = outMaxTime; } } if (list[i] == "mf") moveForward(); if (list[i] == "mb") moveBack(); if (list[i] == "rr") rotateRight(); if (list[i] == "rl") rotateLeft(); if (list[i] == "hr") headRight(); if (list[i] == "hl") headLeft(); if (list[i] == "fr") fire(); } if (bot->atEnd()) { switch (mode) { case 0: //timer->stop(); killBot(); break; case 1: bot->reset(); break; } } }