• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ setX函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中setX函数的典型用法代码示例。如果您正苦于以下问题:C++ setX函数的具体用法?C++ setX怎么用?C++ setX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setX函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: planRoute

void TREnemy::moveAlongPath(){
    planRoute(false);
    if(path.empty()){
        return;
    }
    int topX = path.front().first;
    int topY = path.front().second;
    int curX = getX();
    int curY = getY();
    if(!undoed && curX != topX){
        if(std::abs(curX - topX) < vel){
            if(curX > topX){
                setDirection(TRDirectionLeft);
                curX = topX;
            }else{
                setDirection(TRDirectionRight);
                curX = topX;
            }
        }else{
            if (curX > topX) {
                setDirection(TRDirectionLeft);
                curX -= vel;
            }else{
                setDirection(TRDirectionRight);
                curX += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setX(curX);
        return;
    }
    if(curY != topY){
        undoed = false;
        if(std::abs(curY - topY) < vel){
            if(curY > topY){
                setDirection(TRDirectionUp);
                curY = topY;
            }else{
                setDirection(TRDirectionDown);
                curY = topY;
            }
        }else{
            if (curY > topY) {
                setDirection(TRDirectionUp);
                curY -= vel;
            }else{
                setDirection(TRDirectionDown);
                curY += vel;
            }
        }
        if(curX == topX && curY == topY){
            path.pop();
        }
        setY(curY);
        return;
    }
    if(curX == topX && curY == topY){
        path.pop();
    }
    return;
}
开发者ID:hahaschool,项目名称:TombRaider,代码行数:63,代码来源:TREnemy.cpp


示例2: setX

void Coordinate::operator+=(const Coordinate& coord)
{
	setX(_x + coord.x());
	setY(_y + coord.y());
}
开发者ID:DanielleWinter,项目名称:ELEN3009-Project-2014,代码行数:5,代码来源:Coordinate.cpp


示例3: QSizeF


//.........这里部分代码省略.........
    _maxSubW = 0.0;
    _maxSubH = setting->rubyFontSize();
    QList<HelperKaraokeLabel*> subList;
    for (int i = 0; i < rubyCount; i++)
    {
        HelperKaraokeLabel* sub = new HelperKaraokeLabel(this);
        sub->_isRuby = true;
        sub->setRubyHidden(_isRubyHidden);
        subList.append(sub);
        sub->setText(ruby[i].ruby());
        sub->_textColor = _textColor;
        sub->_strokeColor = _strokeColor;

        // set font
        QFont f;
        f.setFamily(setting->fontName());
        f.setWeight(99);
        f.setPixelSize(setting->rubyFontSize());
        f.setLetterSpacing(QFont::SpacingType::AbsoluteSpacing, 1);
        sub->setFont(f);

        QSizeF subsize = sub->minimumSizeHint();
        if (_maxSubW < subsize.width())
        {
            _maxSubW = subsize.width();
        }
        // should be even!!
        /*
        if (_maxSubH < subsize.height())
        {
        	_maxSubH = subsize.height();
        }*/
    }

    // rearrange size
    _maxSubH += 1.0; // shadow

    //  /--/                // _rubyOffset > 0
    //      /<--->/      // _maxSubW
    //  |--|a|----|b|----|c|--|
    //  AAAAAAAAAAAAAAAAA

    //
    // |a|b|c|
    //	---A---
    // /--/                // _rubyOffset < 0

    size.setHeight(size.height() + _maxSubH + setting->rubyVSpace());
    if (rubyCount > 0)
    {
        qreal subTotalW = _maxSubW*rubyCount;
        qreal oWidth = size.width();

        if (oWidth < subTotalW)
        {
            size.setWidth(_maxSubW*rubyCount);
            _rubyOffset = (oWidth - subTotalW) / 2.0;
        }
        else
        {
            auto oMaxSubW = _maxSubW;
            /*
            _maxSubW = ((qreal)(oWidth)) / rubyCount;
            _rubyOffset = oMaxSubW/2;
            */
            _rubyOffset = (oWidth - rubyCount*oMaxSubW) / rubyCount / 2.0;
            _maxSubW = oMaxSubW + _rubyOffset * 2.0;
        }

        for (int i = 0; i < rubyCount; i++)
        {
            subList[i]->setFixedSize(QSize(_maxSubW, _maxSubH+setting->rubyVSpace()));
            subList[i]->_maxSubW = _maxSubW;
            subList[i]->_maxSubH = _maxSubH;
            auto geo = subList[i]->geometry();
            geo.setX(geo.x() + i*_maxSubW + (_rubyOffset>0 ? _rubyOffset : 0));
            subList[i]->setGeometry(geo);
        }
        /*
        auto geo = this->geometry();
        geo.setY(maxSubH + subSpaceH);
        this->setGeometry(geo);
        */
    }

    setFixedSize(size.toSize());


    // render to image
    pimage = new QImage(size.toSize(), QImage::Format_ARGB32);
    QPainter painter(pimage);
    pimage->fill(qRgba(0, 0, 0, 0));
    render(&painter, QPoint(), QRegion(), QWidget::DrawChildren);


    // assign return value
    *ppimage = pimage;

    return size;
}
开发者ID:b17ee518,项目名称:f3fcb5de86f31ecb32d3ca856a233670,代码行数:101,代码来源:helperkaraokelabel.cpp


示例4: swap

void OpticalFlowTransitionModel::predict(vector<Sample>& samples, const Mat& image, const optional<Sample>& target) {
	points.clear();
	forwardPoints.clear();
	backwardPoints.clear();
	forwardStatus.clear();
	error.clear();
	squaredDistances.clear();
	correctFlowCount = 0;

	// build pyramid of the current image
	cv::buildOpticalFlowPyramid(makeGrayscale(image), currentPyramid, windowSize, maxLevel, true, BORDER_REPLICATE, BORDER_REPLICATE);
	if (previousPyramid.empty() || !target) { // optical flow cannot be computed if there is no previous pyramid or no current target
		swap(previousPyramid, currentPyramid);
		return fallback->predict(samples, image, target);
	}

	// compute grid of points at target location
	for (auto point = templatePoints.begin(); point != templatePoints.end(); ++point)
		points.push_back(Point2f(target->getWidth() * point->x + target->getX(), target->getHeight() * point->y + target->getY()));
	// compute forward and backward optical flow
	cv::calcOpticalFlowPyrLK(previousPyramid, currentPyramid, points, forwardPoints, forwardStatus, error, windowSize, maxLevel);
	cv::calcOpticalFlowPyrLK(currentPyramid, previousPyramid, forwardPoints, backwardPoints, backwardStatus, error, windowSize, maxLevel);
	swap(previousPyramid, currentPyramid);

	// compute flow and forward-backward-error
	vector<Point2f> flows;
	flows.reserve(points.size());
	squaredDistances.reserve(points.size());
	for (unsigned int i = 0; i < points.size(); ++i) {
		flows.push_back(forwardPoints[i] - points[i]);
		if (forwardStatus[i] && backwardStatus[i]) {
			Point2f difference = backwardPoints[i] - points[i];
			squaredDistances.push_back(make_pair(difference.dot(difference), i));
		}
	}
	if (squaredDistances.size() < points.size() / 2) // the flow for more than half of the points could not be computed
		return fallback->predict(samples, image, target);

	// find the flows with the least forward-backward-error (not more than 1 pixel)
	float maxError = 1 * 0.5f;
	vector<float> xs, ys;
	sort(squaredDistances.begin(), squaredDistances.end(), [](pair<float, int> lhs, pair<float, int> rhs) { return lhs.first < rhs.first; });
	xs.reserve(squaredDistances.size());
	ys.reserve(squaredDistances.size());
	for (correctFlowCount = 0; correctFlowCount < squaredDistances.size(); ++correctFlowCount) {
		if (squaredDistances[correctFlowCount].first > maxError)
			break;
		int index = squaredDistances[correctFlowCount].second;
		xs.push_back(flows[index].x);
		ys.push_back(flows[index].y);
	}
	if (correctFlowCount < points.size() / 2) // to little correct correspondences
		return fallback->predict(samples, image, target);

	// compute median flow (only change in position for now)
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	float medianX = xs[xs.size() / 2];
	float medianY = ys[ys.size() / 2];
	Point2f medianFlow(medianX, medianY);

	// compute ratios of point distances in previous and current image
	vector<float> squaredRatios;
	squaredRatios.reserve(correctFlowCount * (correctFlowCount - 1) / 2);
	for (unsigned int i = 0; i < correctFlowCount; ++i) {
		for (unsigned int j = i + 1; j < correctFlowCount; ++j) {
			Point2f point1 = points[squaredDistances[i].second];
			Point2f forwardPoint1 = forwardPoints[squaredDistances[i].second];
			Point2f point2 = points[squaredDistances[j].second];
			Point2f forwardPoint2 = forwardPoints[squaredDistances[j].second];
			Point2f differenceBefore = point1 - point2;
			Point2f differenceAfter = forwardPoint1 - forwardPoint2;
			float squaredDistanceBefore = differenceBefore.dot(differenceBefore);
			float squaredDistanceAfter = differenceAfter.dot(differenceAfter);
			squaredRatios.push_back(squaredDistanceAfter / squaredDistanceBefore);
		}
	}

	// compute median ratio to complete the median flow
	sort(squaredRatios.begin(), squaredRatios.end());
	float medianRatio = sqrt(squaredRatios[squaredRatios.size() / 2]);

	// predict samples according to median flow and random noise
	for (auto sample = samples.begin(); sample != samples.end(); ++sample) {
		int oldX = sample->getX();
		int oldY = sample->getY();
		float oldSize = sample->getSize();
		// change position according to median flow
		double newX = oldX + medianX;
		double newY = oldY + medianY;
		double newSize = oldSize * medianRatio;
		// add noise to position
		double positionDeviation = scatter * sample->getSize();
		newX += positionDeviation * generator();
		newY += positionDeviation * generator();
		newSize *= pow(2, scatter * generator());
		// round to integer
		sample->setX((int)(newX + 0.5));
		sample->setY((int)(newY + 0.5));
		sample->setSize((int)(newSize + 0.5));
//.........这里部分代码省略.........
开发者ID:HVisionSensing,项目名称:FeatureDetection,代码行数:101,代码来源:OpticalFlowTransitionModel.cpp


示例5: Hexagon

HexagonGrid::HexagonGrid()
{
    // Creating 200x200 hexagonal map
    unsigned int index = 0;
    for (unsigned int q = 0; q != 200; ++q)
    {
        for (unsigned int p = 0; p != 200; ++p, ++index)
        {
            auto hexagon = new Hexagon(index);
            int x = 48*100 + 16*(q+1) - 24*p;
            int y = (q+1)*12 + 6*p + 12;
            if (p&1)
            {
                x -= 8;
                y -= 6;
            }

            hexagon->setCubeX(q - (p + (p&1))/2);
            hexagon->setCubeZ(p);
            hexagon->setCubeY(-hexagon->cubeX() - hexagon->cubeZ());

            hexagon->setX(x);
            hexagon->setY(y);
            _hexagons.push_back(hexagon);
        }
    }

    // Creating links between hexagons
    for (index = 0; index != 200*200; ++index)
    {
        auto hexagon = _hexagons.at(index);

        unsigned int q = index/200; // hexagonal y
        unsigned int p = index%200; // hexagonal x

        unsigned index1 = (q + 1)*200 + p;
        unsigned index4 = (q-1)*200 + p;
        unsigned int index2, index3, index5, index6;
        if (index&1)
        {
            index2 = q*200 + p-1;
            index3 = (q-1)*200 + p-1;
            index5 = (q-1)*200 + p+1;
            index6 = q*200 + p+1;
        }
        else
        {
            index2 = (q+1)*200 + p-1;
            index3 = q*200 + p-1;
            index5 = q*200 + p+1;
            index6 = (q+1)*200 + p+1;
        }

        if (index1 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index1));
        if (index2 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index2));
        if (index3 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index3));
        if (index4 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index4));
        if (index5 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index5));
        if (index6 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index6));
    }
}
开发者ID:Legun,项目名称:falltergeist,代码行数:61,代码来源:HexagonGrid.cpp


示例6: setPosition

void BossLaser::setMissedPosition() 
{
	setPosition(VECTOR2(GAME_WIDTH/2, GAME_HEIGHT/5));
	setX(Entity::getPositionX());
	setY(Entity::getPositionY());
}
开发者ID:JohnHurtTheFool,项目名称:games_project_2,代码行数:6,代码来源:bossLaser.cpp


示例7: setX

Point::Point()
{
    setX(0.0);
    setY(0.0);
    setY(0.0);
}
开发者ID:awilanowska,项目名称:zpk2014,代码行数:6,代码来源:point.cpp


示例8: Location

 Location(unsigned long int _size, T _x, T _y) : size(_size) {
     setX(_x);
     setY(_y);
 }
开发者ID:Curiosidad-Racional,项目名称:Checkerboard,代码行数:4,代码来源:location.hpp


示例9: setX

void Entity::setPosition(float x, float y)
{
    setX(x);
    setY(y);
}
开发者ID:jhpy1024,项目名称:glfPong,代码行数:5,代码来源:Entity.cpp


示例10: Surface


//.........这里部分代码省略.........
			// Sum of all character lengths in the current line.
			int linePixels = 0;
			for (auto &c : line)
			{
				linePixels += islower(c) ? lowerCharWidth : upperCharWidth;
			}

			// Check against the current longest line.
			if (linePixels > longestLength)
			{
				longestLength = linePixels;
			}
		}

		// In pixels.
		return longestLength;
	}(this->textLines, upperCharWidth, lowerCharWidth);

	const int newHeight = static_cast<int>(this->textLines.size()) * upperCharHeight;

	// Resize the surface with the proper dimensions for fitting all the text.
	SDL_FreeSurface(this->surface);
	this->surface = [](int width, int height, int colorBits)
	{
		return SDL_CreateRGBSurface(0, width, height, colorBits, 0, 0, 0, 0);
	}(newWidth, newHeight, Surface::DEFAULT_BPP);

	// Make this surface transparent.
	this->setTransparentColor(Color::Transparent);
	this->fill(Color::Transparent);
	
	// Blit each character surface in at the right spot.
	auto point = Int2();
	auto fontSurface = textureManager.getSurface(font.getFontTextureName());
	int upperCharOffsetWidth = font.getUpperCharacterOffsetWidth();
	int upperCharOffsetHeight = font.getUpperCharacterOffsetHeight();
	int lowerCharOffsetWidth = font.getLowerCharacterOffsetWidth();
	int lowerCharOffsetHeight = font.getLowerCharacterOffsetHeight();
	for (auto &line : this->textLines)
	{
		for (auto &c : line)
		{
			int width = islower(c) ? lowerCharWidth : upperCharWidth;
			int height = islower(c) ? lowerCharHeight : upperCharHeight;
			auto letterSurface = [&]()
			{
				auto cellPosition = Font::getCharacterCell(c);
				int offsetWidth = islower(c) ? lowerCharOffsetWidth : upperCharOffsetWidth;
				int offsetHeight = islower(c) ? lowerCharOffsetHeight : upperCharOffsetHeight;

				// Make a copy surface of the font character.
				auto pixelPosition = Int2(
					cellPosition.getX() * (width + offsetWidth),
					cellPosition.getY() * (height + offsetHeight));
				auto clipRect = Rectangle(pixelPosition.getX(), pixelPosition.getY(),
					width, height);

				auto surface = Surface(width, height);
				fontSurface.blit(surface, Int2(), clipRect);

				return surface;
			}();

			// Set the letter surface to have transparency.
			letterSurface.setTransparentColor(Color::Magenta);

			// Set the letter colors to the desired color.
			auto letterPixels = static_cast<unsigned int*>(letterSurface.getSurface()->pixels);
			auto mappedColor = SDL_MapRGBA(letterSurface.getSurface()->format, 
				textColor.getR(), textColor.getG(), textColor.getB(), textColor.getA());

			int area = letterSurface.getWidth() * letterSurface.getHeight();
			for (int i = 0; i < area; ++i)
			{
				auto pixel = &letterPixels[i];
				
				// If transparent, then color it? I dunno, but it works.
				if ((*pixel) == 0)
				{
					*pixel = mappedColor;
				}
			}

			// Draw the letter onto this texture.
			letterSurface.blit(*this, point);

			// Move drawing position to the right of the current character.
			point.setX(point.getX() + width);
		}

		// Move drawing point back to the left and down by one capital character size.
		point.setX(0);
		point.setY(point.getY() + upperCharHeight);
	}

	assert(this->surface->w > 1);
	assert(this->surface->h > 1);
	assert(this->textLines.size() > 0);
	assert(this->fontName == fontName);
}
开发者ID:basecq,项目名称:OpenTESArena,代码行数:101,代码来源:TextBox.cpp


示例11: setX

void EllipseObject::setObjectCenterX(qreal centerX)
{
    setX(centerX);
}
开发者ID:claudeocquidant,项目名称:Embroidermodder,代码行数:4,代码来源:object-ellipse.cpp


示例12: setX

void VESPERSEXAFSScanConfiguration::setPosition(QPair<double, double> pos)
{
	setX(pos.first);
	setY(pos.second);
}
开发者ID:Cpppro,项目名称:acquaman,代码行数:5,代码来源:VESPERSEXAFSScanConfiguration.cpp


示例13: setX

void Point::set(std::shared_ptr<Point> data)
{
	setX (data->getX());
	setY (data->getY());
}
开发者ID:vcappello,项目名称:WinGui,代码行数:5,代码来源:point.cpp


示例14: setX

void Transform::subToX(int x)
{
	setX(getX()-x);

}
开发者ID:MidnightDrifter,项目名称:GAME-ENGINE-FINAL,代码行数:5,代码来源:Transform.cpp


示例15: setX

void Dynamite::onTick()
{
    setX(getX()-speed);
    setY(getY()+rand()%21-10);
}
开发者ID:dylwhich,项目名称:MachineGunAlienWerewolfAttack,代码行数:5,代码来源:dynamite.cpp


示例16: setX

PlayerPanel::PlayerPanel() : UI::Base()
{
    auto game = Game::getInstance();
    auto renderer = game->renderer();
    auto mouse = game->mouse();

    _background = std::make_shared<Image>("art/intrface/iface.frm");
    _ui.push_back(_background);

    setX((renderer->width() - 640) / 2);
    setY(renderer->height() - _background->height());

    _background->setPosition(this->position());

    mouseInHandler().add([this, mouse](Event::Event* event)
    {
        mouse->pushState(Input::Mouse::Cursor::BIG_ARROW);
    });

    mouseOutHandler().add([this, mouse](Event::Event* event)
    {
        if (mouse->scrollState())
        {
            // this trick is needed for correct cursor type returning on scrolling
            auto state = mouse->state();
            mouse->popState();
            mouse->popState();
            mouse->pushState(state);
        }
        else
        {
            mouse->popState();
        }
    });

    // Change hand button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(218, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->changeHand(); });

    // Inventory button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_INVENTORY, position() + Point(211, 40)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openInventory(); });

    // Options button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_OPTIONS, position() + Point(210, 61)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openGameMenu(); });

    // Attack button
    _isAttackBtnPressed = false;
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_ATTACK, position() + Point(267, 25)));

    _ui.back()->mouseDownHandler().add([this](Event::Event* event){
        if(auto mouse = dynamic_cast<Event::Mouse*>(event))
        {
            if(mouse->leftButton())
                _isAttackBtnPressed = true;
        }
    });

    _ui.back()->mouseUpHandler().add([this](Event::Event* event){
        _isAttackBtnPressed = false;
    });


    // Hit points
    _hitPoints = std::make_shared<SmallCounter>(position() + Point(473, 40));
    _hitPoints->setType(SmallCounter::Type::SIGNED);
    _hitPoints->setNumber(game->player()->hitPoints());
    _ui.push_back(_hitPoints);

    // Armor class
    _armorClass = std::make_shared<SmallCounter>(position() + Point(473, 76));
    _armorClass->setType(SmallCounter::Type::SIGNED);
    _armorClass->setNumber(game->player()->armorClass());
    _ui.push_back(_armorClass);

    // Skilldex button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(523, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openSkilldex();
    });

    // MAP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_MAP, position() + Point(526, 39)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openMap();
    });

    // CHA button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_CHA, position() + Point(526, 58)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openCharacterScreen();
    });

    // PIP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_PIP, position() + Point(526, 77)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openPipBoy();
    });

//.........这里部分代码省略.........
开发者ID:CynicRus,项目名称:falltergeist,代码行数:101,代码来源:PlayerPanel.cpp


示例17: setX

void Character::moveOnCenter() {
	setX((m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE);
	setY((m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE);
}
开发者ID:jsj2008,项目名称:kdegames,代码行数:4,代码来源:character.cpp


示例18: setX

/** Initializer **/
void Wall::init(const int & x, const int & orientation)
{
	setX(x);
	setO(orientation);
}
开发者ID:Hagglesmith,项目名称:tunnelproject-1,代码行数:6,代码来源:Wall.cpp


示例19: setXYZ

 /** \brief Set the X, Y and Z components of the state */
 void setXYZ(double x, double y, double z)
 {
     setX(x);
     setY(y);
     setZ(z);
 }
开发者ID:WPI-ARC,项目名称:deformable_planners,代码行数:7,代码来源:PatchedSE3StateSpace.hpp


示例20: updateGameLogic

/*Funcao de update logico do proprio jogo. E' executada em cada ciclo apos a checagem de colisao, antes
  do update logico das entidades do jogo.*/
void updateGameLogic(double deltaTime)
{
    int i, estadoInicial, posInicial, numVivos;
    Vetor v, p;

	/*Antes temos que criar os dois botes, sempre que der.*/
	while ( (2 - getNumBotesVivos()) > 0 ) 
	{
		/*Apenas criamos o vetor e setamos apenas 1 de suas coordenadas (a outra = 0). Assim esse valor que estamos setando
          sera igual ao modulo do vetor, que queremos que seja um numero especifico dependendo das configuracoes.
          Depois iremos atualizar (para variar) a direcao, e somente a direcao, da velocidade.*/
        v = VETORinit(getSpeed() + (getRandDouble()*10 ), 0);
		/*Inicializamos a posicao com um valor fora da tela, para que no teste a seguir nao haja nenhuma entidade para que possamos
		  criar uma.*/
		p = VETORinit(-30.0, -30.0);

        /*Agora escolhemos uma posicao aleatoria ao longo das bordas do oceano para criar o bote,
          e atualizamos a sua direcao para eles comecarem se mexendo para algum lado.*/
		while ( getEntityByPositionVector(p) != NULL || getX(p) < 0)
		{
			posInicial = rand()%4;
    	    estadoInicial = rand()%2;

	        if (posInicial == 0)
    	    {
    	    	setX(p, rand()%SCREEN_W);
				setY(p, 10);
    	        if (estadoInicial == 0)
					setEstado(7, v);
				else if (estadoInicial == 1)
					setEstado(5, v);
			}
			else if (posInicial == 1)
    	    {
				setX(p, 0);
				setY(p, rand()%SCREEN_H);
				if (estadoInicial == 0)
					setEstado(4, v);
				else if (estadoInicial == 1)
					setEstado(5, v);
			}
			else if (posInicial == 2)
    	    {
				setX(p, rand()%SCREEN_W);
				setY(p, SCREEN_H-1);
				if (estadoInicial == 0)
					setEstado(6, v);
				else if (estadoInicial == 1)
					setEstado(4, v);
			}
			else if (posInicial == 3)
    	    {
				setX(p, SCREEN_W-1);
				setY(p, rand()%SCREEN_H);
    	        if (estadoInicial == 0)
					setEstado(6, v);
				else if (estadoInicial == 1)
					setEstado(7, v);
    		}
		}
        /*Finalmente, criamos o bote.*/
        criaBote(p, v);
	}

    /*deltaTime em segundos, frequencia em ciclos por segundo (passageiros a serem criados por segundo).*/
    timeElapsed += deltaTime;
    if (timeElapsed >= 1)  /*Um segundo inteiro foi completado, criar passageiros...*/
    {
		numVivos = getNumPassageirosVivos();

        for (i=0; i<getFrequency() && numVivos < getMaxNumPassageiros(); i++)
        {
            /*Apenas criamos o vetor e setamos apenas 1 de suas coordenadas (a outra = 0). Assim esse valor que estamos setando
              sera igual ao modulo do vetor, que queremos que seja um numero especifico dependendo das configuracoes.
              Depois iremos atualizar (para variar) a direcao, e somente a direcao, da velocidade.*/
            v = VETORinit(getSpeed() + (getRandDouble()*2 - 1), 0);
			/*Inicializamos a posicao com um valor fora da tela, para que no teste a seguir nao haja nenhuma entidade para que possamos
			  criar uma.*/
			p = VETORinit(-30.0, -30.0);

            /*Agora escolhemos uma posicao aleatoria ao longo das bordas do oceano para criar o passageiro,
              e atualizamos a sua direcao para eles comecarem se mexendo ao centro do oceano.*/
			while ( getEntityByPositionVector(p) != NULL || getX(p) < 0)
			{
	            posInicial = rand()%4;
    	        estadoInicial = rand()%6;

	            if (posInicial == 0)
    	        {
    	            setX(p, rand()%SCREEN_W);
					setY(p, 10);
    	            if (estadoInicial <= 3)
    	                setEstado(1, v);
    	            else if (estadoInicial == 4)
    	                setEstado(7, v);
    	            else if (estadoInicial == 5)
    	                setEstado(5, v);
    	        }
//.........这里部分代码省略.........
开发者ID:gorobaum,项目名称:gorobaumhome,代码行数:101,代码来源:Naufrago.c



注:本文中的setX函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ setXBaseValue函数代码示例发布时间:2022-05-30
下一篇:
C++ setWriteError函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap