Last changes

This commit is contained in:
SirLynix
2023-02-02 20:33:53 +01:00
committed by Jérôme Leclercq
parent cee75dcc11
commit 5a57aca66a
26 changed files with 310 additions and 183 deletions

View File

@@ -16,7 +16,6 @@
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Utility/BasicMainloop.hpp>
#include <chrono>
#include <iostream>
#include <thread>
@@ -47,10 +46,10 @@ int main()
sound.EnableLooping(true);
// La source du son se situe vers la gauche (Et un peu en avant)
sound.SetPosition(Nz::Vector3f::Left()*50.f + Nz::Vector3f::Forward()*5.f);
sound.SetPosition(Nz::Vector3f::Left() * 50.f + Nz::Vector3f::Forward() * 5.f);
// Et possède une vitesse de 10 par seconde vers la droite
sound.SetVelocity(Nz::Vector3f::Left()*-10.f);
sound.SetVelocity(Nz::Vector3f::Right() * 10.f);
// On joue le son
sound.Play();
@@ -58,16 +57,27 @@ int main()
Nz::MillisecondClock clock;
app.AddUpdater([&](Nz::Time elapsedTime)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 30));
if (sound.GetStatus() != Nz::SoundStatus::Playing)
{
// On arrête le son et l'application
sound.Stop();
app.Quit();
}
// On bouge la source du son en fonction du temps depuis chaque mise à jour
Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetElapsedTime().AsSeconds();
Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.Restart().AsSeconds();
sound.SetPosition(pos);
std::cout << "Position: " << pos.x << std::endl;
// Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap
if (pos.x > Nz::Vector3f::Left().x * -50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape))
sound.Stop(); // On arrête le son (Stoppant également la boucle)
if (pos.x > Nz::Vector3f::Right().x * 50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape))
{
sound.Stop();
app.Quit();
}
});
return app.Run();