0 Members and 2 Guests are viewing this topic.
#include <SFML/Audio.hpp>#include <SFML/Graphics.hpp>#include <iostream>#include <cmath>using std::cout;using std::endl;#include "RenderManager.h"int relativeX, relativeY;float speed = 0.05;const float PI = 3.14159265;int rotation;int main(){ // Create the main window sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"); // Render Manager cge::RenderManager myRenderManager(window); // Load a sprite to display sf::Texture texture; if (!texture.LoadFromFile("missile.gif")) return EXIT_FAILURE; sf::Sprite missile(texture); myRenderManager.add(missile); // Start the game loop while (window.IsOpened()) { // ## PROCESS ## if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape)) { window.Close(); //return 0; } relativeX = sf::Mouse::GetPosition(window).x - missile.GetPosition().x; relativeY = sf::Mouse::GetPosition(window).y - missile.GetPosition().y; rotation = atan(relativeX/relativeY)*180/PI; if (sf::Mouse::GetPosition(window).x > missile.GetPosition().x) missile.Move(.05, 0); else missile.Move(-.05, 0); if (sf::Mouse::GetPosition(window).y > missile.GetPosition().y) missile.Move(0, .05); else missile.Move(0, -.05); // ## OUTPUT ## //std::cout<< sf::Mouse::GetPosition().x<< std::endl; //std::cout<< missile.GetPosition().x<< std::endl; //std::cout<< atan(0.1)*180/PI<< endl; // Clear screen window.Clear(); // Draw the sprite myRenderManager.draw(); // Update the window window.Display(); } return 0;}