/* * 2D Game Engine * RenderGUI.h: * Based on pikuma.com 2D game engine in C++ and Lua course * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by ManoĆ«l Trapier on 28/02/2021. */ #ifndef IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H #define IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include class RenderGUISystem : public System { public: RenderGUISystem() = default; void update(const std::unique_ptr ®istry, SDL_Rect &camera) { ImGui::NewFrame(); ImGuiWindowFlags windowFlags; if (ImGui::Begin("Spawn enemies")) { /* Main properties */ static int enemyXPos = 0, enemyYPos = 0, enemyHealth = 100; static int enemyXVelocity = 0, enemyYVelocity = 0; static float enemyScale = 1, enemyRotation = 0; const char* spriteList[] = { "truck-image", "tank-image" }; static int spriteSelection = 0; /* Projectile */ static float projectileAngle = 0, projectileDuration = 5, projectileFrequency = 3; static int projectileSpeed = 100; double projectileXVelocity, projectileYVelocity; // Sprite selection if (ImGui::CollapsingHeader("Sprite")) { ImGui::Combo("combo", &spriteSelection, spriteList, IM_ARRAYSIZE(spriteList)); } ImGui::Spacing(); if (ImGui::CollapsingHeader("Transform")) { ImGui::InputInt("X position", &enemyXPos); ImGui::InputInt("Y position", &enemyYPos); ImGui::SliderFloat("Scale", &enemyScale, 0.5, 10); ImGui::SliderAngle("Rotation", &enemyRotation, 0, 360); } ImGui::Spacing(); if (ImGui::CollapsingHeader("Rigid Body")) { ImGui::InputInt("X Velocity", &enemyXVelocity); ImGui::InputInt("Y Velocity", &enemyYVelocity); } ImGui::Spacing(); // default Health if (ImGui::CollapsingHeader("Health")) { ImGui::SliderInt("Starting health", &enemyHealth, 1, 100); } ImGui::Spacing(); if (ImGui::CollapsingHeader("Projectile Emitter")) { // Angle/Speed of projectiles ImGui::SliderAngle("Angle", &projectileAngle, 0, 360); ImGui::SliderInt("Speed", &projectileSpeed, 10, 500); // Frequency / duration of projectives (seconds) ImGui::InputFloat("Frequency (sec)", &projectileFrequency); ImGui::InputFloat("Duration (sec)", &projectileDuration); } ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); if (ImGui::Button("Spawn")) { projectileXVelocity = cos(projectileAngle) * (double)projectileSpeed; projectileYVelocity = sin(projectileAngle) * (double)projectileSpeed; Logger::Warning("proj X Vel ==> %f", projectileXVelocity); Logger::Warning("proj Y Vel ==> %f", projectileYVelocity); Entity newEnemy = registry->createEntity(); newEnemy.addComponent(glm::vec2(enemyXPos, enemyYPos), glm::vec2(enemyScale, enemyScale), glm::degrees(enemyRotation)); newEnemy.addComponent(glm::vec2(enemyXVelocity, enemyYVelocity)); newEnemy.addComponent(spriteList[spriteSelection], 2, 32, 32); newEnemy.addComponent(25, 20, glm::vec2(5, 5)); newEnemy.addComponent(glm::vec2(projectileXVelocity, projectileYVelocity), projectileFrequency * 1000, projectileDuration * 1000, 10, false); newEnemy.addComponent(enemyHealth); newEnemy.group("enemies"); } } ImGui::End(); /* Mouse overlay */ windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_Always, ImVec2(0, 0)); ImGui::SetNextWindowBgAlpha(0.9f); if (ImGui::Begin("Mouse coordinates", NULL, windowFlags)) { ImGui::Text("Map Coordinates: x=%.1f, y=%.1f", ImGui::GetIO().MousePos.x + camera.x, ImGui::GetIO().MousePos.y + camera.y); } ImGui::End(); ImGui::Render(); ImGuiSDL::Render(ImGui::GetDrawData()); } }; #endif /* IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H */