@ -10,30 +10,53 @@
# include <SFML/Audio.hpp>
# include <SFML/Audio.hpp>
# include <SFML/Window/Event.hpp>
# include <SFML/Window/Event.hpp>
using namespace ImGui ;
constexpr int FPS = 30 ;
constexpr int FPS = 30 ;
constexpr int X_DIM = 1920 / 2 ;
constexpr int X_DIM = 1920 / 2 ;
constexpr int Y_DIM = 1080 / 2 ;
constexpr int Y_DIM = 1080 / 2 ;
bool window_active_out = true ;
void ImGui_setup ( sf : : RenderWindow & window ) {
void ImGui_setup ( sf : : RenderWindow & window ) {
bool res = ImGui : : SFML : : Init ( window ) ;
bool res = SFML : : Init ( window ) ;
fmt : : println ( " IMGUI returned {} " , res ) ;
fmt : : println ( " IMGUI returned {} " , res ) ;
}
}
void ImGui_update ( sf : : RenderWindow & window , sf : : Clock & deltaClock , sf : : Time & tick ) {
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 ( ) ;
sf : : Vector2u size = window . getSize ( ) ;
ImGui : : SetWindowPos ( ImVec2 ( size . x - 150 , 0 ) ) ;
ImGui : : SetWindowSize ( ImVec2 ( 150 , 50 ) ) ;
SFML : : Update ( window , deltaClock . restart ( ) ) ;
std : : string msg = fmt : : format ( " Time: {} \n " , tick . asSeconds ( ) ) ;
ImGui : : Button ( msg . c_str ( ) ) ;
SetNextWindowPos ( ImVec2 ( 0 , size . y / 2 ) ) ;
ImGui : : End ( ) ;
SetNextWindowSize ( ImVec2 ( size . x , size . y / 2 ) ) ;
Begin ( " Turing's Tarpit " , & window_active_out ) ;
// HP | Hits Taken | Round | Streak
Text ( " HP X " ) ; SameLine ( ) ;
Text ( " Hits Taken X " ) ; SameLine ( ) ;
Text ( " Round X " ) ; SameLine ( ) ;
Text ( " Streak X " ) ;
// HP BAR
float hp = 50.0f ;
SliderFloat ( " HP " , & hp , 0.0f , 100.0f ) ;
// Build Log
TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Build Log " ) ;
BeginChild ( " Scrolling " ) ;
for ( int n = 0 ; n < 50 ; n + + ) {
TextWrapped ( " %04d: Some Text " , n ) ;
}
EndChild ( ) ;
// image placeholder
End ( ) ;
}
}
void Window_update ( sf : : RenderWindow & window ) {
void Window_update ( sf : : RenderWindow & window , sf : : Sprite & player ) {
window . clear ( ) ;
window . clear ( ) ;
ImGui : : SFML : : Render ( window ) ;
window . draw ( player ) ;
SFML : : Render ( window ) ;
window . display ( ) ;
window . display ( ) ;
}
}
@ -42,7 +65,7 @@ void Handle_events(sf::RenderWindow &window) {
// 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 ) ;
SFML : : ProcessEvent ( window , event ) ;
switch ( event . type ) {
switch ( event . type ) {
@ -62,14 +85,17 @@ void Handle_events(sf::RenderWindow &window) {
}
}
}
}
sf : : Time Update_entities ( sf : : RenderWindow & window , sf : : Clock & clock , sf : : Clock & deltaClock , sf : : Time & tick ) {
sf : : Time Update_entities ( sf : : RenderWindow & window , sf : : Sprite & player , sf : : Clock & clock , sf : : Clock & deltaClock , sf : : Time & tick ) {
sf : : Vector2u winSize = window . getSize ( ) ;
sf : : Vector2u winSize = window . getSize ( ) ;
float timeStep = 1.0f / FPS ;
float timeStep = 1.0f / FPS ;
sf : : Time since = clock . getElapsedTime ( ) ;
sf : : Time since = clock . getElapsedTime ( ) ;
sf : : Time nextTick = since - tick > sf : : seconds ( 1 ) ? since : tick ;
sf : : Time nextTick = since - tick > sf : : seconds ( 1 ) ? since : tick ;
player . setPosition ( winSize . x / 2 , 0 ) ;
player . setScale ( { 2.0f , 2.0f } ) ;
ImGui_update ( window , deltaClock , tick ) ;
ImGui_update ( window , deltaClock , tick ) ;
Window_update ( window ) ;
Window_update ( window , player ) ;
return nextTick ;
return nextTick ;
}
}
@ -91,12 +117,21 @@ int main() {
sf : : Clock deltaClock ;
sf : : Clock deltaClock ;
sf : : Clock clock ;
sf : : Clock clock ;
sf : : Time tick = clock . getElapsedTime ( ) ;
sf : : Time tick = clock . getElapsedTime ( ) ;
sf : : Texture texture ;
sf : : Sprite player ;
// fake image here
if ( ! texture . loadFromFile ( " ./assets/sprite.png " ) ) {
fmt : : println ( " Error loading sprite! " ) ;
}
texture . setSmooth ( true ) ;
player . setTexture ( texture ) ;
while ( window . isOpen ( ) ) {
while ( window . isOpen ( ) & & window_active_out ) {
Handle_events ( window ) ;
Handle_events ( window ) ;
// 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 , clock , deltaClock , tick ) ;
tick = Update_entities ( window , player , clock , deltaClock , tick ) ;
}
}
ImGui : : SFML : : Shutdown ( ) ;
SFML : : Shutdown ( ) ;
}
}