diff --git a/examples/Tut01/main.cpp b/examples/Tut01/main.cpp index b5e07074d..b1d962e1e 100644 --- a/examples/Tut01/main.cpp +++ b/examples/Tut01/main.cpp @@ -1,4 +1,4 @@ -// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel-01---Hello-World +// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B01%5D-Hello-World #include #include diff --git a/examples/Tut02/build.lua b/examples/Tut02/build.lua new file mode 100644 index 000000000..dbb8a8c9f --- /dev/null +++ b/examples/Tut02/build.lua @@ -0,0 +1,11 @@ +EXAMPLE.Name = "Tut02_Events" + +EXAMPLE.EnableConsole = true + +EXAMPLE.Files = { + "main.cpp" +} + +EXAMPLE.Libraries = { + "NazaraSDK" +} diff --git a/examples/Tut02/main.cpp b/examples/Tut02/main.cpp new file mode 100644 index 000000000..83de624c6 --- /dev/null +++ b/examples/Tut02/main.cpp @@ -0,0 +1,50 @@ +// Sources pour https://github.com/DigitalPulseSoftware/NazaraEngine/wiki/(FR)-Tutoriel:-%5B02%5D-Gestion-des-événements + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + Ndk::Application application(argc, argv); + + Nz::RenderWindow& mainWindow = application.AddWindow(); + mainWindow.Create(Nz::VideoMode(800, 600, 32), "Test"); + + mainWindow.EnableCloseOnQuit(false); + + Ndk::World& world = application.AddWorld(); + world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); + world.GetSystem().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color(117, 122, 214))); + + Ndk::EntityHandle viewEntity = world.CreateEntity(); + viewEntity->AddComponent(); + + Ndk::CameraComponent& viewer = viewEntity->AddComponent(); + viewer.SetTarget(&mainWindow); + viewer.SetProjectionType(Nz::ProjectionType_Orthogonal); + + + Nz::EventHandler& eventHandler = mainWindow.GetEventHandler(); + eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) + { + std::cout << Nz::Keyboard::GetKeyName(e.code) << std::endl; + + // Profitons-en aussi pour nous donner un moyen de quitter le programme + if (e.code == Nz::Keyboard::Escape) + Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application + }); + + + while (application.Run()) + { + mainWindow.Display(); + } + + return EXIT_SUCCESS; +}