MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Update

Method Update

examples/Particles/SpacebattleDemo.cpp:676–746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674}
675
676bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
677{
678 if (!ParticleDemo::Update(fsm, elapsedTime))
679 return false;
680
681 const float speed = 100.f;
682
683 /*if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
684 m_turretCannonBaseRotation = std::max(m_turretCannonBaseRotation - speed * elapsedTime, -65.f);
685
686 if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S))
687 m_turretCannonBaseRotation = std::min(m_turretCannonBaseRotation + speed * elapsedTime, 40.f);
688
689 if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q))
690 m_turretBaseRotation += speed * elapsedTime;
691
692 if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D))
693 m_turretBaseRotation -= speed * elapsedTime;*/
694
695 m_turret.cannonBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(m_turretCannonBaseRotation, 0.f, 0.f));
696 m_turret.rotatingBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(0.f, m_turretBaseRotation, 0.f));
697
698 bool discharged = m_turretShootTimer < 1.f;
699 if (Nz::Mouse::IsButtonPressed(Nz::Mouse::Left) && !discharged)
700 {
701 m_turretFireSound.Play();
702
703 m_turretShootTimer = -1.f;
704
705 Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>();
706
707 TorpedoParticle* particle = static_cast<TorpedoParticle*>(m_torpedoGroup->CreateParticle());
708 particle->color = Nz::Color::White;
709 particle->position = cannonNode.ToGlobalPosition(Nz::Vector3f::Forward() * 10.f);
710 particle->rotation = 0.f;
711 particle->life = 15.f;
712 particle->size.Set(13.34f, 7.41f);
713 particle->size *= 2.f;
714 particle->velocity = cannonNode.GetForward() * 100.f;
715 }
716
717 m_turretShootTimer += elapsedTime * 2.f;
718 if (discharged && m_turretShootTimer >= 1.f)
719 m_turretReloadSound.Play();
720
721 m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>().SetPosition(Nz::Vector3f::Backward() * std::sin(std::min(m_turretShootTimer, 0.f) * float(M_PI)) * 3.f);
722
723 m_spaceshipSpawnCounter += elapsedTime;
724 if (m_spaceshipSpawnCounter >= 10.f)
725 {
726 m_spaceshipSpawnCounter -= 10.f;
727
728 auto& spacestationNode = m_spacestationEntity->GetComponent<Ndk::NodeComponent>();
729
730 const Ndk::EntityHandle& spaceship = m_spaceshipTemplate->Clone();
731 RegisterEntity(spaceship);
732 auto& nodeComponent = spaceship->GetComponent<Ndk::NodeComponent>();
733 auto& spaceshipComponent = spaceship->GetComponent<SpaceshipComponent>();

Callers 1

EnterMethod · 0.45

Calls 11

CreateParticleMethod · 0.80
ToGlobalPositionMethod · 0.80
GetRightMethod · 0.80
KillMethod · 0.80
SetRotationMethod · 0.45
PlayMethod · 0.45
SetMethod · 0.45
GetForwardMethod · 0.45
SetPositionMethod · 0.45
CloneMethod · 0.45
GetPositionMethod · 0.45

Tested by

no test coverage detected