void Sprite::SetScale(float x, float y) { SetScale(Vector2(x, y)); }
Vector2 Vector4::xy() const { return Vector2 (x, y); }
Vector2 Vector4::zy() const { return Vector2 (z, y); }
Vector2 Vector4::xx() const { return Vector2 (x, x); }
Vector2 Vector4::zx() const { return Vector2 (z, x); }
Vector2 Vector4::xw() const { return Vector2 (x, w); }
Vector2 Vector4::zw() const { return Vector2 (z, w); }
void GuiControl::setWidth(float w) { setRect(Rect2D::xywh(rect().x0y0(), Vector2(w, rect().height()))); }
Vector2 GuiControl::fromOSWindowCoords(const Vector2& v) const { Vector2 xform = toOSWindowCoords(Vector2(0, 0)); return v - xform; }
//--------------------------------------------------------------------- void Frustum::setFrustumOffset(Real horizontal, Real vertical) { setFrustumOffset(Vector2(horizontal, vertical)); }
void GuiControl::setHeight(float h) { setRect(Rect2D::xywh(rect().x0y0(), Vector2(rect().width(), h))); }
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)) { character2D_->wounded_ = true; sample2D_->SpawnEffect(character2DNode); sample2D_->PlaySoundEffect("BigExplosion.wav"); } } // Handle climbing a slope if (nodeName == "Slope") character2D_->onSlope_ = true; }
Vector2 CollisionPolygon2D::_get_shape_range() const { return Vector2(shape_from,shape_to); }
void Sprite::SetScale(float scale) { SetScale(Vector2(scale, scale)); }
Vector2 Vector4::zz() const { return Vector2 (z, z); }
void GuiControl::setPosition(float x, float y) { setPosition(Vector2(x, y)); }
Vector2 Vector4::wz() const { return Vector2 (w, z); }
void GuiControl::moveBy(float x, float y) { moveBy(Vector2(x, y)); }
Vector2 Vector4::yw() const { return Vector2 (y, w); }
void GuiControl::setSize(float x, float y) { setSize(Vector2(x, y)); }
Vector2 Vector4::ww() const { return Vector2 (w, w); }
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); } }
Vector2 Vector4::yx() const { return Vector2 (y, x); }
Vector2 Vector4::wy() const { return Vector2 (w, y); }
Vector2 Vector4::wx() const { return Vector2 (w, x); }
Vector2 Vector4::xz() const { return Vector2 (x, z); }
Vector2 Vector4::yy() const { return Vector2 (y, y); }
Vector2 Vector4::yz() const { return Vector2 (y, z); }
Rectangle::Rectangle(const float &x, const float &y, const float &width, const float &height) { this->position = Vector2(x, y); this->size = Vector2(width, height); }
void Sprite::SetPosition(float x, float y) { SetPosition(Vector2(x, y)); }