#include <iostream>
#include <string>
#include <imgui.h>
#include <imgui-SFML.h>
#include <SFML/Graphics.hpp>
#include "sol.hpp"
int main() {
sol::state lua;
lua.script_file("./res/test.lua");
std::string title = lua["screen"]["title"];
const int width = lua["screen"]["width"];
const int height = lua["screen"]["height"];
sf::RenderWindow window(sf::VideoMode(width, height), title);
window.setFramerateLimit(60);
ImGui::SFML::Init(window);
// TODO Read from lua?
sf::Texture texture;
if (!texture.loadFromFile("./res/Sprite-0001.png")) {
std::cout << "ugh" << std::endl;
}
sf::Sprite dude;
dude.setTexture(texture);
// TODO "speed" for movement
// TODO input controll to LUA
// TODO ImGUI (because it's awesome), not working?
sf::Clock deltaClock;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(event);
if (event.type == sf::Event::Closed)
window.close();
}
ImGui::SFML::Update(deltaClock.restart());
sf::Vector2f movement;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
//std::cout << "left ";
movement.x -= 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
//std::cout << "left ";
movement.x += 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
//std::cout << "left ";
movement.y -= 5;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
//std::cout << "left ";
movement.y += 5;
}
dude.move(movement);
ImGui::Begin("Hello, world!");
ImGui::Button("Look a button!");
ImGui::End();
window.clear(sf::Color::White);
window.draw(dude);
ImGui::Render();
window.display();
}
ImGui::SFML::Shutdown();
}