当前位置: 首页>>代码示例>>C++>>正文


C++ Vector2函数代码示例

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


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

示例1: SetScale

void Sprite::SetScale(float x, float y)
{
    SetScale(Vector2(x, y));
}
开发者ID:Boshin,项目名称:Urho3D,代码行数:4,代码来源:Sprite.cpp

示例2:

Vector2 Vector4::xy() const  { return Vector2       (x, y); }
开发者ID:MilchBuby,项目名称:riboncore,代码行数:1,代码来源:Vector4.cpp

示例3: setRect

void GuiControl::setWidth(float w) {
    setRect(Rect2D::xywh(rect().x0y0(), Vector2(w, rect().height())));
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:3,代码来源:GuiControl.cpp

示例4: toOSWindowCoords

Vector2 GuiControl::fromOSWindowCoords(const Vector2& v) const {
    Vector2 xform = toOSWindowCoords(Vector2(0, 0));
    return v - xform;
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:4,代码来源:GuiControl.cpp

示例5: setFrustumOffset

 //---------------------------------------------------------------------
 void Frustum::setFrustumOffset(Real horizontal, Real vertical)
 {
     setFrustumOffset(Vector2(horizontal, vertical));
 }
开发者ID:jjiezheng,项目名称:pap_full,代码行数:5,代码来源:OgreFrustum.cpp

示例6: GetContext

void Urho2DPlatformer::HandleCollisionBegin(PhysicsWorld2D *, RigidBody2D *, RigidBody2D *, Node *nodeA, Node * nodeB,
                                            const std::vector<uint8_t> &, CollisionShape2D *, CollisionShape2D *)
{
    // Get colliding node
    auto* hitNode = nodeA;
    if (hitNode->GetName() == "Imp")
        hitNode = nodeB;
    QString nodeName = hitNode->GetName();
    Node* character2DNode = scene_->GetChild("Imp", true);

    // Handle ropes and ladders climbing
    if (nodeName == "Climb")
    {
        if (character2D_->isClimbing_) // If transition between rope and top of rope (as we are using split triggers)
            character2D_->climb2_ = true;
        else
        {
            character2D_->isClimbing_ = true;
            auto* body = character2DNode->GetComponent<RigidBody2D>();
            body->SetGravityScale(0.0f); // Override gravity so that the character doesn't fall
            // Clear forces so that the character stops (should be performed by setting linear velocity to zero, but currently doesn't work)
            body->SetLinearVelocity(Vector2(0.0f, 0.0f));
            body->SetAwake(false);
            body->SetAwake(true);
        }
    }

    if (nodeName == "CanJump")
        character2D_->aboveClimbable_ = true;

    // Handle coins picking
    if (nodeName == "Coin")
    {
        hitNode->Remove();
        character2D_->remainingCoins_ -= 1;
        auto* ui = GetContext()->m_UISystem.get();
        if (character2D_->remainingCoins_ == 0)
        {
            Text* instructions = static_cast<Text*>(ui->GetRoot()->GetChild("Instructions", true));
            instructions->SetText("!!! Go to the Exit !!!");
        }
        Text* coinsText = static_cast<Text*>(ui->GetRoot()->GetChild("CoinsText", true));
        coinsText->SetText(QString(character2D_->remainingCoins_)); // Update coins UI counter
        sample2D_->PlaySoundEffect("Powerup.wav");
    }

    // Handle interactions with enemies
    if (nodeName == "Enemy" || nodeName == "Orc")
    {
        auto* animatedSprite = character2DNode->GetComponent<AnimatedSprite2D>();
        float deltaX = character2DNode->GetPosition().x_ - hitNode->GetPosition().x_;

        // Orc killed if character is fighting in its direction when the contact occurs (flowers are not destroyable)
        if (nodeName == "Orc" && animatedSprite->GetAnimation() == "attack" && (deltaX < 0 == animatedSprite->GetFlipX()))
        {
            static_cast<Mover*>(hitNode->GetComponent<Mover>())->emitTime_ = 1;
            if (!hitNode->GetChild("Emitter", true))
            {
                hitNode->GetComponent("RigidBody2D")->Remove(); // Remove Orc's body
                sample2D_->SpawnEffect(hitNode);
                sample2D_->PlaySoundEffect("BigExplosion.wav");
            }
        }
        // Player killed if not fighting in the direction of the Orc when the contact occurs, or when colliding with a flower
        else
        {
            if (!character2DNode->GetChild("Emitter", true))
            {
                character2D_->wounded_ = true;
                if (nodeName == "Orc")
                {
                    auto* orc = static_cast<Mover*>(hitNode->GetComponent<Mover>());
                    orc->fightTimer_ = 1;
                }
                sample2D_->SpawnEffect(character2DNode);
                sample2D_->PlaySoundEffect("BigExplosion.wav");
            }
        }
    }

    // Handle exiting the level when all coins have been gathered
    if (nodeName == "Exit" && character2D_->remainingCoins_ == 0)
    {
        // Update UI
        auto* ui = GetContext()->m_UISystem.get();
        Text* instructions = static_cast<Text*>(ui->GetRoot()->GetChild("Instructions", true));
        instructions->SetText("!!! WELL DONE !!!");
        instructions->SetPosition(IntVector2(0, 0));
        // Put the character outside of the scene and magnify him
        character2DNode->SetPosition(Vector3(-20.0f, 0.0f, 0.0f));
        character2DNode->SetScale(1.5f);
    }

    // Handle falling into lava
    if (nodeName == "Lava")
    {
        auto* body = character2DNode->GetComponent<RigidBody2D>();
        body->ApplyForceToCenter(Vector2(0.0f, 1000.0f), true);
        if (!character2DNode->GetChild("Emitter", true))
        {
//.........这里部分代码省略.........
开发者ID:nemerle,项目名称:lutefisk3d,代码行数:101,代码来源:Urho2DPlatformer.cpp

示例7: Vector2

Vector2 CollisionPolygon2D::_get_shape_range() const {

	return Vector2(shape_from,shape_to);
}
开发者ID:Scrik,项目名称:godot,代码行数:4,代码来源:collision_polygon_2d.cpp

示例8: setPosition

void GuiControl::setPosition(float x, float y) {
    setPosition(Vector2(x, y));
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:3,代码来源:GuiControl.cpp

示例9: moveBy

void GuiControl::moveBy(float x, float y) {
    moveBy(Vector2(x, y));
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:3,代码来源:GuiControl.cpp

示例10: setSize

void GuiControl::setSize(float x, float y) {
    setSize(Vector2(x, y));
}
开发者ID:luaman,项目名称:g3d-cvs,代码行数:3,代码来源:GuiControl.cpp

示例11: FetchEnemy

void ServerApp::SpawnEnemy()
{
	ServerEnemy::ENEMY_TYPE type = (ServerEnemy::ENEMY_TYPE)Math::RandIntMinMax(ServerEnemy::E_EASY, ServerEnemy::E_HARD);
	ServerEnemy* e = FetchEnemy();
	if (e)
	{
		// Universal settings
		e->active = true;
		e->x_ = Math::RandFloatMinMax(-S_SPAWN_OFFSET, s_screen_width + S_SPAWN_OFFSET); //rand() % (int)(s_screen_width + S_SPAWN_OFFSET * 2.f);
		//e->x_ -= S_SPAWN_OFFSET;
		if (e->x_ > 0 && e->x_ <= s_screen_width)
		{
			// X axis within screen, spawn around offset of y axis only
			bool up_down = rand() % 2;
			if (up_down) // Up
			{
				e->y_ = Math::RandFloatMinMax(-S_SPAWN_OFFSET, 0);//(rand() % (int)S_SPAWN_OFFSET) - S_SPAWN_OFFSET;
			}
			else // Down
			{
				e->y_ = Math::RandFloatMinMax(s_screen_height, s_screen_height + S_SPAWN_OFFSET);//(rand() % (int)S_SPAWN_OFFSET) + s_screen_height;
			}
		}
		else
		{
			e->y_ = Math::RandFloatMinMax(-S_SPAWN_OFFSET, s_screen_height + S_SPAWN_OFFSET); //rand() % (int)(s_screen_height + S_SPAWN_OFFSET * 2.f);
			//e->y_ -= S_SPAWN_OFFSET;
		}
		
		Vector2 dir = (Vector2(s_screen_width, s_screen_height) - Vector2(e->x_, e->y_)).Normalized();

		switch (type)
		{
		case ServerEnemy::E_EASY: // Spawn easy enemy
			{
				e->hp = 1;
				e->speed = 100.f;
				e->type_ = ServerEnemy::E_EASY;
			}
			break;
		case ServerEnemy::E_NORMAL: // Spawn normal enemy
			{
				e->hp = 2;
				e->speed = 150.f;
				e->type_ = ServerEnemy::E_NORMAL;
			}
			break;
		case ServerEnemy::E_HARD: // Spawn hard enemy
			{
				e->hp = 3;
				e->speed = 200.f;
				e->type_ = ServerEnemy::E_HARD;
			}
			break;
		}

		// Universal settings
		e->vel_x = dir.x * e->speed;
		e->vel_y = dir.y * e->speed;

		RakNet::BitStream bs;
		bs.Write((unsigned char)ID_NEW_ENEMY);
		bs.Write(e->id);
		bs.Write(e->type_);
		bs.Write(e->x_);
		bs.Write(e->y_);
		bs.Write(e->vel_x);
		bs.Write(e->vel_y);
		bs.Write(e->speed);
		bs.Write(e->hp);

		rakpeer_->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
	}
}
开发者ID:NothingMuch123,项目名称:Multiplayer-Assignment-2,代码行数:74,代码来源:ServerApp.cpp

示例12: Vector2

		Rectangle::Rectangle(const float &x, const float &y, const float &width, const float &height) {
			this->position = Vector2(x, y);
			this->size = Vector2(width, height);
		}
开发者ID:DanielRS,项目名称:DwarfEngine,代码行数:4,代码来源:Rectangle.cpp

示例13: SetPosition

void Sprite::SetPosition(float x, float y)
{
    SetPosition(Vector2(x, y));
}
开发者ID:Boshin,项目名称:Urho3D,代码行数:4,代码来源:Sprite.cpp


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