|
|
|
@ -8,6 +8,7 @@ |
|
|
|
|
#include <SFML/Graphics/Texture.hpp> |
|
|
|
|
#include <SFML/Graphics/RenderWindow.hpp> |
|
|
|
|
#include <SFML/System.hpp> |
|
|
|
|
#include <SFML/Audio.hpp> |
|
|
|
|
#include <SFML/Window/Event.hpp> |
|
|
|
|
|
|
|
|
|
void ImGui_setup(sf::RenderWindow &window) { |
|
|
|
@ -72,7 +73,7 @@ struct BoxTest Box2d_setup(b2World &world) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Handle_events(sf::RenderWindow &window, BoxTest &box) { |
|
|
|
|
void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) { |
|
|
|
|
sf::Event event; |
|
|
|
|
|
|
|
|
|
// is this a main event loop
|
|
|
|
@ -90,10 +91,12 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box) { |
|
|
|
|
b2Vec2 force(-200, 1000); |
|
|
|
|
box.body->ApplyForceToCenter(force, true); |
|
|
|
|
box.body->ApplyTorque(100.0f, true); |
|
|
|
|
click.play(); |
|
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { |
|
|
|
|
b2Vec2 force(200, 1000); |
|
|
|
|
box.body->ApplyForceToCenter(force, true); |
|
|
|
|
box.body->ApplyTorque(-100.0f, true); |
|
|
|
|
click.play(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case sf::Event::MouseButtonPressed: |
|
|
|
@ -101,10 +104,12 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box) { |
|
|
|
|
b2Vec2 force(-200, 1000); |
|
|
|
|
box.body->ApplyForceToCenter(force, true); |
|
|
|
|
box.body->ApplyTorque(100.0f, true); |
|
|
|
|
click.play(); |
|
|
|
|
} else if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) { |
|
|
|
|
b2Vec2 force(200, 1000); |
|
|
|
|
box.body->ApplyForceToCenter(force, true); |
|
|
|
|
box.body->ApplyTorque(-100.0f, true); |
|
|
|
|
click.play(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -152,11 +157,19 @@ int main() { |
|
|
|
|
fmt::print("Setting up a window for you...\n"); |
|
|
|
|
sf::ContextSettings settings; |
|
|
|
|
settings.antialiasingLevel = 8; |
|
|
|
|
|
|
|
|
|
sf::RenderWindow window(sf::VideoMode(1920, 1080), "Simple Game Demo", sf::Style::Default, settings); |
|
|
|
|
window.setFramerateLimit(60); |
|
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
|
ImGui_setup(window); |
|
|
|
|
|
|
|
|
|
sf::SoundBuffer buffer; |
|
|
|
|
if(!buffer.loadFromFile("click.mp3")) { |
|
|
|
|
fmt::print("Failed to load click.ogg!\n"); |
|
|
|
|
} |
|
|
|
|
sf::Sound click; |
|
|
|
|
click.setBuffer(buffer); |
|
|
|
|
|
|
|
|
|
sf::Clock deltaClock; |
|
|
|
|
sf::Clock clock; |
|
|
|
|
sf::Time tick = clock.getElapsedTime(); |
|
|
|
@ -170,7 +183,7 @@ int main() { |
|
|
|
|
BoxTest box = Box2d_setup(world); |
|
|
|
|
|
|
|
|
|
while (window.isOpen()) { |
|
|
|
|
Handle_events(window, box); |
|
|
|
|
Handle_events(window, box, click); |
|
|
|
|
// preparing for refactoring this into a class or struct for everything
|
|
|
|
|
tick = Update_entities(window, world, clock, deltaClock, tick, box, player); |
|
|
|
|
} |
|
|
|
|