|
|
@ -1,5 +1,3 @@ |
|
|
|
#include "imgui.h" |
|
|
|
|
|
|
|
#include "imgui-SFML.h" |
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES |
|
|
|
#define _USE_MATH_DEFINES |
|
|
|
#include <math.h> |
|
|
|
#include <math.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
@ -10,27 +8,11 @@ |
|
|
|
#include <SFML/System.hpp> |
|
|
|
#include <SFML/System.hpp> |
|
|
|
#include <SFML/Audio.hpp> |
|
|
|
#include <SFML/Audio.hpp> |
|
|
|
#include <SFML/Window/Event.hpp> |
|
|
|
#include <SFML/Window/Event.hpp> |
|
|
|
|
|
|
|
#include "dbc.hpp" |
|
|
|
void ImGui_setup(sf::RenderWindow &window) { |
|
|
|
|
|
|
|
ImGui::SFML::Init(window); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) { |
|
|
|
|
|
|
|
ImGui::SFML::Update(window, deltaClock.restart()); |
|
|
|
|
|
|
|
// ImGui::ShowDemoWindow();
|
|
|
|
|
|
|
|
ImGui::Begin("Clock"); |
|
|
|
|
|
|
|
sf::Vector2u size = window.getSize(); |
|
|
|
|
|
|
|
ImGui::SetWindowPos(ImVec2(size.x - 150, 0)); |
|
|
|
|
|
|
|
ImGui::SetWindowSize(ImVec2(150, 50)); |
|
|
|
|
|
|
|
std::string msg = fmt::format("Time: {}\n", tick.asSeconds()); |
|
|
|
|
|
|
|
ImGui::Button(msg.c_str()); |
|
|
|
|
|
|
|
ImGui::End(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Window_update(sf::RenderWindow &window, sf::Sprite &player) { |
|
|
|
void Window_update(sf::RenderWindow &window, sf::Sprite &player) { |
|
|
|
window.clear(); |
|
|
|
window.clear(); |
|
|
|
window.draw(player); |
|
|
|
window.draw(player); |
|
|
|
ImGui::SFML::Render(window); |
|
|
|
|
|
|
|
window.display(); |
|
|
|
window.display(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,10 +55,7 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) { |
|
|
|
|
|
|
|
|
|
|
|
// is this a main event loop
|
|
|
|
// is this a main event loop
|
|
|
|
while (window.pollEvent(event)) { |
|
|
|
while (window.pollEvent(event)) { |
|
|
|
ImGui::SFML::ProcessEvent(window, event); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(event.type) { |
|
|
|
switch(event.type) { |
|
|
|
|
|
|
|
|
|
|
|
case sf::Event::Closed: |
|
|
|
case sf::Event::Closed: |
|
|
|
fmt::print("Exiting...\n"); |
|
|
|
fmt::print("Exiting...\n"); |
|
|
|
window.close(); |
|
|
|
window.close(); |
|
|
@ -107,6 +86,8 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) { |
|
|
|
click.play(); |
|
|
|
click.play(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return; // just here to shutup warnings
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -126,7 +107,6 @@ sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &cl |
|
|
|
player.setPosition(position.x * 100.0f, winSize.y - position.y * 100.0f); |
|
|
|
player.setPosition(position.x * 100.0f, winSize.y - position.y * 100.0f); |
|
|
|
player.setRotation(angle * 180.0f / M_PI); |
|
|
|
player.setRotation(angle * 180.0f / M_PI); |
|
|
|
|
|
|
|
|
|
|
|
ImGui_update(window, deltaClock, tick); |
|
|
|
|
|
|
|
Window_update(window, player); |
|
|
|
Window_update(window, player); |
|
|
|
|
|
|
|
|
|
|
|
return nextTick; |
|
|
|
return nextTick; |
|
|
@ -154,10 +134,9 @@ int main() { |
|
|
|
sf::ContextSettings settings; |
|
|
|
sf::ContextSettings settings; |
|
|
|
settings.antialiasingLevel = 8; |
|
|
|
settings.antialiasingLevel = 8; |
|
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow window(sf::VideoMode(1920, 1080), "Simple Game Demo", sf::Style::Default, settings); |
|
|
|
sf::RenderWindow window(sf::VideoMode(1280, 720), "Simple Game Demo", sf::Style::Default, settings); |
|
|
|
window.setFramerateLimit(60); |
|
|
|
window.setFramerateLimit(60); |
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
ImGui_setup(window); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::SoundBuffer buffer; |
|
|
|
sf::SoundBuffer buffer; |
|
|
|
if(!buffer.loadFromFile("click.mp3")) { |
|
|
|
if(!buffer.loadFromFile("click.mp3")) { |
|
|
@ -183,6 +162,4 @@ int main() { |
|
|
|
// preparing for refactoring this into a class or struct for everything
|
|
|
|
// preparing for refactoring this into a class or struct for everything
|
|
|
|
tick = Update_entities(window, world, clock, deltaClock, tick, box, player); |
|
|
|
tick = Update_entities(window, world, clock, deltaClock, tick, box, player); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SFML::Shutdown(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|