예제 #1
0
void IceBlock::makeMove(GameDirection direction){
	if (getState() == BoxStateMoving) return;
	CCPoint currentPos = getTileMapPosition();
	CCPoint vector = GAMEUTILS->getTiledVectorFromDirection(direction);
	CCPoint point = ccp(currentPos.x + vector.x, currentPos.y - vector.y);
	// Jest �ciana
	if (GAMEUTILS->isWallPresent(point)){
		stopMoving();
		type = GAME_TYPE_BOX;
		properities |= PPUSHABLE;
	}
	GameSprite* obj = GAMEUTILS->objectAt(point, this);
	if (obj ){

		if ((obj->properities & PSHOOTABLE) && type == GAME_TYPE_BULLET){
			obj->getKill();
		}

		//this->hit(direction, obj);

		stopMoving();
		//fixPosition();
		type = GAME_TYPE_BOX;
		properities |= PPUSHABLE;
	}
	else{
		setState(BoxStateMoving);
		GameSprite::makeMove(direction);
		this->direction = direction;
	}



}
예제 #2
0
파일: PlayField.cpp 프로젝트: KDE/ksokoban
void
PlayField::timerEvent(QTimerEvent *) {
  assert(moveInProgress_);
  if (moveSequence_ == 0) {
    QAbstractEventDispatcher::instance()->unregisterTimers(this);
    moveInProgress_ = false;
    return;
  }

  bool more=false;

  mapDelta_->start();
  if (animDelay_) more = moveSequence_->next();
  else {
    while (moveSequence_->next()) if (levelMap_->completed()) break;
    more = true;   // FIXME: clean this up
    stopMoving();
  }
  mapDelta_->end();

  if (more) {
    paintDelta();
    if (levelMap_->completed()) {
      stopMoving();
      ModalLabel::message(i18n("Level completed"), this);
      nextLevel();
      return;
    }
  } else stopMoving();
}
예제 #3
0
void Robot::calibrateGrid()
{
  int i = 0;
  for(i = 0; i < 25; i++)
  {
    gridSensors.calibrate();
    delay(20); 
  }

  turnTo(NWEST);
  delay(500);
  moveTicks(AFEW, APPROACHSPEED);
  stopMoving(APPROACHSPEED);

  for(i = 0; i < 25; i++)
  {
    gridSensors.calibrate();
    delay(20); 
  }

  moveTicks(-AFEW, APPROACHSPEED);
  stopMoving(APPROACHSPEED, true);
  delay(500);
  turnTo(NORTH);
  delay(500);
}
예제 #4
0
// TODO: This function may need to be re-coded because it is too specific for
// the code we're on. It might be best to have something like this in the AI part.
// It might be best to just have openClaws and closeClaws.
void Robot::dropBlock()
{
  unsigned int sensors[8];
  bool atPoint = false;
  bool delivered = false;
  int ticks_moved=0;

  turnTo(SOUTH);
  movePoints(1);
  moveTicks(60, 25);
  stopMoving(25);
  openClaws();
  delay(300);
  moveTicks(-50, 25);
  stopMoving(25, true);
  delay(300);
  turnTo(NORTH);
  delay(300);
  movePoints(1);

  delay(500);


  /*while (!delivered)
    {
    ticks_moved = 0;
    while ((ticks_moved < 70) && !atPoint)
    {
  //Go Forward
  moveTicks(2, 25);  
  ticks_moved = ticks_moved + wheelEnc.getCountsM1();
  gridSensors.readCalibrated(sensors, QTR_EMITTERS_ON);

  if ((sensors[0] < SENSORBLACK) && (sensors[7] < SENSORBLACK) && (ticks_moved >10))
  {
  motorStop();
  delay(2000);
  atPoint = true;
  servo(SERVO_RIGHT,30);  //Check required values.
  servo(SERVO_LEFT,80);
  moveTicks(-ticks_moved, 20);
  delivered = true;
  }

  }
  motorStop();
  delay(2000);
  atPoint = false;
  moveTicks(-ticks_moved, 20);


  }*/
}
예제 #5
0
void SizeAnchor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	fixSelectedItems(false, templist);
	QGraphicsItem::mouseReleaseEvent(event);
	setFlag(ItemIsSelectable, true);
	emit stopMoving();
}
예제 #6
0
void IceBlock::hit(GameDirection hitDirection, GameSprite *object){
	if (!object)return;
	if (type == GAME_TYPE_BOX){
		Box::hit(hitDirection, object);
		return;
	}
	if (currentState == -1)
		return;
	if (object->getType() == GAME_TYPE_ROBBO
		|| object->getType() == GAME_TYPE_QUESTIONMARK || object->getType() == GAME_TYPE_BULLET)
	{
		object->getKill();
	}
	else if (object->properities & PSHOOTABLE)
	{

		object->getKill();


		stopMoving();
		//fixPosition();

	}

}
예제 #7
0
파일: player.cpp 프로젝트: KDE/granatier
void Player::init()
{
    updateDirection();
    stopMoving();
    int row = m_arena->getRowFromY(m_y);
    int column = m_arena->getColFromX(m_x);
    m_arena->setCellElement(row, column, this);
}
예제 #8
0
파일: nmeagps.cpp 프로젝트: UpWind/devel
void NMEAGPS::toggleSimulation() {
    if (boat.isMoving){
        stopMoving();

    } else {
        startMoving();
    }
}
예제 #9
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    mainLayout = new QVBoxLayout();
    window = new QWidget();

    gameView = new GameView();
    gameModel = new GameModel();
    topbar = new Topbar();

    QObject::connect(gameModel, SIGNAL(sig_createMap(std::vector<std::shared_ptr<Tile> >)),
                     gameView, SLOT(createWorldMap(std::vector<std::shared_ptr<Tile> >)));
    QObject::connect(gameModel, SIGNAL(sig_putEnemies(std::vector<std::shared_ptr<Enemy> >)),
                     gameView, SLOT(createEnemies(std::vector<std::shared_ptr<Enemy> >)));
    QObject::connect(gameModel, SIGNAL(sig_putHealPck(std::vector<std::shared_ptr<Tile> >)),
                      gameView, SLOT(createHealPcks(std::vector<std::shared_ptr<Tile> >)));
    QObject::connect(gameModel, SIGNAL(sig_getBoundary(int,int)),
                     gameView, SLOT(setBoundary(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_createProta(int,int)),
                     gameView, SLOT(createProta(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaPos(int,int)),
                     gameView, SLOT(changeProtaPos(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaHealth(float)),
                     gameView, SLOT(changeProtaHealth(float)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaEnergy(float)),
                     gameView, SLOT(changeProtaEnergy(float)));
    QObject::connect(gameModel,SIGNAL(sig_fightEnemy(std::shared_ptr<Enemy>)),
                     gameView,SLOT(fightEnemy(std::shared_ptr<Enemy>)));
    QObject::connect(gameModel,SIGNAL(sig_recovery(std::shared_ptr<Tile>)),
                     gameView,SLOT(recovery(std::shared_ptr<Tile>)));
    QObject::connect(gameModel, SIGNAL(sig_findPath(std::vector<std::shared_ptr<PathNode>>)),
                     gameView, SLOT(highlightPath(std::vector<std::shared_ptr<PathNode>>)));

    QObject::connect(gameView, SIGNAL(sig_changeProtaPosbyMouse(int,int)),
                     gameModel, SLOT(goDestinationByMouse(int,int)));
    QObject::connect(gameModel,SIGNAL(sig_stopMoving()),
                     gameView, SLOT(stopMoving()));

    gameModel->initialGame();
    mainLayout->addWidget(gameView);

//------------------------test-------------------
    //gameModel->doAnimation(0,0,24,16);
   // gameView->removeHighlight();



      mainLayout->addWidget(topbar);
      QObject::connect(gameModel,SIGNAL(sig_changeProtaHealth(float)),
                       topbar,SLOT(changeHealthValue(float)));
      QObject::connect(gameModel,SIGNAL(sig_changeProtaEnergy(float)),
                       topbar,SLOT(changeEnergyValue(float)));
      QObject::connect(topbar->getAnimation_slider(),SIGNAL(valueChanged(int)),
                        gameModel,SLOT(setAnimationTime(int)));
    window->setLayout(mainLayout);
    this->setCentralWidget(window);

}
예제 #10
0
/*!
	Changes the moving status (true or false).
	Only changed to true if character starts moving to a new destination.
*/
void CharacterMovement::setMoving( bool startMoving )
{
	if( startMoving )
	{
		moveTo();
	}
	else
	{
		stopMoving();
	}
}
예제 #11
0
파일: PlayField.cpp 프로젝트: KDE/ksokoban
void
PlayField::levelChange() {
  stopMoving();
  stopDrag();
  history_->clear();
  setSize(width(), height());

  updateLevelXpm();
  updateStepsXpm();
  updatePushesXpm();
  highlight();
}
예제 #12
0
void AFRCameraController::makeMovementStep()
{
  if (stepsToDest > 0)
  {
    FVector currentLoc = camera->GetActorLocation();
    camera->SetActorRelativeLocation(currentLoc + routeStep);
    stepsToDest--;
  }
  else
  {
    stopMoving();
  }
}
/**
*	@brief Takes the resident to hospital 
*	(non-doctor-induced emergency, despite the function name...)
*/
void Nurse2::doHospitalise(se306_project1::ResidentMsg msg) {

	double distanceFromCheckpoint = sqrt(pow((msg.currentCheckpointX - px),2) + pow((msg.currentCheckpointY - py),2));

	move(msg.currentCheckpoint);
	if (distanceFromCheckpoint < 15) { // next to nurse1
		stopMoving();
        readyToHospitalise = true;
	}
	
	if (readyToHospitalise == true) { // go back outside once Nurse is next to resident
		move("Nurse2Origin");
	}
}
예제 #14
0
void GLWidget::releaseInput()
{
	if(!mouseGrabbed) return;

	QCursor::setPos(grabPos);
	releaseMouse();
	releaseKeyboard();
	setMouseTracking(false);

	sceneTimer->stop();
	stopMoving();

	mouseGrabbed = false;
}
예제 #15
0
//едем назад
void ARobotic::moveBackward(uint8_t speed, uint16_t distance){

	digitalWrite(DIRL,LOW);
	digitalWrite(DIRR,LOW);
	if (speed){
		setRightWheelSpeed(speed);
		setLeftWheelSpeed(speed);
	}

	//обработка distance
	if (distance){
		waitingDistance4LM(distance);
		stopMoving();
	}
}
예제 #16
0
파일: Game.cpp 프로젝트: jhpy1024/glfPong
void Game::specialKeyReleased(int key, int x, int y)
{
    switch (key)
    {
    case GLUT_KEY_UP:
    case GLUT_KEY_DOWN:
    {
        auto paddlePtr = static_cast<Paddle*>(m_Entities["Paddle"].get());
        paddlePtr->stopMoving();
    }
    break;
    default:
        break;
    }
}
예제 #17
0
GLWidget::GLWidget(QWidget * parent)
	: QGLWidget(parent)
{
	mouseGrabbed= false;
	movedWhileGrabbed= false;

	// movingTo initialization
	stopMoving();

	// sceneTimer is connected to sceneTimerEvent (private slot)
	sceneTimer= new QTimer(this);
	connect(sceneTimer, SIGNAL(timeout()), this, SLOT(sceneTimerEvent()));

	makeGrid(0.0,0.1,2.0);

	fileRender= false;
}
예제 #18
0
void Character::initNodePath(Player *player,
							 CollisionTraverser *traverser,
							 CollisionTraverser *traverserQueue,
							 CollisionHandlerQueue *colliHandlerQueue,
							 Filename charDir,
							 Filename charWalkDir,
							 Filename charStandDir,
							 std::string lodNodename,
							 std::string colliNodeName) {
	LODNode *lod = new LODNode(lodNodename);
	NodePath lodNodePath(lod);
	lodNodePath.reparent_to(player->getWindow()->get_render());
	lod->add_switch(50, 0);

	// load character and place on the grounds
	NodePath character = player->getWindow()->load_model(player->getPanda()->get_models(), charDir);
	character.reparent_to(lodNodePath);
	character.set_scale(0.203, 0.203, 0.203);

	// add collision node to character
	CollisionNode *collNode = new CollisionNode(colliNodeName);
	collNode->add_solid(new CollisionSphere(0, 0, 0, 2.5));
	NodePath fromObj = character.attach_new_node(collNode);
	CollisionHandlerPusher *colliHandlerPusher = new CollisionHandlerPusher();
	colliHandlerPusher->add_collider(fromObj, character);

	traverser->add_collider(fromObj, colliHandlerPusher);
	traverserQueue->add_collider(fromObj, colliHandlerQueue);

	// Load the walk animation
	player->getWindow()->load_model(character, charStandDir);
	player->getWindow()->load_model(character, charWalkDir);

	// bind animation
	auto_bind(character.node(), animCollection);

	stopMoving();
	nodePath = character;
	
	standAnimName = animCollection.get_anim_name(0);
	walkAnimName = animCollection.get_anim_name(1);

	// get animation names
	//for(int i = 0; i < animCollection.get_num_anims(); i++)
	//	cout << animCollection.get_anim_name(i) << endl;
}
예제 #19
0
파일: sliderbase.cpp 프로젝트: Adamiko/los
void SliderBase::mousePressEvent(QMouseEvent *e)
{
	QPoint p = e->pos();
	const Qt::MouseButton button = e->button();
	d_timerTick = 0;

	getScrollMode(p, button, d_scrollMode, d_direction);
	stopMoving();

	switch (d_scrollMode)
	{
		case ScrPage:
		case ScrTimer:
			d_mouseOffset = 0;
			DoubleRange::incPages(d_direction);
			emit sliderMoved(value(), _id);
			emit sliderMoved((int)value(), _id);
			d_tmrID = startTimer(qwtMax(250, 2 * d_updTime));
			break;

		case ScrMouse:
			d_speed = 0;
			if (button == Qt::RightButton)
			{
				emit sliderRightClicked(e->globalPos(), _id);
				break;
			}
			d_time.start();
			if (_cursorHoming && button == Qt::LeftButton)
			{
				_ignoreMouseMove = true;
				d_mouseOffset = 0.0;
			}
			else
				d_mouseOffset = getValue(p) - value();

			emit sliderPressed(_id);
			break;

		default:
			d_mouseOffset = 0;
			d_direction = 0;
			break;
	}
}
예제 #20
0
void CharacterMovement::moveTo(QVector3D destination)
{
	// new destination
	_destination = destination;
	stopMoving();
	//
	qreal dist = UtilFunctions::calculateDistance(_position, destination);
	if (dist <= _minDistance)
	{
		qWarning() << "[CharacterMovement::moveTo(QVector3D)] Distance to next point is smaller than the minimum distance variable." << dist;
		qDebug() << "[CharacterMovement::moveTo(QVector3D)] - Emited stopedMoving";
		emit stopedMoving();
	}
	else
	{
		moveTo();
	}
}
예제 #21
0
    void
    StationKeep::updatePathControl(const IMC::PathControlState* pcs)
    {
      double range = Math::norm(pcs->x, pcs->y);

      switch (m_sks)
      {
        case ST_OFF_STATION:
          if (pcs->flags & IMC::PathControlState::FL_NEAR)
          {
            stopMoving(range);
            m_sks = ST_ON_STATION;
          }
          break;
        default:
          break;
      }
    }
예제 #22
0
void IceBlock::update(){
	if (currentState == -1)
		return;
	if (type == GAME_TYPE_BOX)return;

	GameSprite* obj = GAMEUTILS->objectAt(getTileMapPosition(), this);
	if (obj&& obj->properities & PSHOOTABLE)
	{
		//this->hit(direction, obj);

		obj->getKill();


		stopMoving();
		//fixPosition();
		type = GAME_TYPE_BOX;
		properities |= PPUSHABLE;
	}

}
예제 #23
0
    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;
      }
    }
예제 #24
0
//поворот через правое колесо на определенный градус
void ARobotic::turnRight(int degree){
	
	//поворачиваем вперед...
	if (degree>0){
		digitalWrite(DIRL,HIGH);
	}else
		digitalWrite(DIRL,LOW);//...или назад

	//скорость разворота
	uint8_t speed = 220;
	//длина дуги
	uint16_t ArcLen = round(PI * _ar_width * degree / 1800);

	//если развернуться нужно на мешьше оборота колеса, делаем скорость ниже
	if (ArcLen < 20){
		speed = 200;
	}

	analogWrite(ENL,speed);
	analogWrite(ENR,0);

	waitingDistance4LM(ArcLen);
	stopMoving();
}
예제 #25
0
파일: PlayField.cpp 프로젝트: KDE/ksokoban
void
PlayField::keyPressEvent(QKeyEvent * e) {
  int x=levelMap_->xpos();
  int y=levelMap_->ypos();

  switch (e->key()) {
  case Qt::Key_Up:
    if (e->state() & Qt::ControlModifier) step(x, 0);
    else if (e->state() & Qt::ShiftModifier) push(x, 0);
    else push(x, y-1);
    break;
  case Qt::Key_Down:
    if (e->state() & Qt::ControlModifier) step(x, MAX_Y);
    else if (e->state() & Qt::ShiftModifier) push(x, MAX_Y);
    else push(x, y+1);
    break;
  case Qt::Key_Left:
    if (e->state() & Qt::ControlModifier) step(0, y);
    else if (e->state() & Qt::ShiftModifier) push(0, y);
    else push(x-1, y);
    break;
  case Qt::Key_Right:
    if (e->state() & Qt::ControlModifier) step(MAX_X, y);
    else if (e->state() & Qt::ShiftModifier) push(MAX_X, y);
    else push(x+1, y);
    break;

  case Qt::Key_Q:
    KApplication::kApplication()->closeAllWindows();
    break;

  case Qt::Key_Backspace:
  case Qt::Key_Delete:
    if (e->state() & Qt::ControlModifier) redo();
    else undo();
    break;

#if 0
  case Qt::Key_X:
    levelMap_->random();
    levelChange();
    repaint(false);
    break;

  case Qt::Key_R:
    level(levelMap_->level());
    return;
    break;
  case Qt::Key_N:
    nextLevel();
    return;
    break;
  case Qt::Key_P:
    previousLevel();
    return;
    break;
  case Qt::Key_U:
    undo();
    return;
    break;
  case Qt::Key_I:
    history_->redo(levelMap_);
    repaint(false);
    return;
    break;

  case Qt::Key_S:
    {
      QString buf;
      history_->save(buf);
      printf("%s\n", (char *) buf);
    }
    return;
    break;

  case Qt::Key_L:
    stopMoving();
    history_->clear();
    level(levelMap_->level());
    {
      char buf[4096]="r1*D1*D1*r1*@r1*D1*";
      //scanf("%s", buf);
      history_->load(levelMap_, buf);
    }
    updateStepsXpm();
    updatePushesXpm();
    repaint(false);
    return;
    break;
#endif


  case Qt::Key_Print:
    HtmlPrinter::printHtml(levelMap_);
    break;

  default:
    e->ignore();
    return;
    break;
  }
}
예제 #26
0
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;
	}
}
예제 #27
0
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()));
    }
예제 #28
0
	void Animal::switchToDead()
	{
		stopMoving();
		texturedQuad(_dead);
		_isDead = true;
	}
void iAnt_controller::ControlStep() {
    LOG << GetHeading() << endl << '\n';
    
    /////////ADDED///////////////
    CVector3 position3d(GetPosition().GetX(), GetPosition().GetY(), 0.02);
    CVector3 target3d(GetTarget().GetX(), GetTarget().GetY(), 0.02);
    CRay3 targetRay(target3d, position3d);
    data->TargetRayList.push_back(targetRay);

    //[ + + ] move foward
    //motorActuator->SetLinearVelocity(RobotForwardSpeed, RobotForwardSpeed);
    //[ + - ] rotates to the right
    //motorActuator->SetLinearVelocity(RobotForwardSpeed, -RobotForwardSpeed);
    //[ +  0] spins left
    //motorActuator->SetLinearVelocity(RobotForwardSpeed, 0.0);
    //[ 0  +] spins right
    //motorActuator->SetLinearVelocity(RobotForwardSpeed, 0.0);
    
    
	east();
    //west();
    //north();
    //south();
    

    //char* pat = LinearSpiral();
    //out << "pat" << *pat << '\n';
    //free(pat);

    //checkDistanceX();   
    // if(west() == true){ 
    //     motorActuator->SetLinearVelocity(stopMoving(checkDistanceX()), stopMoving(checkDistanceX()));
    //     //motorActuator->SetLinearVelocity(RobotForwardSpeed,RobotForwardSpeed);
    // } 
    // if(west() == true) {
    //     motorActuator->SetLinearVelocity(RobotForwardSpeed,RobotForwardSpeed);
    // }
//    if(east() == true){
//        motorActuator->SetLinearVelocity(RobotForwardSpeed, RobotForwardSpeed);     
//    }


    //UNCONMMENT
     bool stop=checkDistanceY();
     cout << "stop: " << stop << '\n';
     stopMoving(stop);
     motorActuator->SetLinearVelocity(stopMoving(stop), stopMoving(stop));
     if (stop)
     {    
         east(); 
         motorActuator->SetLinearVelocity(0.0,RobotForwardSpeed);
         if(east() == true) {
             motorActuator->SetLinearVelocity(RobotForwardSpeed,RobotForwardSpeed);
         }
         stop = false;
     } 



    //motorActuator->SetLinearVelocity(stopMoving(stop), stopMoving(stop));
    //north();
    // if(north() == true) { 
    //     //motorActuator->SetLinearVelocity(RobotForwardSpeed, RobotForwardSpeed); 
    //      motorActuator->SetLinearVelocity(stopMoving(checkDistanceY()), stopMoving(checkDistanceY()));
    // }
    // if(south() == true) {
    //     checkDistanceY();  
    //     motorActuator->SetLinearVelocity(RobotForwardSpeed, RobotForwardSpeed); 
        
    // } 
    
}
예제 #30
0
// movePoints has the robot move the number of points told.
// Positive is forward, negative is backwards.
// Slowing down does not happen until we have moved the number of points told.
// If you want to be safe, move one point. Todd suggests you take a risk.
void Robot::movePoints(int numberOfPoints, bool useBothSensors)
{
  bool forward = true;
  // Move the number of points. We're not going to slow down here.
  if (numberOfPoints < 0)
  {
    numberOfPoints = -numberOfPoints;
    forward = false;
  }

  for (int i = 0; i < numberOfPoints; i++)
  {
    switch (myDirection)
    {
      case NEAST:
      case SEAST:
      case NWEST:
      case SWEST:
        if (forward)
        {
          moveTicks(DIAGONALTICKS, STRAIGHTSPEED);
        }
        else
        {
          moveTicks(-DIAGONALTICKS, STRAIGHTSPEED);
        }
        break;

      default:
        if (forward)
        {
          moveTicks(ORTHOGONALTICKS, STRAIGHTSPEED);
        }
        else
        {
          moveTicks(-ORTHOGONALTICKS, STRAIGHTSPEED);
        }
        break;
    }
    moveTillPoint(STRAIGHTSPEED, forward, useBothSensors);
  }
  stopMoving(STRAIGHTSPEED);

  unsigned int sensors[8];
  gridSensors.readCalibrated(sensors, QTR_EMITTERS_ON);
  delay(20);

  // TODO WE NEED TO LOOK INTO THIS WAY MORE
  // This code is being written assuming that our gridSensors have the right most sensor
  // at sensor[0] and the left most sensor at sensor[8]  

  // Turn the error adjust off. 
  //errorAdjust = false;
/*  switch (myDirection)
  {
    // If we're facing north east
    case NEAST:
      // If our right sensor is on the line, but left is not.
      if ((sensors[0] < SENSORBLACK) && (sensors[7] > SENSORBLACK))
      {
        // Then we turn north.
//        turnTo(NORTH);
//        delay(10);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
//        delay(10);
        // Turn east.
//        turnTo(EAST);
//        delay(10);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
        delay(10);
      }
      // If our left sensor is on the line, but right is not.
      else if ((sensors[0] > SENSORBLACK) && (sensors[7] < SENSORBLACK))
      {
        // Then we turn east.
        turnTo(EAST);
        delay(10);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        delay(10);
        // Turn north.
        turnTo(NORTH);
        delay(10);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
        delay(10);
      }
      // If both sensors are on the line.
      else
      {
        // Move forward a few ticks
        moveTicks(AFEW, APPROACHSPEED);
        stopMoving(APPROACHSPEED);
      }
      break;
    case SEAST:
      // If our right sensor is on the line, but left is not.
      if ((sensors[0] < SENSORBLACK) && (sensors[7] > SENSORBLACK))
      {
        // Then we turn south.
        turnTo(SOUTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn east.
        turnTo(EAST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If our left sensor is on the line, but right
      // is not.
      else if ((sensors[0] > SENSORBLACK) && (sensors[7] < SENSORBLACK))
      {
        // Then we turn east.
        turnTo(EAST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn south.
        turnTo(SOUTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If both sensors are on the line.
      else
      {
        // Move forward a few ticks
        moveTicks(AFEW, APPROACHSPEED);
        stopMoving(APPROACHSPEED);
      }    
      break;
    case NWEST:
      // If our right sensor is on the line, but left is not.
      if ((sensors[0] < SENSORBLACK) && (sensors[7] > SENSORBLACK))
      {
        // Then we turn north.
        turnTo(NORTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn west.
        turnTo(WEST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If our left sensor is on the line, but right is not.
      else if ((sensors[0] > SENSORBLACK) && (sensors[7] < SENSORBLACK))
      {
        // Then we turn west.
        turnTo(WEST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn north.
        turnTo(NORTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If both sensors are on the line.
      else
      {
        // Move forward a few ticks
        moveTicks(AFEW, APPROACHSPEED);
        stopMoving(APPROACHSPEED);
      }    
      break;
    case SWEST:
      // If our right sensor is on the line, but left is not.
      if ((sensors[0] < SENSORBLACK) && (sensors[7] > SENSORBLACK))
      {
        // Then we turn south.
        turnTo(SOUTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn west.
        turnTo(WEST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If our left sensor is on the line, but right is not.
      else if ((sensors[0] > SENSORBLACK) && (sensors[7] < SENSORBLACK))
      {
        // Then we turn east.
        turnTo(WEST);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving
        stopMoving(APPROACHSPEED);
        // Turn north.
        turnTo(SOUTH);
        // Move till we hit the line.
        moveTillPoint(APPROACHSPEED, forward, useBothSensors);
        // Stop Moving.
        stopMoving(APPROACHSPEED);
      }
      // If both sensors are on the line.
      else
      {
        // Move forward a few ticks
        moveTicks(AFEW, APPROACHSPEED);
        stopMoving(APPROACHSPEED);
      }    
      break;
  }
  // Turn the error adjust back on.
  errorAdjust = true;*/
}