GUI mostly laid out but the code needs more refining and cleanup. Currently it creates too many assets in the render function.
This commit is contained in:
parent
e7a226f1db
commit
846d5964fe
2 changed files with 50 additions and 14 deletions
BIN
assets/text.ttf
Normal file
BIN
assets/text.ttf
Normal file
Binary file not shown.
64
sfmltest.cpp
64
sfmltest.cpp
|
@ -6,6 +6,10 @@
|
|||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
@ -17,6 +21,8 @@ constexpr int X_DIM = 1920 / 2;
|
|||
constexpr int Y_DIM = 1080 / 2;
|
||||
bool window_active_out = false;
|
||||
bool show_build_log = false;
|
||||
int hit_points = 50;
|
||||
sf::Font font;
|
||||
|
||||
void ImGui_setup(sf::RenderWindow &window) {
|
||||
bool res = SFML::Init(window);
|
||||
|
@ -43,8 +49,6 @@ void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock) {
|
|||
}
|
||||
|
||||
void Window_update(sf::RenderWindow &window, sf::Sprite &background) {
|
||||
window.clear();
|
||||
window.draw(background);
|
||||
if(show_build_log) {
|
||||
SFML::Render(window);
|
||||
}
|
||||
|
@ -61,7 +65,6 @@ void Handle_events(sf::RenderWindow &window) {
|
|||
}
|
||||
|
||||
switch(event.type) {
|
||||
|
||||
case sf::Event::Closed:
|
||||
fmt::print("Exiting...\n");
|
||||
window.close();
|
||||
|
@ -84,8 +87,45 @@ void Handle_events(sf::RenderWindow &window) {
|
|||
}
|
||||
}
|
||||
|
||||
void Update_entities(sf::RenderWindow &window, sf::Sprite &background, sf::Clock &clock, sf::Clock &deltaClock) {
|
||||
void write_text(sf::RenderWindow &window, const char *content, sf::Vector2f position) {
|
||||
// hp text
|
||||
sf::Text text;
|
||||
text.setFont(font);
|
||||
text.setString(content);
|
||||
text.setCharacterSize(48);
|
||||
text.setFillColor(sf::Color(100, 250, 50));
|
||||
text.setPosition(position);
|
||||
window.draw(text);
|
||||
}
|
||||
|
||||
void Update_entities(sf::RenderWindow &window, sf::Clock &clock, sf::Clock &deltaClock) {
|
||||
window.clear();
|
||||
|
||||
sf::Texture texture;
|
||||
sf::Sprite background;
|
||||
|
||||
// fake image here
|
||||
if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) {
|
||||
fmt::println("Error loading sprite!");
|
||||
}
|
||||
texture.setSmooth(true);
|
||||
background.setTexture(texture);
|
||||
background.setPosition(0, 0);
|
||||
window.draw(background);
|
||||
|
||||
sf::RectangleShape hp_bar({1920/2 - 18*2, 45.0f});
|
||||
hp_bar.setPosition({18, 434});
|
||||
hp_bar.setFillColor(sf::Color(100, 250, 50));
|
||||
window.draw(hp_bar);
|
||||
|
||||
// hp text
|
||||
write_text(window, "100", {60, 363});
|
||||
// rounds text
|
||||
write_text(window, "222", {305, 363});
|
||||
// streaks text
|
||||
write_text(window, "333", {540, 363});
|
||||
// deaths text
|
||||
write_text(window, "444", {757, 363});
|
||||
|
||||
if(show_build_log) {
|
||||
ImGui_update(window, deltaClock);
|
||||
|
@ -100,6 +140,11 @@ int main() {
|
|||
sf::ContextSettings settings;
|
||||
settings.antialiasingLevel = 8;
|
||||
|
||||
if(!font.loadFromFile("./assets/text.ttf")) {
|
||||
fmt::println("Cannot load font.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings);
|
||||
window.setPosition({.x=0,.y=0});
|
||||
|
||||
|
@ -109,20 +154,11 @@ int main() {
|
|||
|
||||
sf::Clock deltaClock;
|
||||
sf::Clock clock;
|
||||
sf::Texture texture;
|
||||
sf::Sprite background;
|
||||
|
||||
// fake image here
|
||||
if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) {
|
||||
fmt::println("Error loading sprite!");
|
||||
}
|
||||
texture.setSmooth(true);
|
||||
background.setTexture(texture);
|
||||
|
||||
while (window.isOpen()) {
|
||||
Handle_events(window);
|
||||
// preparing for refactoring this into a class or struct for everything
|
||||
Update_entities(window, background, clock, deltaClock);
|
||||
Update_entities(window, clock, deltaClock);
|
||||
show_build_log = window_active_out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue