void PlayField::step(int _x, int _y) { if (!canMoveNow()) return; int oldX=levelMap_->xpos(); int oldY=levelMap_->ypos(); int x=oldX, y=oldY; int dx=0, dy=0; if (_x>oldX) dx=1; if (_x<oldX) dx=-1; if (_y>oldY) dy=1; if (_y<oldY) dy=-1; while (!(x==_x && y==_y) && levelMap_->step(x+dx, y+dy)) { x += dx; y += dy; } if (x!=oldX || y!=oldY) { Move *m = new Move(oldX, oldY); m->step(x, y); m->finish(); history_->add(m); m->undo(levelMap_); startMoving(m); } }
void SizeAnchor::mousePressEvent(QGraphicsSceneMouseEvent *event) { setSelected(false); setFlag(ItemIsSelectable, false); templist = fixSelectedItems(true); QGraphicsItem::mousePressEvent(event); emit startMoving(); }
void NMEAGPS::toggleSimulation() { if (boat.isMoving){ stopMoving(); } else { startMoving(); } }
/** * \brief Do it all GUI slot to handle changes to GUI elements */ void focusercontrollerwidget::guiChanged() { if (sender() == ui->positionSpinBox) { int current = _focuser->current(); ui->positionButton->setEnabled(current != ui->positionSpinBox->value()); } if (sender() == ui->positionButton) { int target = ui->positionSpinBox->value(); startMoving(target); } }
void PlayField::mousePressEvent(QMouseEvent *e) { if (!canMoveNow()) return; if (dragInProgress_) { if (e->button() == Qt::LeftButton) dragObject(e->x(), e->y()); else stopDrag(); return; } int x=pixel2x(e->x()); int y=pixel2y(e->y()); if (x < 0 || y < 0 || x >= levelMap_->width() || y >= levelMap_->height()) return; if (e->button() == Qt::LeftButton && pathFinder_.canDrag(x, y)) { changeCursor(Qt::SizeAllCursor); highlightX_ = x; highlightY_ = y; update(x2pixel(x), y2pixel(y), size_, size_); pathFinder_.updatePossibleDestinations(x, y); dragX_ = x2pixel(x); dragY_ = y2pixel(y); mousePosX_ = e->x() - dragX_; mousePosY_ = e->y() - dragY_; dragInProgress_ = true; } Move *m; switch (e->button()) { case Qt::LeftButton: m = pathFinder_.search(levelMap_, x, y); if (m != 0) { history_->add(m); startMoving(m); } break; case Qt::MidButton: undo(); return; break; case Qt::RightButton: push(x, y); break; default: return; } }
void StationKeep::update(const IMC::EstimatedState* state) { double range = getRange(state); switch (m_sks) { case ST_INITIAL: if (range < m_radius) { stopMoving(range); m_sks = ST_ON_STATION; } else { startMoving(range); m_sks = ST_OFF_STATION; } break; case ST_ON_STATION: if (range > m_radius) { startMoving(range); m_sks = ST_OFF_STATION; } break; case ST_OFF_STATION: break; default: std::string str = DTR("invalid station keeping state"); // signal error before throwing exception m_task->signalError(str); throw std::runtime_error(str); break; } }
DesktopDock::DesktopDock(QObject *parent) : QObject(parent) { kdebugf(); createDefaultConfiguration(); DockWindow = new DesktopDockWindow(); MoveMenuAction = new QAction(tr("Move"), DockWindow); connect(MoveMenuAction, SIGNAL(triggered()), DockWindow, SLOT(startMoving())); if (config_file.readBoolEntry("Desktop Dock", "MoveInMenu")) createMenu(); kdebugf2(); }
void PlayField::startMoving(Move *m) { startMoving(new MoveSequence(m, levelMap_)); }
void TREnemy::endAttacking(){ setStaticAnimated(false); startMoving(); }
void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed) { //empty the map clear(); setItemPointersNull(); createMenuItems(); createAboutBoxItems(); createSelectLevelsetFromListItems(); createVictoryItems(); createLevelCompletedItems(); //empty the list of moving items movingItems_.clear(); //empty the list of free slots freeTiles_.clear(); //fill the list of free slots int numberOfXTiles = width() / 40; int numberOfYTiles = height() /40; // qDebug() << numberOfXTiles << " slots in x direction"; // qDebug() << numberOfYTiles << " slots in y rirection"; for (int i = 0; i < numberOfXTiles; i++ ) { for (int j = 0; j < numberOfYTiles; j++) { freeTiles_.append(QPointF(i*40,j*40)); } } //spread the rocks for (int i = 0; i < rocks; i++) { QPointF * pPosition = findRandomFreeSlot(); //If there was no room no point to continue if (pPosition == NULL) break; QPixmap rockPixmap (":/pix/kari.png"); QGraphicsPixmapItem * pRock = addPixmap(rockPixmap); pRock->setData(0,"rock"); pRock->setPos(*pPosition); delete pPosition; } //spread the ghosts ghostsLeft_ = ghosts; spreadGhosts(ghosts); //spread the octopuses QList <Octopus*> octopusList; for (int i=0; i < octopuses; i++) { QPointF * pPosition = findRandomFreeSlot(); //If there was no room no point to continue if (pPosition == NULL) break; QPixmap octopusPixmap (":/pix/tursas.png"); Octopus * pOctopus = new Octopus(octopusPixmap,octopusSpeed); pOctopus->setData(0,"octopus"); pOctopus->setPos(*pPosition); addItem(pOctopus); pOctopus->startMoving(); movingItems_.append(pOctopus); connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving())); connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving())); octopusList.append(pOctopus); delete pPosition; } //place the ship QPointF * pPosition = findRandomFreeSlot(); if (pPosition == NULL) { // Game cannot begin without a free position for ship, so give an error message and return QMessageBox::critical(NULL,"Error! Too many objects on screen","No free space to place the ship. The game cannot start. Please choose another level."); return; } QList<QPixmap> shipImages; shipImages.append(QPixmap(":/pix/laiva.png")); shipImages.append(QPixmap(":/pix/laiva_1aave.png")); shipImages.append(QPixmap(":/pix/laiva_2aave.png")); shipImages.append(QPixmap(":/pix/laiva_3aave.png")); shipImages.append(QPixmap(":/pix/laiva_4aave.png")); shipImages.append(QPixmap(":/pix/laiva_5aave.png")); shipImages.append(QPixmap(":/pix/laiva_6aave.png")); shipImages.append(QPixmap(":/pix/laiva_7aave.png")); shipImages.append(QPixmap(":/pix/laiva_8aave.png")); shipImages.append(QPixmap(":/pix/laiva_9aave.png")); shipImages.append(QPixmap(":/pix/laiva_10aave.png")); Ship * pShip = new Ship (shipImages); pShip->setData(0,"ship"); pShip->setPos(*pPosition); addItem(pShip); connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) ); connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int))); connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool))); pShip->startMoving(); movingItems_.append(pShip); connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving())); connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving())); foreach (Octopus* pOctopus, octopusList) { connect(pOctopus,SIGNAL(droppingGhosts()),pShip,SLOT(dropAllGhosts())); }
void CreatureMover::step(float dt, Direction dir, const TileMap& tm) { // Set direction to move in moveIntention = dir; // Increment the move delay counter if necessary if(moveTimerOn) moveTimer += dt; // Reset timer if no move button is held if(moveIntention == Direction::NONE) { moveTimerOn = false; moveTimer = 0.0f; } // Stop if at the destination if(moving && justReachedDestination() && moveIntention == Direction::NONE) { stopMoving(); } // Stop if at a wall else if(moving && justReachedDestination() && moveIntention != Direction::NONE && !canMoveIn(destination, moveIntention, tm)) { stopMoving(); } // Destination reached but continue in the same direction else if(moving && justReachedDestination() && moveIntention != Direction::NONE && canMoveIn(destination, moveIntention, tm) && moveIntention == lastMove) { resetVelToDest(); } // Destination reached but continue in a different direction else if(moving && justReachedDestination() && moveIntention != Direction::NONE && canMoveIn(destination, moveIntention, tm) && moveIntention != lastMove) { changeDirection(moveIntention); } // Destination not reached so keep going else if(moving && !justReachedDestination()) { setVelToDest(); } // Change direction from stationary, and start movement timer else if(!moveTimerOn && !moving && moveIntention != Direction::NONE && canMoveIn(pos, moveIntention, tm)) { moveTimerOn = true; moveTimer = 0.0f; lastMove = moveIntention; } // Start moving from stationary else if(moveTimerOn && moveTimer >= moveDelay && !moving && moveIntention != Direction::NONE && canMoveIn(pos, moveIntention, tm)) { startMoving(moveIntention); moveTimerOn = false; moveTimer = 0.0f; } // Change direction but don't move else if(!moving && moveIntention != Direction::NONE && !canMoveIn(pos, moveIntention, tm)) { lastMove = moveIntention; } }
void AbstractSelection::mousePressEvent(QMouseEvent *event, ImageArea &imageArea) { mButton = event->button(); mIsMouseMoved = false; if (mIsSelectionExists) { imageArea.setImage(mImageCopy); paint(imageArea); if (mButton == Qt::RightButton) { mIsSelectionAdjusting = true; startAdjusting(imageArea); } if (event->pos().x() > mTopLeftPoint.x() && event->pos().x() < mBottomRightPoint.x() && event->pos().y() > mTopLeftPoint.y() && event->pos().y() < mBottomRightPoint.y()) { if (!mIsSelectionAdjusting) { makeUndoCommand(imageArea); } if (!mIsImageSelected) { startMoving(imageArea); if (!mIsSelectionAdjusting) { mIsImageSelected = true; } } else { drawBorder(imageArea); } mIsSelectionMoving = true; mMoveDiffPoint = mBottomRightPoint - event->pos(); return; } else if (event->pos().x() >= mBottomRightPoint.x() && event->pos().x() <= mBottomRightPoint.x() + 6 && event->pos().y() >= mBottomRightPoint.y() && event->pos().y() <= mBottomRightPoint.y() + 6) { if (!mIsSelectionAdjusting) { makeUndoCommand(imageArea); } startResizing(imageArea); mIsSelectionResizing = true; return; } else { clearSelection(imageArea); } } if (event->button() == Qt::LeftButton) { mBottomRightPoint = mTopLeftPoint = event->pos(); mHeight = mWidth = 0; mImageCopy = *imageArea.getImage(); startSelection(imageArea); mIsPaint = true; } }
/** * \brief Editing the position has finished * * We handle editing of the target position field differently: if the user * chooses to edit the field, then we assume that the result of the edit * is the position he wants to move to, so we initiate the move. We cannot * do this with value changes, because the user might want to peform many * more changes before committing to a new position */ void focusercontrollerwidget::editingFinished() { int target = ui->positionSpinBox->value(); startMoving(target); }
/** * \brief This slot initiates moving to a new target position */ void focusercontrollerwidget::movetoPosition(int target) { displayTarget(target); startMoving(target); }