Esempio n. 1
0
void LofarBeam::_setupConnections()
{
    // setup all the relationships between parameters
    connect( _array.get(), SIGNAL( updatedSelection() ), 
                      this, SLOT( refreshFilter() ) );
    connect( _array.get(), SIGNAL( updatedSelection() ), 
                      this, SLOT( refreshRCU() ) );
    connect( _array.get(), SIGNAL( updatedSelection() ), 
                      this, SLOT( refreshFrequency() ) );
    connect( _lofar->clockSpeeds().get(), SIGNAL( updatedSelection() ),
                      this, SLOT( clockUpdated() ) );
    connect( _frequency.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( frequencyUpdate() ) );
    connect( _bandwidth.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( bandwidthUpdate() ) );
    connect( _subbands.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( subbandUpdate() ) );
    connect( _directionType.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( updateDirection()) );
    connect( _directionX.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( updateDirection()) );
    connect( _directionY.get(), SIGNAL( updatedSelection() ),
                      this, SLOT( updateDirection()) );
    //connect( _filter.get(), SIGNAL( updatedSelection() ),
    //                  this, SLOT( frequencyUpdate() ) );
}
Esempio n. 2
0
void CentipedeSegment::handleCollision(GameObject* collider)
{
	if (collider->ID == 0) {
		//check if mushroom is on same y axis due to collision when edges are aligned
		if ((GLuint)collider->getCenter().y == (GLuint)this->getCenter().y) {
			//check if mushroom is in moving direction-> fixes error when moving down along a mushrom which has a mushroom on the field under itself
			if (direction == LEFT && collider->getCenter().x < this->getPosition().x1 ||
				direction == RIGHT && collider->getCenter().x > this->getPosition().x2) {
					//change direction
					updateDirection();
			}	
		}
	}
	else if (collider->ID == 2) {
		//If I am not a HEAD -> Do nothing
		if (this->type != HEAD) return;

		//check if segment is from this centipede -> no collision to check
		GLboolean isFromMyself = GL_FALSE;
		CentipedeSegment *follower =  following;
		if (follower != nullptr) {
			while (isFromMyself != GL_TRUE) {
				if (collider == follower) isFromMyself = GL_TRUE;

				follower = follower->getFollowing();
				if (follower == nullptr) break;
			}
		}
		if (isFromMyself == GL_TRUE) return;

		//check if centipede is on same y axis due to collision when edges are aligned
		if ((GLuint)collider->getCenter().y == (GLuint)this->getCenter().y) {
			//check if Centipede is in moving direction-> fixes error that heads get stuck to each other
			if (direction == LEFT && collider->getCenter().x < this->getCenter().x ||
				direction == RIGHT && collider->getCenter().x > this->getCenter().x) {
				//change direction
				updateDirection();
			}
		}
	}
	if (collider->ID == 1) {
		//die, spawn mushroom
		if(isAlive) //prevents double mushroom spawning
			centipedeManager->spawnMushroom(this->getCenter());
		isAlive = false;
		if (previous != nullptr) previous->setFollowing(nullptr);
	}
}
void QAbstractAnimationJob::setDirection(Direction direction)
{
    if (m_direction == direction)
        return;

    if (m_state == Stopped) {
        if (m_direction == Backward) {
            m_currentTime = duration();
            m_currentLoop = m_loopCount - 1;
        } else {
            m_currentTime = 0;
            m_currentLoop = 0;
        }
    }

    // the commands order below is important: first we need to setCurrentTime with the old direction,
    // then update the direction on this and all children and finally restart the pauseTimer if needed
    if (m_hasRegisteredTimer)
        QQmlAnimationTimer::ensureTimerUpdate();

    m_direction = direction;
    updateDirection(direction);

    if (m_hasRegisteredTimer)
        // needed to update the timer interval in case of a pause animation
        QQmlAnimationTimer::updateAnimationTimer();
}
Esempio n. 4
0
void QAbstractAnimation::setDirection(Direction direction)
{
    Q_D(QAbstractAnimation);
    if (d->direction == direction)
        return;

    if (state() == Stopped) {
        if (direction == Backward) {
            d->currentTime = duration();
            d->currentLoop = d->loopCount - 1;
        } else {
            d->currentTime = 0;
            d->currentLoop = 0;
        }
    }

    // the commands order below is important: first we need to setCurrentTime with the old direction,
    // then update the direction on this and all children and finally restart the pauseTimer if needed
    if (d->hasRegisteredTimer)
        QAnimationTimer::ensureTimerUpdate();

    d->direction = direction;
    updateDirection(direction);

    if (d->hasRegisteredTimer)
        // needed to update the timer interval in case of a pause animation
        QAnimationTimer::updateAnimationTimer();

    emit directionChanged(direction);
}
Esempio n. 5
0
void Player::updatePosition()
{
	double friction = 0.1;
	double speed = sqrt(pow(velocity.x, 2) + pow(velocity.y, 2));

	double frictionX = 0;
	double frictionY = 0;

	if (speed != 0)
	{
		frictionX = friction * ((double)velocity.x / speed);
		frictionY = friction * ((double)velocity.y / speed);
	}

	if (std::abs(velocity.x) <= std::abs((float)frictionX))
		velocity.x = 0;
	else
		velocity.x -= frictionX;

	if (std::abs(velocity.y) <= std::abs((float)frictionY))
		velocity.y = 0;
	else
		velocity.y -= frictionY;

	body.move(velocity);
	updateDirection();
}
Esempio n. 6
0
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);
}
void CompassPanel::init()
{
    m_direction = new QLabel("Direction: ");
    m_leftCompass = new Compass(this);
    m_rightCompass = new Compass(this);
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(m_direction);
    layout->addWidget(m_leftCompass,  1, 0);
    layout->addWidget(m_rightCompass, 1, 1);
    setLayout(layout);

    connect(m_leftCompass, SIGNAL(directionChanged(QString)), this, SLOT(updateDirection(QString)));
    connect(m_leftCompass, SIGNAL(directionChanged(Compass::Direction)), m_rightCompass, SLOT(setDirection(Compass::Direction)));
    connect(m_rightCompass, SIGNAL(directionChanged(Compass::Direction)), m_leftCompass, SLOT(setDirection(Compass::Direction)));
    m_leftCompass->setDirection(Compass::North);
    updateDirection(m_leftCompass->directionName(Compass::North));
}
Esempio n. 8
0
void Entity::requestDirection(Direction _direction)
{
	nextDirection = _direction;
	//if current and intended direction are exactly opposite, turn immediately
	if (((direction | _direction) == (UP | DOWN )) | ((direction | _direction) == (LEFT | RIGHT)))
	{
		updateDirection();
	}
}
Esempio n. 9
0
void PingPong::startGame()
{
    m_showDialog = false;
    Q_EMIT showDialogChanged();
    //! [Start the game]
    if (m_role == 1)
        updateDirection();

    m_timer->start(50);
    //! [Start the game]
}
Esempio n. 10
0
/*-----------------------------------------------*/
void Chicken::setRandomMovement()
{
   /* PURPOSE:		Sets a random speed for both x and y directions
      RECEIVES:
      RETURNS:
      REMARKS:
   */

   setSpeed(randomSpeed(), randomSpeed());
   updateDirection();
}
Esempio n. 11
0
DirectionVectorWidget::DirectionVectorWidget(QWidget *parent) :
  QWidget(parent)
{
  ui.setupUi(this);

  m_direction = Vec(0,0,1);

  m_lightdisc = new LightDisc(ui.disc);

  connect(m_lightdisc, SIGNAL(directionChanged(QPointF)),
	  this, SLOT(updateDirection(QPointF)));
}
Esempio n. 12
0
void CentipedeSegment::update(GLfloat tpf)
{
	if (previous != nullptr && previous->isAlive == GL_FALSE) type = HEAD;

	if (type != HEAD) {
		updateBody(tpf);
		return;
	}

	GLfloat movement = CENTIPEDE_SPEED * tpf;
	switch (direction)
	{
		case LEFT:
			Position.x1 -= movement;
			if (Position.x1 < 0) updateDirection();
			break;
		case RIGHT:
			Position.x1 += movement;
			if (Position.x1 > FIELDSIZE - CENTISEGMENT_WIDTH) updateDirection();
			break;
		case UP:
			Position.y1 -= movement;
			if (getCenter().y < FIELDSIZE - AREA && (GLuint)Position.y1 != (GLuint)AABB.y1) updateDirection();
			break;
		case DOWN:
			Position.y1 += movement;
			if (getCenter().y > 1 && (GLuint)Position.y1 + CENTISEGMENT_HEIGHT != (GLuint)AABB.y2) updateDirection();
		default:
			break;
	}

	Position.x2 = Position.x1 + CENTISEGMENT_WIDTH;
	Position.y2 = Position.y1 + CENTISEGMENT_HEIGHT;

	AABB = Position;
}
Esempio n. 13
0
void updateParticles(void)
{
    
    for (int i = 0; i < particleAmount; i++) {
        updateDirection(i);
        
        particles[i].position[0] = particles[i].position[0] + particles[i].speed * particles[i].direction[0];
        
        particles[i].position[1] = particles[i].position[1] + particles[i].speed * particles[i].direction[1];
        
        particles[i].position[2] = particles[i].position[2] + particles[i].speed * particles[i].direction[2];
        
        //particles[i].rotation =
        
        particles[i].age++;

        if (particles[i].age>maxAge) {
            restartParticle(i);
        }
    }
}
Esempio n. 14
0
void VillagerC::AI()
{
	/* PURPOSE:		Modifies object based on artificial intelligence
	RECEIVES:
	RETURNS:
	REMARKS:
	*/

	float speedX = this->speedX;
	float speedY = this->speedY;

	// If stopped Restart Character Maybe
	if (speedX == 0 && speedY == 0)
	{
		int willRestart = rand() % 100;
		if (willRestart == 0)
		{
			// Set speed and animation
			speedX = randomSpeed();
			speedY = randomSpeed();
			setAnimation("Walking");

			updateDirection(speedX, speedY);
		}
	}
	else
	{
		// Randomly stop characters
		int willStop = rand() % 250;
		if (willStop == 0)
		{
			speedX = 0;
			speedY = 0;
			setAnimation("Idle");
		}
	}

	setSpeed(speedX, speedY);
}
void SceneObjectImplementation::faceObject(SceneObject* obj, bool notifyClient) {
	Vector3 thisPos = getPosition();
	Vector3 targetPos = obj->getPosition();

	float directionangle = atan2(targetPos.getX() - thisPos.getX(), targetPos.getY() - thisPos.getY());

	if (directionangle < 0) {
		float a = M_PI + directionangle;
		directionangle = M_PI + a;
	}

	float err = fabs(directionangle - direction.getRadians());

	if (err < 0.05) {
		//info("not updating " + String::valueOf(directionangle), true);
		return;
	}

	if (notifyClient) {
		updateDirection(directionangle);
	} else {
		direction.setHeadingDirection(directionangle);
	}
}
Esempio n. 16
0
void Enemy::update(float timeStep)
{
	setMoving(false);
	for (auto& e : getManager()->getAll<Player>()) {
		Player* p = reinterpret_cast<Player*>(e);
        if (p->isMoving() && !p->isDead()) {
			setMoving(true);
            break;
        }
    }

    if (!isMoving()) return;

    //Update target depending on players movement and deadness.
    updateTarget();
    if (currentTarget == NULL) return;

    //Determine direction of enemy so correct sprite is drawn.
    updateDirection();

    //Movement phase
    updateMovement(timeStep);

}
Esempio n. 17
0
// This is the function that makes the algorith work!!!
//	Determines the direction to take after coming to an intersection
//  North=2, South=4, East=1, West=3
char old_DetermineDirection(char left, char right, char forward, int xcoor, int ycoor, int intersection, int Distance, int exploredArray[], int typeArray[], int pointArray[], int point, int getXCoor[], int getYCoor[]) {
	int Direction = updateDirection(0, false);
	bool directionNew = true;
	int compareType = 0;
	int Coordinate = updateCoordinate(xcoor, ycoor, point, false);

	if (Direction == 1) {
		if (forward) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor < getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(1, true);
				updateXCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (left) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor > getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(2, true);
				updateYCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (right) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor < getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(4, true);
				updateYCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (compareType == getType(left, right, forward)) {
			return traversedAdjacentPath(left, right, forward, xcoor, ycoor, intersection, Distance, exploredArray, typeArray, pointArray, point, getXCoor, getYCoor);
		}
	}

	else if (Direction == 2) {
		if (right) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor < getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(1, true);
				updateXCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (forward) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor > getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(2, true);
				updateYCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (left) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor > getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] >= typeArray[i] && Coordinate != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(3, true);
				updateXCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (compareType == getType(left, right, forward)) {
			return traversedAdjacentPath(left, right, forward, xcoor, ycoor, intersection, Distance, exploredArray, typeArray, pointArray, point, getXCoor, getYCoor);
		}
	}
	else if (Direction == 3) {
		if (right) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor > getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] > 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(2, true);
				updateYCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (forward) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor > getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] > 0 && typeArray[i] != 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(3, true);
				updateXCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (left) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor < getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] > 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(4, true);
				updateYCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (compareType == getType(left, right, forward)) {
			return traversedAdjacentPath(left, right, forward, xcoor, ycoor, intersection, Distance, exploredArray, typeArray, pointArray, point, getXCoor, getYCoor);
		}
	}
	else if (Direction == 4) {
		if (left) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor < getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] > 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(1, true);
				updateXCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (right) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (xcoor > getXCoor[i] && ycoor == getYCoor[i]) {
					if (exploredArray[i] > 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(3, true);
				updateXCOOR((-1 * Distance), true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (forward) {
			directionNew = true;
			int i = 0;
			while (i < intersection) {
				if (ycoor < getYCoor[i] && xcoor == getXCoor[i]) {
					if (exploredArray[i] > 0) {
						directionNew = false;
					}
				}
				i++;
			}
			if (directionNew == true) {
				Direction = updateDirection(4, true);
				updateYCOOR(Distance, true);
				return directionToRover(Direction);
			}
			else if (directionNew == false) {
				compareType++;
			}
		}
		if (compareType == getType(left, right, forward)) {
			return traversedAdjacentPath(left, right, forward, xcoor, ycoor, intersection, Distance, exploredArray, typeArray, pointArray, point, getXCoor, getYCoor);
		}
	}
}
Esempio n. 18
0
// Determines what to do if all adjacent paths have already been traversed
char traversedAdjacentPath(char left, char right, char forward, int xcoor, int ycoor, int intersection, int Distance, int exploredArray[], int typeArray[], int pointArray[], int point, int getXCoor[], int getYCoor[]) {
	int stop = 1;
	int Direction = updateDirection(0, false);
	int Coordinate = updateCoordinate(xcoor, ycoor, point, false);
	static bool endMap = false;
	int isDeadEnd = getType(left, right, forward);
	if (isDeadEnd == 1) {
		return new_DetermineDirection(left, right, forward, xcoor, ycoor, Distance);
	}
	else {
		int i = 0;
		while (i < intersection) {
			stop = 1;
			if (pointArray[i] == Coordinate) {
				if (exploredArray[i - 1] < typeArray[i - 1]) {
					if (ycoor == getYCoor[pointArray[i - 1]]) {
						if (xcoor > getXCoor[pointArray[i - 1]]) {
							Direction = updateDirection(3, true);
							updateXCOOR((-1 * Distance), true);
						}
						else if (xcoor < getXCoor[pointArray[i - 1]]) {
							Direction = updateDirection(1, true);
							updateXCOOR(Distance, true);
						}
					}
					else if (xcoor == getXCoor[pointArray[i - 1]]) {
						if (ycoor > getYCoor[pointArray[i - 1]]) {
							Direction = updateDirection(2, true);
							updateYCOOR((-1 * Distance), true);
						}
						else if (ycoor < getYCoor[pointArray[i - 1]]) {
							Direction = updateDirection(4, true);
							updateYCOOR(Distance, true);
						}
					}
					stop--;
				}
				else if (exploredArray[i + 1] < typeArray[i + 1]) {
					if (ycoor == getYCoor[pointArray[i + 1]]) {
						if (xcoor > getXCoor[pointArray[i + 1]]) {
							Direction = updateDirection(3, true);
							updateXCOOR((-1 * Distance), true);
						}
						else if (xcoor < getXCoor[pointArray[i + 1]]) {
							Direction = updateDirection(1, true);
							updateXCOOR(Distance, true);
						}
					}
					else if (xcoor == getXCoor[pointArray[i + 1]]) {
						if (ycoor > getYCoor[pointArray[i + 1]]) {
							Direction = updateDirection(2, true);
							updateYCOOR((-1 * Distance), true);
						}
						else if (ycoor < getYCoor[pointArray[i + 1]]) {
							Direction = updateDirection(4, true);
							updateYCOOR(Distance, true);
						}
					}
					stop--;
				}
				else if ((exploredArray[i - 1] >= typeArray[i - 1]) && (exploredArray[i + 1] >= typeArray[i + 1])) {
					stop++;
				}
			}
			i++;
		}
	}
	if (stop == 2) {
		// DONE MAPPING!!!!
		return 'E';
	}
	else {
		return directionToRover(Direction);
	}
}
Esempio n. 19
0
char new_DetermineDirection(char left, char right, char forward, int xcoor, int ycoor, int Distance) {
	char nextDirection = ' ';
	int Direction = updateDirection(0, false);

	if (Direction == 1) {
		if (!left && !right && !forward) {
			Direction = updateDirection(3, true);
			updateXCOOR((-1 * Distance), true);
		}
		else if (forward) {
			Direction = updateDirection(1, true);
			updateXCOOR(Distance, true);
		}
		else if (left) {
			Direction = updateDirection(2, true);
			updateYCOOR((-1 * Distance), true);
		}
		else if (right) {
			Direction = updateDirection(4, true);
			updateYCOOR(Distance, true);
		}
		nextDirection = directionToRover(Direction);
	}
	else if (Direction == 2) {
		if (!left && !right && !forward) {
			Direction = updateDirection(4, true);
			updateYCOOR(Distance, true);
		}
		else if (right) {
			Direction = updateDirection(1, true);
			updateXCOOR(Distance, true);
		}
		else if (forward) {
			Direction = updateDirection(2, true);
			updateYCOOR((-1 * Distance), true);
		}
		else if (left) {
			Direction = updateDirection(3, true);
			updateXCOOR((-1 * Distance), true);
		}
		nextDirection = directionToRover(Direction);
	}
	else if (Direction == 3) {
		if (!left && !right && !forward) {
			Direction = updateDirection(1, true);
			updateXCOOR(Distance, true);
		}
		else if (right) {
			Direction = updateDirection(2, true);
			updateYCOOR((-1 * Distance), true);
		}
		else if (forward) {
			Direction = updateDirection(3, true);
			updateXCOOR((-1 * Distance), true);
		}
		else if (left) {
			Direction = updateDirection(4, true);
			updateYCOOR(Distance, true);
		}
		nextDirection = directionToRover(Direction);
	}
	else if (Direction == 4) {
		if (!left && !right && !forward) {
			Direction = updateDirection(2, true);
			updateYCOOR((-1 * Distance), true);
		}
		else if (left) {
			Direction = updateDirection(1, true);
			updateXCOOR(Distance, true);
		}
		else if (right) {
			Direction = updateDirection(3, true);
			updateXCOOR((-1 * Distance), true);
		}
		else if (forward) {
			Direction = updateDirection(4, true);
			updateYCOOR(Distance, true);
		}
		nextDirection = directionToRover(Direction);
	}
	return nextDirection;
}
Esempio n. 20
0
void rotateWithOrientation(int degrees, byte power) {
	rotateDegrees(degrees, power);
	updateDirection(degrees * sgn(power));
}
void sipQPauseAnimation::sipProtectVirt_updateDirection(bool sipSelfWasArg,QAbstractAnimation::Direction a0)
{
    (sipSelfWasArg ? QAbstractAnimation::updateDirection(a0) : updateDirection(a0));
}
Esempio n. 22
0
void Game::update() {
	sf::Time t = clock.getElapsedTime();
	updateDirection();

	sf::Vector2i pixelPos = sf::Mouse::getPosition(window);
	sf::Vector2f v = window.mapPixelToCoords(pixelPos) - player.position;

	float len = sqrt(powf(v.x, 2) + powf(v.y, 2));
	// vector unitari que va del centre del jugador
	// en direcció a on apuntem
	player.facing = v / len;

	// get hurt!
	for (auto &enemy : enemies) {
        enemy.update(player, map);
		enemy.collisions(map);
		if (distancePointPoint(enemy.position, player.position) < 30.f) {

			enemy.attacking_timeout = clock.getElapsedTime() + sf::milliseconds(250);

			player.hit(player.position - enemy.position);
			flash_timeout = clock.getElapsedTime() + sf::milliseconds(40);

			player.hp -= 20;
			hurt_sound.play();
			if (player.hp <= 0) {
                death_scream_sound.play();
                music.stop();
				next_game_state = GameOver;
				input_timeout = clock.getElapsedTime() + sf::milliseconds(1000);
				game_over_sound.play();
				gameOver_music.play();
			}
		}
	}

	player.update();
	player.collisions(map);

	for (auto &bullet : bullets) {
        bullet.update(map);

		for (auto &enemy : enemies) {
			// if we already hit that enemy, don't hit it again
			if (std::find(
						bullet.enemies_hit.begin(),
						bullet.enemies_hit.end(),
						&enemy) != bullet.enemies_hit.end()) {
				continue;
			}
			if (lineCrossesCircle(bullet.prev_pos, bullet.position, enemy.position, enemy.radius)) {
				bullet.enemies_hit.push_back(&enemy);
				if (rand() % 3 == 0) {
					splashBlood(enemy, bullet.vvel, 10);
					enemy.stagger_timeout = clock.getElapsedTime() + sf::milliseconds(250);
				} else {
				    zombie_death_sound.play();
					enemy.alive = false;
					//bullet.alive = false;

					splashBlood(enemy, bullet.vvel);
					if (rand() % 10 == 0) {
						Magazine mag(&textures[3], &clock, &window, enemy.position);
						magazines.push_back(mag);
					}
				}
			}
		}
	}
	spent_in_a += clock.getElapsedTime() - t;
	t = clock.getElapsedTime();

	for (auto &part : particles) {
        part.update(map);
	}

	for (auto &knife : knives) {
        knife.update(map);
		if (knife.alive) {
			if (knife.vvel.x != 0 && knife.vvel.y != 0) {
				for (auto &enemy : enemies) {
					if (distancePointPoint(knife.position, enemy.position) < enemy.radius) {
						enemy.alive = false;
						splashBlood(enemy, knife.vvel);

						if (rand() % 6 == 0) {
							Magazine mag(&textures[3], &clock, &window, enemy.position);
							magazines.push_back(mag);
						}
					}
				}
			} else {
				if (distancePointPoint(knife.position, player.position) < player.radius + knife.radius) {
					knife.alive = false;
				}
			}
		}
	}

	for (auto &mag : magazines) {
		if (distancePointPoint(mag.position, player.position) < player.radius + 3) {
			mag.alive = false;
			player.extra_ammo += mag_size;
		}
	}

	if (enemies.size() == 0 &&
			distancePointPoint(player.position, warp_pos) < 30) {
		map_n += 1;
		if(loadMap(map_n) != 0) {
			// fin
			music.stop();
			next_game_state = GameOver;
			input_timeout = clock.getElapsedTime() + sf::milliseconds(1000);
			victory_music.play();
		}
	}

	// el jugador al centre de la pantalla
	sf::View view = window.getView();
	view.setCenter(player.position);
	window.setView(view);
	spent_in_b += clock.getElapsedTime() - t;
}
Esempio n. 23
0
void swingWithCoords(float degrees, byte direction, byte power) {
	float arcLength = (float)sqrt(648) * (degrees * (PI / 180));
	swingDegrees(degrees, direction, power);
	updateDirection(degrees * (sgn(direction) * sgn(power)));
	updateCoords(arcLength * sgn(direction) * sgn(power));
}
Esempio n. 24
0
void Vector::add(Vector vec2){
	xComponent += vec2.getMagnitude() * cos(vec2.getDirection());
	yComponent += vec2.getMagnitude() * sin(vec2.getDirection());
	updateDirection();
}
Esempio n. 25
0
/**
 * @details Constructs a LofarBeam object.
 */
LofarBeam::LofarBeam( Lofar* lofar )
    : State(true), _lofar(lofar), _localUpdate(false)
{
    // construct parameters
    //_streams.reset(new MultiRangeParameter<unsigned int>(
   //                        "streams(beamlets)", 
    //                       "the output channels to map the subbands to. Max of 64 per beam is allowed") );
    //_streams.setRange( Range<unsigned int>(0,247) );

    _array.reset(new SelectionParameter<RCU::Array>(
                           "Antenna Array",
                           "Defines the Antenna array to use in this beam" ) );

    QList<QString> arrayDesc;  arrayDesc << "Low Band" 
                                         << "High Band";

    QList<RCU::Array> arrayValues;  arrayValues << RCU::LB << RCU::HB;
    _array->setAllowableValues( arrayDesc, arrayValues);


    _filter.reset( new SelectionParameter<RCU_Filter>(
                       "RCU Filter", 
                       "The filter to apply to the RCU chain") );

    _ids.reset( new MultiRangeParameter<unsigned int>(
                       "rcu id", 
                       "The ids of all rcu's to be included in the beam") );

    _frequency.reset( new SingleParameter<float>(
                       "frequency",
                       "The frequency range to observe" ) );

    _bandwidth.reset( new SingleParameter<float>(
                       "bandwidth",
                       "The width of the frequecy band to observe"
                       " relative to the start frequency" ) );

    _subbands.reset( new MultiRangeParameter<unsigned int>(
                       "subbands", 
                       "The subband identifiers associated with the frequen") );

    _directionType.reset( new SelectionParameter<QString>( 
                       "direction", "The type "
                       "of direction input. "
                       "SKYSCAN will scan the sky with a L x M grid in "
                       "the (l,m) plane") );
    _directionType->setAllowableValues( _direction.types(), _direction.types() );
    _directionType->set(_direction.types()[0]);

    _directionX.reset( new SingleParameter<float>("x", 
                   "The longitude in degrees for direction specification" ) );
    _directionX->setRange( Range<float>(-180,180) );
    _directionY.reset( new SingleParameter<float>("y", 
                   "The latitude in degrees for direction specification" ) );
    _directionY->setRange( Range<float>(-90.0,90.0) );
     updateDirection();

    // set default values (pre-connection)
    _frequency->set(0.0);
    _bandwidth->set(0.0);
    _setupConnections();

    // set default values
    _array->set(RCU::LB);
    refreshFilter();
    _filter->set(RCU_Filter());
    _ids->set( _lofar->rcuIds( _array->value()) );
    _subbands->set( _lofar->subbandRanges() );
    _subbands->setAllowableValues( _lofar->subbandRanges() );
    _directionX->set(0.0);
    _directionY->set(0.0);
    refreshFrequency();
    refreshRCU();

    // set up the RCU group
    ParameterGroup g("RCU Selection");
    g.addParameter( _array );
    g.addParameter( _filter );
    g.addParameter( _ids );

    // set up the frequency group
    ParameterGroup f("Frequency");
    f.addParameter( _frequency );
    f.addParameter( _bandwidth );
    f.addParameter( _subbands );

    // set up the direction group
    ParameterGroup d("Direction");
    d.addParameter( _directionType );
    d.addParameter( _directionX );
    d.addParameter( _directionY );

    appendGroup( g );
    appendGroup( f );
    appendGroup( d );
}
Esempio n. 26
0
void PingPong::checkBoundaries()
{
    float ballWidth = m_boardWidth/54;
    float blockSize = m_boardWidth/27;
    float blockHeight = m_boardHeight/5;
    //! [Checking the boundaries]
    if (((m_ballX + ballWidth) > (m_boardWidth - blockSize)) && ((m_ballY + ballWidth) < (m_rightBlockY + blockHeight))
            && (m_ballY > m_rightBlockY)) {
        m_targetY = 2 * m_ballY - m_ballPreviousY;
        m_targetX = m_ballPreviousX;
        interval = -5;
        updateDirection();
    }
    else if ((m_ballX < blockSize) && ((m_ballY + ballWidth) < (m_leftBlockY + blockHeight))
             && (m_ballY > m_leftBlockY)) {
        m_targetY = 2 * m_ballY - m_ballPreviousY;
        m_targetX = m_ballPreviousX;
        interval = 5;
        updateDirection();
    }
    else if (m_ballY < 0 || (m_ballY + ballWidth > m_boardHeight)) {
        m_targetY = m_ballPreviousY;
        m_targetX = m_ballX + interval;
        updateDirection();
    }
    //! [Checking the boundaries]
    else if ((m_ballX + ballWidth) > m_boardWidth) {
        m_resultLeft++;
        m_targetX = m_boardWidth;
        m_targetY = m_boardHeight/2;
        m_ballPreviousX = m_ballX = m_boardWidth/2;
        m_ballPreviousY = m_ballY = m_boardHeight - m_boardWidth/54;

        updateDirection();
        checkResult();
        QByteArray result;
        result.append("result ");
        QByteArray res;
        res.setNum(m_resultLeft);
        result.append(res);
        result.append(' ');
        res.setNum(m_resultRight);
        result.append(res);
        result.append(" \n");
        socket->write(result);
        qDebug() << result;
        Q_EMIT resultChanged();
    }
    else if (m_ballX < 0) {
        m_resultRight++;
        m_targetX = 0;
        m_targetY = m_boardHeight/2;
        m_ballPreviousX = m_ballX = m_boardWidth/2;
        m_ballPreviousY = m_ballY = m_boardHeight - m_boardWidth/54;
        updateDirection();
        checkResult();
        QByteArray result;
        result.append("result ");
        QByteArray res;
        res.setNum(m_resultLeft);
        result.append(res);
        result.append(' ');
        res.setNum(m_resultRight);
        result.append(res);
        result.append(" \n");
        socket->write(result);
        Q_EMIT resultChanged();
    }
}
Esempio n. 27
0
void Vector::setXComponent(float x){ xComponent = x; updateDirection(); }
Esempio n. 28
0
MenuButton::MenuButton(const LoaderParams* pParams) :
GameObject(pParams)
{
	m_currentFrame = MOUSE_OUT; // start at frame 0
	updateDirection(1);
}
void sipQSequentialAnimationGroup::sipProtectVirt_updateDirection(bool sipSelfWasArg,QAbstractAnimation::Direction a0)
{
    (sipSelfWasArg ? QSequentialAnimationGroup::updateDirection(a0) : updateDirection(a0));
}
Esempio n. 30
0
void Vector::setYComponent(float y){ yComponent = y; updateDirection(); }